From 10cc588bba5f0a28059cb1bc97770df44288be4f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 20 Oct 2023 22:59:26 +0000 Subject: [PATCH 01/92] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index da4e09b..3c963c7 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/ndarray-base-slice": "^0.1.0", "@stdlib/slice-base-args2multislice": "^0.1.0", "@stdlib/slice-ctor": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.1.0" }, "devDependencies": { From eca8f06747fcd51023b681eead4ec324f06dfa52 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 20 Oct 2023 23:01:18 +0000 Subject: [PATCH 02/92] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 43 +- benchmark/benchmark.js | 681 --- branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 49 - docs/types/test.ts | 164 - 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 | 102 - package.json | 70 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 616 -- 41 files changed, 6203 insertions(+), 5092 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 05d1840..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-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 ab56cca..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index ced95ae..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-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 c1c45e7..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 2dd36ec..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: '38 14 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -200,7 +193,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]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index b906eff..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,681 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var baseEmpty = require( '@stdlib/ndarray-base-empty' ); -var empty = require( '@stdlib/ndarray-empty' ); -var pkg = require( './../package.json' ).name; -var sliceDimensionFrom = require( './../lib' ); - - -// MAIN // - -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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2 ], { 'dtype': 'float64' } ), - empty( [ 2 ], { 'dtype': 'float32' } ), - empty( [ 2 ], { 'dtype': 'int32' } ), - empty( [ 2 ], { 'dtype': 'complex128' } ), - empty( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== '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 d8a1299..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-from" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-from -[production-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-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 2ab577a..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import sliceDimensionFrom from '../docs/types/index'; -export = sliceDimensionFrom; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 1b0db5f..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var l=function(i,r){return function(){return r||i((r={exports:{}}).exports,r),r.exports}};var o=l(function(p,u){ -var v=require('@stdlib/slice-base-args2multislice/dist'),c=require('@stdlib/slice-ctor/dist'),f=require('@stdlib/ndarray-base-ndims/dist'),q=require('@stdlib/ndarray-base-slice/dist'),g=require('@stdlib/ndarray-base-normalize-index/dist'),w=require('@stdlib/array-base-filled/dist'),s=require('@stdlib/error-tools-fmtprodmsg/dist');function b(i,r,m,t,d){var n,e,a;if(e=f(i),e===0)throw new TypeError(s('nullF7',e));if(a=g(r,e-1),a===-1)throw new RangeError(s('nullF8',e,r));return n=w(null,e),n[a]=new c(m,null),q(i,v(n),t,d)}u.exports=b -});var h=o();module.exports=h; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 185421a..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar args2multislice = require( '@stdlib/slice-base-args2multislice' );\nvar Slice = require( '@stdlib/slice-ctor' );\nvar ndims = require( '@stdlib/ndarray-base-ndims' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' );\nvar filled = require( '@stdlib/array-base-filled' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns a shifted view of an input ndarray along a specified dimension.\n*\n* @param {ndarray} x - input array\n* @param {integer} dim - index of dimension to slice\n* @param {integer} start - starting index (inclusive)\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {TypeError} first argument must be an ndarray having one or more dimensions\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceDimensionFrom( x, 0, 1, false, false );\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 sliceDimensionFrom( x, dim, start, strict, writable ) {\n\tvar args;\n\tvar N;\n\tvar d;\n\n\t// Retrieve array meta data:\n\tN = ndims( x );\n\n\t// Check whether we were provided a zero-dimensional array...\n\tif ( N === 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.', N ) );\n\t}\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, N-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', N, dim ) );\n\t}\n\t// Define a list of slice arguments:\n\targs = filled( null, N );\n\targs[ d ] = new Slice( start, null );\n\n\t// Return a new array view:\n\treturn slice( x, args2multislice( args ), strict, writable );\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceDimensionFrom;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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 shifted view of an input ndarray along a specified dimension.\n*\n* @module @stdlib/ndarray-base-slice-dimension-from\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var sliceDimensionFrom = require( '@stdlib/ndarray-base-slice-dimension-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 = sliceDimensionFrom( x, 0, 2, false, false );\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,EAAkB,QAAS,oCAAqC,EAChEC,EAAQ,QAAS,oBAAqB,EACtCC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAiB,QAAS,sCAAuC,EACjEC,EAAS,QAAS,2BAA4B,EAC9CC,EAAS,QAAS,uBAAwB,EA6C9C,SAASC,EAAoBC,EAAGC,EAAKC,EAAOC,EAAQC,EAAW,CAC9D,IAAIC,EACAC,EACAC,EAMJ,GAHAD,EAAIZ,EAAOM,CAAE,EAGRM,IAAM,EACV,MAAM,IAAI,UAAWR,EAAQ,+GAAgHQ,CAAE,CAAE,EAIlJ,GADAC,EAAIX,EAAgBK,EAAKK,EAAE,CAAE,EACxBC,IAAM,GACV,MAAM,IAAI,WAAYT,EAAQ,6GAA8GQ,EAAGL,CAAI,CAAE,EAGtJ,OAAAI,EAAOR,EAAQ,KAAMS,CAAE,EACvBD,EAAME,CAAE,EAAI,IAAId,EAAOS,EAAO,IAAK,EAG5BP,EAAOK,EAAGR,EAAiBa,CAAK,EAAGF,EAAQC,CAAS,CAC5D,CAKAb,EAAO,QAAUQ,IC7CjB,IAAIS,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "args2multislice", "Slice", "ndims", "slice", "normalizeIndex", "filled", "format", "sliceDimensionFrom", "x", "dim", "start", "strict", "writable", "args", "N", "d", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ffc1f03..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,49 +0,0 @@ - -{{alias}}( x, dim, start, strict, writable ) - Returns a shifted view of an input ndarray along a specified dimension. - - Parameters - ---------- - x: ndarray - Input array. - - dim: integer - Index of dimension to slice. If less than zero, the index is resolved - relative to the last dimension, with the last dimension corresponding to - the value `-1`. - - start: integer - Starting index (inclusive). If less than zero, the corresponding element - along the specified dimension is resolved relative to the last element - along that dimension. For negative integers, the last element - corresponds to the value `-1`. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - writable: boolean - Boolean indicating whether a returned ndarray should be writable. This - parameter only applies to ndarray constructors which support read-only - instances. - - Returns - ------- - out: ndarray - Output array view. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > x.shape - [ 2, 2 ] - > var y = {{alias}}( x, 1, 1, false, false ) - - > 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 9dfeaf3..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,164 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sliceDimensionFrom = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = 0; - - sliceDimensionFrom( empty( 'float64', sh, order ), 1, s, false, false ); // $ExpectType float64ndarray - sliceDimensionFrom( empty( 'float32', sh, order ), 1, s, false, false ); // $ExpectType float32ndarray - sliceDimensionFrom( empty( 'complex128', sh, order ), 1, s, false, false ); // $ExpectType complex128ndarray - sliceDimensionFrom( empty( 'complex64', sh, order ), 1, s, false, false ); // $ExpectType complex64ndarray - sliceDimensionFrom( empty( 'int32', sh, order ), 1, s, false, false ); // $ExpectType int32ndarray - sliceDimensionFrom( empty( 'int16', sh, order ), 1, s, false, false ); // $ExpectType int16ndarray - sliceDimensionFrom( empty( 'int8', sh, order ), 1, s, false, false ); // $ExpectType int8ndarray - sliceDimensionFrom( empty( 'uint32', sh, order ), 1, s, false, false ); // $ExpectType uint32ndarray - sliceDimensionFrom( empty( 'uint16', sh, order ), 1, s, false, false ); // $ExpectType uint16ndarray - sliceDimensionFrom( empty( 'uint8', sh, order ), 1, s, false, false ); // $ExpectType uint8ndarray - sliceDimensionFrom( empty( 'uint8c', sh, order ), 1, s, false, false ); // $ExpectType uint8cndarray - - sliceDimensionFrom( empty( 'float64', sh, order ), 1, s, true, true ); // $ExpectType float64ndarray - sliceDimensionFrom( empty( 'float32', sh, order ), 1, s, true, true ); // $ExpectType float32ndarray - sliceDimensionFrom( empty( 'complex128', sh, order ), 1, s, true, true ); // $ExpectType complex128ndarray - sliceDimensionFrom( empty( 'complex64', sh, order ), 1, s, true, true ); // $ExpectType complex64ndarray - sliceDimensionFrom( empty( 'int32', sh, order ), 1, s, true, true ); // $ExpectType int32ndarray - sliceDimensionFrom( empty( 'int16', sh, order ), 1, s, true, true ); // $ExpectType int16ndarray - sliceDimensionFrom( empty( 'int8', sh, order ), 1, s, true, true ); // $ExpectType int8ndarray - sliceDimensionFrom( empty( 'uint32', sh, order ), 1, s, true, true ); // $ExpectType uint32ndarray - sliceDimensionFrom( empty( 'uint16', sh, order ), 1, s, true, true ); // $ExpectType uint16ndarray - sliceDimensionFrom( empty( 'uint8', sh, order ), 1, s, true, true ); // $ExpectType uint8ndarray - sliceDimensionFrom( empty( 'uint8c', sh, order ), 1, s, true, true ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const s = 0; - - sliceDimensionFrom( '10', 1, s, false, false ); // $ExpectError - sliceDimensionFrom( 10, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( false, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( true, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( null, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( [], 1, s, false, false ); // $ExpectError - sliceDimensionFrom( {}, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( ( x: number ): number => x, 1, s, false, false ); // $ExpectError - - sliceDimensionFrom( '10', 1, s, true, true ); // $ExpectError - sliceDimensionFrom( 10, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( false, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( true, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( null, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( [], 1, s, true, true ); // $ExpectError - sliceDimensionFrom( {}, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( ( x: number ): number => x, 1, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a number... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 1; - - sliceDimensionFrom( x, '5', s, false, false ); // $ExpectError - sliceDimensionFrom( x, false, s, false, false ); // $ExpectError - sliceDimensionFrom( x, true, s, false, false ); // $ExpectError - sliceDimensionFrom( x, null, s, false, false ); // $ExpectError - sliceDimensionFrom( x, undefined, s, false, false ); // $ExpectError - sliceDimensionFrom( x, [ '5' ], s, false, false ); // $ExpectError - sliceDimensionFrom( x, {}, s, false, false ); // $ExpectError - sliceDimensionFrom( x, ( x: number ): number => x, s, false, false ); // $ExpectError - - sliceDimensionFrom( x, '5', s, true, true ); // $ExpectError - sliceDimensionFrom( x, false, s, true, true ); // $ExpectError - sliceDimensionFrom( x, true, s, true, true ); // $ExpectError - sliceDimensionFrom( x, null, s, true, true ); // $ExpectError - sliceDimensionFrom( x, undefined, s, true, true ); // $ExpectError - sliceDimensionFrom( x, [ '5' ], s, true, true ); // $ExpectError - sliceDimensionFrom( x, {}, s, true, true ); // $ExpectError - sliceDimensionFrom( x, ( x: number ): number => x, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceDimensionFrom( x, 1, '5', false, false ); // $ExpectError - sliceDimensionFrom( x, 1, false, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, true, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, null, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, undefined, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, [ '5' ], false, false ); // $ExpectError - sliceDimensionFrom( x, 1, {}, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, ( x: number ): number => x, 1, false, false ); // $ExpectError - - sliceDimensionFrom( x, 1, '5', true, true ); // $ExpectError - sliceDimensionFrom( x, 1, false, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, true, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, null, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, undefined, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, [ '5' ], true, true ); // $ExpectError - sliceDimensionFrom( x, 1, {}, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, ( x: number ): number => x, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x, 1, s, '5', false ); // $ExpectError - sliceDimensionFrom( x, 1, s, 5, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, null, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, undefined, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, [ '5' ], false ); // $ExpectError - sliceDimensionFrom( x, 1, s, {}, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x, 1, s, false, '5' ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, 5 ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, null ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, undefined ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, [ '5' ] ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, {} ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x ); // $ExpectError - sliceDimensionFrom( x, 1 ); // $ExpectError - sliceDimensionFrom( x, 1, s ); // $ExpectError - sliceDimensionFrom( x, 1, s, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index b17162a..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 sliceDimensionFrom = 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 = sliceDimensionFrom( x, 1, 1, false, false ); -// 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 columns of each matrix: -var y2 = sliceDimensionFrom( x, 2, 1, false, false ); -// returns - -var a2 = ndarray2array( y2 ); -console.log( a2 ); -// => [ [ [ 1, 2 ], [ 4, 5 ], [ 7, 8 ] ], [ [ 10, 11 ], [ 13, 14 ], [ 16, 17 ] ], [ [ 19, 20 ], [ 22, 23 ], [ 25, 26 ] ] ] - -// Get the last two matrices: -var y3 = sliceDimensionFrom( x, 0, 1, false, false ); -// returns - -var a3 = ndarray2array( y3 ); -console.log( a3 ); -// => [ [ [ 9, 10, 11 ], [ 12, 13, 14 ], [ 15, 16, 17 ] ], [ [ 18, 19, 20 ], [ 21, 22, 23 ], [ 24, 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 2d4595f..1248b30 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..21713c6 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-ctor@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndims@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-normalize-index@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-filled@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function m(m,o,a,l,j){var h,v,b;if(0===(v=i(m)))throw new TypeError(d("invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.",v));if(-1===(b=r(o,v-1)))throw new RangeError(d("invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.",v,o));return(h=t(null,v))[b]=new s(a,null),n(m,e(h),l,j)}export{m as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..11cf251 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport Slice from '@stdlib/slice-ctor';\nimport ndims from '@stdlib/ndarray-base-ndims';\nimport slice from '@stdlib/ndarray-base-slice';\nimport normalizeIndex from '@stdlib/ndarray-base-normalize-index';\nimport filled from '@stdlib/array-base-filled';\nimport format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Returns a shifted view of an input ndarray along a specified dimension.\n*\n* @param {ndarray} x - input array\n* @param {integer} dim - index of dimension to slice\n* @param {integer} start - starting index (inclusive)\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {TypeError} first argument must be an ndarray having one or more dimensions\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\n*\n* @example\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceDimensionFrom( x, 0, 1, false, false );\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 sliceDimensionFrom( x, dim, start, strict, writable ) {\n\tvar args;\n\tvar N;\n\tvar d;\n\n\t// Retrieve array meta data:\n\tN = ndims( x );\n\n\t// Check whether we were provided a zero-dimensional array...\n\tif ( N === 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.', N ) );\n\t}\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, N-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', N, dim ) );\n\t}\n\t// Define a list of slice arguments:\n\targs = filled( null, N );\n\targs[ d ] = new Slice( start, null );\n\n\t// Return a new array view:\n\treturn slice( x, args2multislice( args ), strict, writable );\n}\n\n\n// EXPORTS //\n\nexport default sliceDimensionFrom;\n"],"names":["sliceDimensionFrom","x","dim","start","strict","writable","args","N","d","ndims","TypeError","format","normalizeIndex","RangeError","filled","Slice","slice","args2multislice"],"mappings":";;woBAyEA,SAASA,EAAoBC,EAAGC,EAAKC,EAAOC,EAAQC,GACnD,IAAIC,EACAC,EACAC,EAMJ,GAAW,KAHXD,EAAIE,EAAOR,IAIV,MAAM,IAAIS,UAAWC,EAAQ,+GAAgHJ,IAI9I,IAAY,KADZC,EAAII,EAAgBV,EAAKK,EAAE,IAE1B,MAAM,IAAIM,WAAYF,EAAQ,6GAA8GJ,EAAGL,IAOhJ,OAJAI,EAAOQ,EAAQ,KAAMP,IACfC,GAAM,IAAIO,EAAOZ,EAAO,MAGvBa,EAAOf,EAAGgB,EAAiBX,GAAQF,EAAQC,EACnD"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 763aa0f..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 shifted view of an input ndarray along a specified dimension. -* -* @module @stdlib/ndarray-base-slice-dimension-from -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var sliceDimensionFrom = require( '@stdlib/ndarray-base-slice-dimension-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 = sliceDimensionFrom( x, 0, 2, false, false ); -* // 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 2b8e198..0000000 --- a/lib/main.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var Slice = require( '@stdlib/slice-ctor' ); -var ndims = require( '@stdlib/ndarray-base-ndims' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' ); -var filled = require( '@stdlib/array-base-filled' ); -var format = require( '@stdlib/string-format' ); - - -// MAIN // - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param {ndarray} x - input array -* @param {integer} dim - index of dimension to slice -* @param {integer} start - starting index (inclusive) -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @param {boolean} writable - boolean indicating whether a returned array should be writable -* @throws {TypeError} first argument must be an ndarray having one or more dimensions -* @throws {RangeError} dimension index exceeds the number of dimensions -* @throws {RangeError} slice 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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -function sliceDimensionFrom( x, dim, start, strict, writable ) { - var args; - var N; - var d; - - // Retrieve array meta data: - N = ndims( x ); - - // Check whether we were provided a zero-dimensional array... - if ( N === 0 ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.', N ) ); - } - // Normalize the dimension index: - d = normalizeIndex( dim, N-1 ); - if ( d === -1 ) { - throw new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', N, dim ) ); - } - // Define a list of slice arguments: - args = filled( null, N ); - args[ d ] = new Slice( start, null ); - - // Return a new array view: - return slice( x, args2multislice( args ), strict, writable ); -} - - -// EXPORTS // - -module.exports = sliceDimensionFrom; diff --git a/package.json b/package.json index 3c963c7..c50f860 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Return a shifted view of an input ndarray along a specific dimension.", "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,49 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-filled": "^0.1.0", - "@stdlib/ndarray-base-ndims": "^0.1.0", - "@stdlib/ndarray-base-normalize-index": "github:stdlib-js/ndarray-base-normalize-index#main", - "@stdlib/ndarray-base-slice": "^0.1.0", - "@stdlib/slice-base-args2multislice": "^0.1.0", - "@stdlib/slice-ctor": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.1.0" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/array-typed": "^0.1.0", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/bench": "^0.1.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-base-assert-is-read-only": "^0.1.1", - "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/ndarray-base-empty": "^0.1.0", - "@stdlib/ndarray-base-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" - }, - "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..7dfcff2 --- /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 99789bd..0000000 --- a/test/test.js +++ /dev/null @@ -1,616 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 ndarray2array = require( '@stdlib/ndarray-to-array' ); -var baseCtor = require( '@stdlib/ndarray-base-ctor' ); -var ctor = require( '@stdlib/ndarray-ctor' ); -var sliceDimensionFrom = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sliceDimensionFrom, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a zero-dimensional array (strict=false)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error' ); - } - t.end(); - - function badValue( x ) { - return function badValue() { - sliceDimensionFrom( x, 0, 0, false, false ); - }; - } -}); - -tape( 'the function throws an error if provided a zero-dimensional array (strict=true)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error' ); - } - t.end(); - - function badValue( x ) { - return function badValue() { - sliceDimensionFrom( x, 0, 0, true, false ); - }; - } -}); - -tape( 'the function throws an error if the dimension index exceeds the number of dimensions (strict=false)', 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 ], 10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - t.throws( badValue( values[ i ], -10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - } - t.end(); - - function badValue( x, dim ) { - return function badValue() { - sliceDimensionFrom( x, dim, 0, false, false ); - }; - } -}); - -tape( 'the function throws an error if the dimension index exceeds the number of dimensions (strict=true)', 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 ], 10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - t.throws( badValue( values[ i ], -10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - } - t.end(); - - function badValue( x, dim ) { - return function badValue() { - sliceDimensionFrom( x, dim, 0, true, false ); - }; - } -}); - -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, - 20, - 20, - 20 - ]; - 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() { - sliceDimensionFrom( x, 0, s, true, false ); - }; - } -}); - -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, - 20, - 20, - 20, - 10 - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceDimensionFrom( values[ i ], 0, start[ i ], false, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), 0, 'returns expected value' ); - t.strictEqual( actual.dtype, values[ i ].dtype, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns an empty array when a starting index is the one more than the last index along a dimension', function test( t ) { - var actual; - var values; - var start; - var dim; - 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' } ) - ]; - - dim = [ - 0, - 1, - 0, - 1, - 4 - ]; - - start = [ - 1, - 1, - 1, - 1, - 1 - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceDimensionFrom( values[ i ], dim[ i ], start[ i ], false, false ); // eslint-disable-line max-len - 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 a shifted view of a provided input array (ndims=1)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 2, true, false ); - - 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 = sliceDimensionFrom( x, 0, -4, true, false ); - - 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)', 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 1, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 2, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, -2, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 1, 1, true, false ); - - 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 = sliceDimensionFrom( x, 1, -2, true, false ); - - 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' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=3)', 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 1, true, false ); - - 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 = sliceDimensionFrom( x, 1, 1, true, false ); - - 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 = sliceDimensionFrom( x, 2, 2, true, false ); - - 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 = sliceDimensionFrom( x, 2, -1, true, false ); - - 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' ); - t.end(); -}); - -tape( 'if a provided ndarray has a constructor supporting read-only instances, the function returns a read-only instance', function test( t ) { - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - x = new baseCtor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports returning writable views', function test( t ) { - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - x = new baseCtor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - t.end(); -}); From f592dadd17ae10014618ffa2a22ea3f16b0c8366 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 21 Oct 2023 01:08:50 +0000 Subject: [PATCH 03/92] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index da4e09b..3c963c7 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/ndarray-base-slice": "^0.1.0", "@stdlib/slice-base-args2multislice": "^0.1.0", "@stdlib/slice-ctor": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.1.0" }, "devDependencies": { From 298c9bd7d7d227aa06ed4c7391dfd2be6a513396 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 21 Oct 2023 01:25:42 +0000 Subject: [PATCH 04/92] Remove files --- index.d.ts | 534 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6716 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 1248b30..0000000 --- a/index.d.ts +++ /dev/null @@ -1,534 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceDimensionFrom( x: float64ndarray, dim: number, start: number, strict: boolean, writable: boolean ): float64ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceDimensionFrom( x: float32ndarray, dim: number, start: number, strict: boolean, writable: boolean ): float32ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: int32ndarray, dim: number, start: number, strict: boolean, writable: boolean ): int32ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: int16ndarray, dim: number, start: number, strict: boolean, writable: boolean ): int16ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: int8ndarray, dim: number, start: number, strict: boolean, writable: boolean ): int8ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint32ndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint32ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint16ndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint16ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint8ndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint8ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint8cndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint8cndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceDimensionFrom( x: complex128ndarray, dim: number, start: number, strict: boolean, writable: boolean ): complex128ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceDimensionFrom( x: complex64ndarray, dim: number, start: number, strict: boolean, writable: boolean ): complex64ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: genericndarray, dim: number, start: number, strict: boolean, writable: boolean ): genericndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: typedndarray, dim: number, start: number, strict: boolean, writable: boolean ): typedndarray; - - -// EXPORTS // - -export = sliceDimensionFrom; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 21713c6..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-ctor@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndims@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-normalize-index@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-filled@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function m(m,o,a,l,j){var h,v,b;if(0===(v=i(m)))throw new TypeError(d("invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.",v));if(-1===(b=r(o,v-1)))throw new RangeError(d("invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.",v,o));return(h=t(null,v))[b]=new s(a,null),n(m,e(h),l,j)}export{m as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 11cf251..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport Slice from '@stdlib/slice-ctor';\nimport ndims from '@stdlib/ndarray-base-ndims';\nimport slice from '@stdlib/ndarray-base-slice';\nimport normalizeIndex from '@stdlib/ndarray-base-normalize-index';\nimport filled from '@stdlib/array-base-filled';\nimport format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Returns a shifted view of an input ndarray along a specified dimension.\n*\n* @param {ndarray} x - input array\n* @param {integer} dim - index of dimension to slice\n* @param {integer} start - starting index (inclusive)\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {TypeError} first argument must be an ndarray having one or more dimensions\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\n*\n* @example\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceDimensionFrom( x, 0, 1, false, false );\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 sliceDimensionFrom( x, dim, start, strict, writable ) {\n\tvar args;\n\tvar N;\n\tvar d;\n\n\t// Retrieve array meta data:\n\tN = ndims( x );\n\n\t// Check whether we were provided a zero-dimensional array...\n\tif ( N === 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.', N ) );\n\t}\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, N-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', N, dim ) );\n\t}\n\t// Define a list of slice arguments:\n\targs = filled( null, N );\n\targs[ d ] = new Slice( start, null );\n\n\t// Return a new array view:\n\treturn slice( x, args2multislice( args ), strict, writable );\n}\n\n\n// EXPORTS //\n\nexport default sliceDimensionFrom;\n"],"names":["sliceDimensionFrom","x","dim","start","strict","writable","args","N","d","ndims","TypeError","format","normalizeIndex","RangeError","filled","Slice","slice","args2multislice"],"mappings":";;woBAyEA,SAASA,EAAoBC,EAAGC,EAAKC,EAAOC,EAAQC,GACnD,IAAIC,EACAC,EACAC,EAMJ,GAAW,KAHXD,EAAIE,EAAOR,IAIV,MAAM,IAAIS,UAAWC,EAAQ,+GAAgHJ,IAI9I,IAAY,KADZC,EAAII,EAAgBV,EAAKK,EAAE,IAE1B,MAAM,IAAIM,WAAYF,EAAQ,6GAA8GJ,EAAGL,IAOhJ,OAJAI,EAAOQ,EAAQ,KAAMP,IACfC,GAAM,IAAIO,EAAOZ,EAAO,MAGvBa,EAAOf,EAAGgB,EAAiBX,GAAQF,EAAQC,EACnD"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 7dfcff2..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 8690be837aa02be477144278ca82143f18c1fdc6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 21 Oct 2023 01:27:12 +0000 Subject: [PATCH 05/92] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 43 +- benchmark/benchmark.js | 681 --- branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 49 - docs/types/test.ts | 164 - 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 | 102 - package.json | 70 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 616 -- 41 files changed, 6203 insertions(+), 5092 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 05d1840..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-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 ab56cca..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index ced95ae..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-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 c1c45e7..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 2dd36ec..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: '38 14 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -200,7 +193,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]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index b906eff..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,681 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var baseEmpty = require( '@stdlib/ndarray-base-empty' ); -var empty = require( '@stdlib/ndarray-empty' ); -var pkg = require( './../package.json' ).name; -var sliceDimensionFrom = require( './../lib' ); - - -// MAIN // - -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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2 ], { 'dtype': 'float64' } ), - empty( [ 2 ], { 'dtype': 'float32' } ), - empty( [ 2 ], { 'dtype': 'int32' } ), - empty( [ 2 ], { 'dtype': 'complex128' } ), - empty( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== '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 d8a1299..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-from" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-from -[production-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-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 2ab577a..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import sliceDimensionFrom from '../docs/types/index'; -export = sliceDimensionFrom; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 1b0db5f..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var l=function(i,r){return function(){return r||i((r={exports:{}}).exports,r),r.exports}};var o=l(function(p,u){ -var v=require('@stdlib/slice-base-args2multislice/dist'),c=require('@stdlib/slice-ctor/dist'),f=require('@stdlib/ndarray-base-ndims/dist'),q=require('@stdlib/ndarray-base-slice/dist'),g=require('@stdlib/ndarray-base-normalize-index/dist'),w=require('@stdlib/array-base-filled/dist'),s=require('@stdlib/error-tools-fmtprodmsg/dist');function b(i,r,m,t,d){var n,e,a;if(e=f(i),e===0)throw new TypeError(s('nullF7',e));if(a=g(r,e-1),a===-1)throw new RangeError(s('nullF8',e,r));return n=w(null,e),n[a]=new c(m,null),q(i,v(n),t,d)}u.exports=b -});var h=o();module.exports=h; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index a75b3e0..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar args2multislice = require( '@stdlib/slice-base-args2multislice' );\nvar Slice = require( '@stdlib/slice-ctor' );\nvar ndims = require( '@stdlib/ndarray-base-ndims' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' );\nvar filled = require( '@stdlib/array-base-filled' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns a shifted view of an input ndarray along a specified dimension.\n*\n* @param {ndarray} x - input array\n* @param {integer} dim - index of dimension to slice\n* @param {integer} start - starting index (inclusive)\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {TypeError} first argument must be an ndarray having one or more dimensions\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceDimensionFrom( x, 0, 1, false, false );\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 sliceDimensionFrom( x, dim, start, strict, writable ) {\n\tvar args;\n\tvar N;\n\tvar d;\n\n\t// Retrieve array meta data:\n\tN = ndims( x );\n\n\t// Check whether we were provided a zero-dimensional array...\n\tif ( N === 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.', N ) );\n\t}\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, N-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', N, dim ) );\n\t}\n\t// Define a list of slice arguments:\n\targs = filled( null, N );\n\targs[ d ] = new Slice( start, null );\n\n\t// Return a new array view:\n\treturn slice( x, args2multislice( args ), strict, writable );\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceDimensionFrom;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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 shifted view of an input ndarray along a specified dimension.\n*\n* @module @stdlib/ndarray-base-slice-dimension-from\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var sliceDimensionFrom = require( '@stdlib/ndarray-base-slice-dimension-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 = sliceDimensionFrom( x, 0, 1, false, false );\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,EAAkB,QAAS,oCAAqC,EAChEC,EAAQ,QAAS,oBAAqB,EACtCC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAiB,QAAS,sCAAuC,EACjEC,EAAS,QAAS,2BAA4B,EAC9CC,EAAS,QAAS,uBAAwB,EA6C9C,SAASC,EAAoBC,EAAGC,EAAKC,EAAOC,EAAQC,EAAW,CAC9D,IAAIC,EACAC,EACAC,EAMJ,GAHAD,EAAIZ,EAAOM,CAAE,EAGRM,IAAM,EACV,MAAM,IAAI,UAAWR,EAAQ,+GAAgHQ,CAAE,CAAE,EAIlJ,GADAC,EAAIX,EAAgBK,EAAKK,EAAE,CAAE,EACxBC,IAAM,GACV,MAAM,IAAI,WAAYT,EAAQ,6GAA8GQ,EAAGL,CAAI,CAAE,EAGtJ,OAAAI,EAAOR,EAAQ,KAAMS,CAAE,EACvBD,EAAME,CAAE,EAAI,IAAId,EAAOS,EAAO,IAAK,EAG5BP,EAAOK,EAAGR,EAAiBa,CAAK,EAAGF,EAAQC,CAAS,CAC5D,CAKAb,EAAO,QAAUQ,IC7CjB,IAAIS,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "args2multislice", "Slice", "ndims", "slice", "normalizeIndex", "filled", "format", "sliceDimensionFrom", "x", "dim", "start", "strict", "writable", "args", "N", "d", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ffc1f03..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,49 +0,0 @@ - -{{alias}}( x, dim, start, strict, writable ) - Returns a shifted view of an input ndarray along a specified dimension. - - Parameters - ---------- - x: ndarray - Input array. - - dim: integer - Index of dimension to slice. If less than zero, the index is resolved - relative to the last dimension, with the last dimension corresponding to - the value `-1`. - - start: integer - Starting index (inclusive). If less than zero, the corresponding element - along the specified dimension is resolved relative to the last element - along that dimension. For negative integers, the last element - corresponds to the value `-1`. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - writable: boolean - Boolean indicating whether a returned ndarray should be writable. This - parameter only applies to ndarray constructors which support read-only - instances. - - Returns - ------- - out: ndarray - Output array view. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > x.shape - [ 2, 2 ] - > var y = {{alias}}( x, 1, 1, false, false ) - - > 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 9dfeaf3..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,164 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sliceDimensionFrom = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = 0; - - sliceDimensionFrom( empty( 'float64', sh, order ), 1, s, false, false ); // $ExpectType float64ndarray - sliceDimensionFrom( empty( 'float32', sh, order ), 1, s, false, false ); // $ExpectType float32ndarray - sliceDimensionFrom( empty( 'complex128', sh, order ), 1, s, false, false ); // $ExpectType complex128ndarray - sliceDimensionFrom( empty( 'complex64', sh, order ), 1, s, false, false ); // $ExpectType complex64ndarray - sliceDimensionFrom( empty( 'int32', sh, order ), 1, s, false, false ); // $ExpectType int32ndarray - sliceDimensionFrom( empty( 'int16', sh, order ), 1, s, false, false ); // $ExpectType int16ndarray - sliceDimensionFrom( empty( 'int8', sh, order ), 1, s, false, false ); // $ExpectType int8ndarray - sliceDimensionFrom( empty( 'uint32', sh, order ), 1, s, false, false ); // $ExpectType uint32ndarray - sliceDimensionFrom( empty( 'uint16', sh, order ), 1, s, false, false ); // $ExpectType uint16ndarray - sliceDimensionFrom( empty( 'uint8', sh, order ), 1, s, false, false ); // $ExpectType uint8ndarray - sliceDimensionFrom( empty( 'uint8c', sh, order ), 1, s, false, false ); // $ExpectType uint8cndarray - - sliceDimensionFrom( empty( 'float64', sh, order ), 1, s, true, true ); // $ExpectType float64ndarray - sliceDimensionFrom( empty( 'float32', sh, order ), 1, s, true, true ); // $ExpectType float32ndarray - sliceDimensionFrom( empty( 'complex128', sh, order ), 1, s, true, true ); // $ExpectType complex128ndarray - sliceDimensionFrom( empty( 'complex64', sh, order ), 1, s, true, true ); // $ExpectType complex64ndarray - sliceDimensionFrom( empty( 'int32', sh, order ), 1, s, true, true ); // $ExpectType int32ndarray - sliceDimensionFrom( empty( 'int16', sh, order ), 1, s, true, true ); // $ExpectType int16ndarray - sliceDimensionFrom( empty( 'int8', sh, order ), 1, s, true, true ); // $ExpectType int8ndarray - sliceDimensionFrom( empty( 'uint32', sh, order ), 1, s, true, true ); // $ExpectType uint32ndarray - sliceDimensionFrom( empty( 'uint16', sh, order ), 1, s, true, true ); // $ExpectType uint16ndarray - sliceDimensionFrom( empty( 'uint8', sh, order ), 1, s, true, true ); // $ExpectType uint8ndarray - sliceDimensionFrom( empty( 'uint8c', sh, order ), 1, s, true, true ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const s = 0; - - sliceDimensionFrom( '10', 1, s, false, false ); // $ExpectError - sliceDimensionFrom( 10, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( false, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( true, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( null, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( [], 1, s, false, false ); // $ExpectError - sliceDimensionFrom( {}, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( ( x: number ): number => x, 1, s, false, false ); // $ExpectError - - sliceDimensionFrom( '10', 1, s, true, true ); // $ExpectError - sliceDimensionFrom( 10, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( false, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( true, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( null, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( [], 1, s, true, true ); // $ExpectError - sliceDimensionFrom( {}, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( ( x: number ): number => x, 1, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a number... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 1; - - sliceDimensionFrom( x, '5', s, false, false ); // $ExpectError - sliceDimensionFrom( x, false, s, false, false ); // $ExpectError - sliceDimensionFrom( x, true, s, false, false ); // $ExpectError - sliceDimensionFrom( x, null, s, false, false ); // $ExpectError - sliceDimensionFrom( x, undefined, s, false, false ); // $ExpectError - sliceDimensionFrom( x, [ '5' ], s, false, false ); // $ExpectError - sliceDimensionFrom( x, {}, s, false, false ); // $ExpectError - sliceDimensionFrom( x, ( x: number ): number => x, s, false, false ); // $ExpectError - - sliceDimensionFrom( x, '5', s, true, true ); // $ExpectError - sliceDimensionFrom( x, false, s, true, true ); // $ExpectError - sliceDimensionFrom( x, true, s, true, true ); // $ExpectError - sliceDimensionFrom( x, null, s, true, true ); // $ExpectError - sliceDimensionFrom( x, undefined, s, true, true ); // $ExpectError - sliceDimensionFrom( x, [ '5' ], s, true, true ); // $ExpectError - sliceDimensionFrom( x, {}, s, true, true ); // $ExpectError - sliceDimensionFrom( x, ( x: number ): number => x, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceDimensionFrom( x, 1, '5', false, false ); // $ExpectError - sliceDimensionFrom( x, 1, false, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, true, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, null, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, undefined, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, [ '5' ], false, false ); // $ExpectError - sliceDimensionFrom( x, 1, {}, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, ( x: number ): number => x, 1, false, false ); // $ExpectError - - sliceDimensionFrom( x, 1, '5', true, true ); // $ExpectError - sliceDimensionFrom( x, 1, false, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, true, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, null, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, undefined, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, [ '5' ], true, true ); // $ExpectError - sliceDimensionFrom( x, 1, {}, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, ( x: number ): number => x, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x, 1, s, '5', false ); // $ExpectError - sliceDimensionFrom( x, 1, s, 5, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, null, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, undefined, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, [ '5' ], false ); // $ExpectError - sliceDimensionFrom( x, 1, s, {}, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x, 1, s, false, '5' ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, 5 ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, null ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, undefined ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, [ '5' ] ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, {} ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x ); // $ExpectError - sliceDimensionFrom( x, 1 ); // $ExpectError - sliceDimensionFrom( x, 1, s ); // $ExpectError - sliceDimensionFrom( x, 1, s, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index b17162a..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 sliceDimensionFrom = 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 = sliceDimensionFrom( x, 1, 1, false, false ); -// 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 columns of each matrix: -var y2 = sliceDimensionFrom( x, 2, 1, false, false ); -// returns - -var a2 = ndarray2array( y2 ); -console.log( a2 ); -// => [ [ [ 1, 2 ], [ 4, 5 ], [ 7, 8 ] ], [ [ 10, 11 ], [ 13, 14 ], [ 16, 17 ] ], [ [ 19, 20 ], [ 22, 23 ], [ 25, 26 ] ] ] - -// Get the last two matrices: -var y3 = sliceDimensionFrom( x, 0, 1, false, false ); -// returns - -var a3 = ndarray2array( y3 ); -console.log( a3 ); -// => [ [ [ 9, 10, 11 ], [ 12, 13, 14 ], [ 15, 16, 17 ] ], [ [ 18, 19, 20 ], [ 21, 22, 23 ], [ 24, 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 2d4595f..1248b30 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..21713c6 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-ctor@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndims@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-normalize-index@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-filled@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function m(m,o,a,l,j){var h,v,b;if(0===(v=i(m)))throw new TypeError(d("invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.",v));if(-1===(b=r(o,v-1)))throw new RangeError(d("invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.",v,o));return(h=t(null,v))[b]=new s(a,null),n(m,e(h),l,j)}export{m as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..11cf251 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport Slice from '@stdlib/slice-ctor';\nimport ndims from '@stdlib/ndarray-base-ndims';\nimport slice from '@stdlib/ndarray-base-slice';\nimport normalizeIndex from '@stdlib/ndarray-base-normalize-index';\nimport filled from '@stdlib/array-base-filled';\nimport format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Returns a shifted view of an input ndarray along a specified dimension.\n*\n* @param {ndarray} x - input array\n* @param {integer} dim - index of dimension to slice\n* @param {integer} start - starting index (inclusive)\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {TypeError} first argument must be an ndarray having one or more dimensions\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\n*\n* @example\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceDimensionFrom( x, 0, 1, false, false );\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 sliceDimensionFrom( x, dim, start, strict, writable ) {\n\tvar args;\n\tvar N;\n\tvar d;\n\n\t// Retrieve array meta data:\n\tN = ndims( x );\n\n\t// Check whether we were provided a zero-dimensional array...\n\tif ( N === 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.', N ) );\n\t}\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, N-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', N, dim ) );\n\t}\n\t// Define a list of slice arguments:\n\targs = filled( null, N );\n\targs[ d ] = new Slice( start, null );\n\n\t// Return a new array view:\n\treturn slice( x, args2multislice( args ), strict, writable );\n}\n\n\n// EXPORTS //\n\nexport default sliceDimensionFrom;\n"],"names":["sliceDimensionFrom","x","dim","start","strict","writable","args","N","d","ndims","TypeError","format","normalizeIndex","RangeError","filled","Slice","slice","args2multislice"],"mappings":";;woBAyEA,SAASA,EAAoBC,EAAGC,EAAKC,EAAOC,EAAQC,GACnD,IAAIC,EACAC,EACAC,EAMJ,GAAW,KAHXD,EAAIE,EAAOR,IAIV,MAAM,IAAIS,UAAWC,EAAQ,+GAAgHJ,IAI9I,IAAY,KADZC,EAAII,EAAgBV,EAAKK,EAAE,IAE1B,MAAM,IAAIM,WAAYF,EAAQ,6GAA8GJ,EAAGL,IAOhJ,OAJAI,EAAOQ,EAAQ,KAAMP,IACfC,GAAM,IAAIO,EAAOZ,EAAO,MAGvBa,EAAOf,EAAGgB,EAAiBX,GAAQF,EAAQC,EACnD"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index b3f97b2..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 shifted view of an input ndarray along a specified dimension. -* -* @module @stdlib/ndarray-base-slice-dimension-from -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var sliceDimensionFrom = require( '@stdlib/ndarray-base-slice-dimension-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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // 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 2b8e198..0000000 --- a/lib/main.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var Slice = require( '@stdlib/slice-ctor' ); -var ndims = require( '@stdlib/ndarray-base-ndims' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' ); -var filled = require( '@stdlib/array-base-filled' ); -var format = require( '@stdlib/string-format' ); - - -// MAIN // - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param {ndarray} x - input array -* @param {integer} dim - index of dimension to slice -* @param {integer} start - starting index (inclusive) -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @param {boolean} writable - boolean indicating whether a returned array should be writable -* @throws {TypeError} first argument must be an ndarray having one or more dimensions -* @throws {RangeError} dimension index exceeds the number of dimensions -* @throws {RangeError} slice 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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -function sliceDimensionFrom( x, dim, start, strict, writable ) { - var args; - var N; - var d; - - // Retrieve array meta data: - N = ndims( x ); - - // Check whether we were provided a zero-dimensional array... - if ( N === 0 ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.', N ) ); - } - // Normalize the dimension index: - d = normalizeIndex( dim, N-1 ); - if ( d === -1 ) { - throw new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', N, dim ) ); - } - // Define a list of slice arguments: - args = filled( null, N ); - args[ d ] = new Slice( start, null ); - - // Return a new array view: - return slice( x, args2multislice( args ), strict, writable ); -} - - -// EXPORTS // - -module.exports = sliceDimensionFrom; diff --git a/package.json b/package.json index 3c963c7..c50f860 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Return a shifted view of an input ndarray along a specific dimension.", "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,49 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-filled": "^0.1.0", - "@stdlib/ndarray-base-ndims": "^0.1.0", - "@stdlib/ndarray-base-normalize-index": "github:stdlib-js/ndarray-base-normalize-index#main", - "@stdlib/ndarray-base-slice": "^0.1.0", - "@stdlib/slice-base-args2multislice": "^0.1.0", - "@stdlib/slice-ctor": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.1.0" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/array-typed": "^0.1.0", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/bench": "^0.1.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-base-assert-is-read-only": "^0.1.1", - "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/ndarray-base-empty": "^0.1.0", - "@stdlib/ndarray-base-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" - }, - "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..33ade19 --- /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 28703b5..0000000 --- a/test/test.js +++ /dev/null @@ -1,616 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 ndarray2array = require( '@stdlib/ndarray-to-array' ); -var baseCtor = require( '@stdlib/ndarray-base-ctor' ); -var ctor = require( '@stdlib/ndarray-ctor' ); -var sliceDimensionFrom = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sliceDimensionFrom, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a zero-dimensional array (strict=false)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error' ); - } - t.end(); - - function badValue( x ) { - return function badValue() { - sliceDimensionFrom( x, 0, 0, false, false ); - }; - } -}); - -tape( 'the function throws an error if provided a zero-dimensional array (strict=true)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error' ); - } - t.end(); - - function badValue( x ) { - return function badValue() { - sliceDimensionFrom( x, 0, 0, true, false ); - }; - } -}); - -tape( 'the function throws an error if the dimension index exceeds the number of dimensions (strict=false)', 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 ], 10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - t.throws( badValue( values[ i ], -10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - } - t.end(); - - function badValue( x, dim ) { - return function badValue() { - sliceDimensionFrom( x, dim, 0, false, false ); - }; - } -}); - -tape( 'the function throws an error if the dimension index exceeds the number of dimensions (strict=true)', 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 ], 10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - t.throws( badValue( values[ i ], -10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - } - t.end(); - - function badValue( x, dim ) { - return function badValue() { - sliceDimensionFrom( x, dim, 0, true, false ); - }; - } -}); - -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, - 20, - 20, - 20 - ]; - 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() { - sliceDimensionFrom( x, 0, s, true, false ); - }; - } -}); - -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, - 20, - 20, - 20, - 10 - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceDimensionFrom( values[ i ], 0, start[ i ], false, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), 0, 'returns expected value' ); - t.strictEqual( actual.dtype, values[ i ].dtype, 'returns expected value' ); - } - t.end(); -}); - -tape( 'in non-strict mode, the function returns an empty array when a starting index is the one more than the last index along a dimension', function test( t ) { - var actual; - var values; - var start; - var dim; - 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' } ) - ]; - - dim = [ - 0, - 1, - 0, - 1, - 4 - ]; - - start = [ - 1, - 1, - 1, - 1, - 1 - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceDimensionFrom( values[ i ], dim[ i ], start[ i ], false, false ); // eslint-disable-line max-len - 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 a shifted view of a provided input array (ndims=1)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 2, true, false ); - - 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 = sliceDimensionFrom( x, 0, -4, true, false ); - - 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)', 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 1, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 2, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, -2, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 1, 1, true, false ); - - 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 = sliceDimensionFrom( x, 1, -2, true, false ); - - 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' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=3)', 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 1, true, false ); - - 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 = sliceDimensionFrom( x, 1, 1, true, false ); - - 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 = sliceDimensionFrom( x, 2, 2, true, false ); - - 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 = sliceDimensionFrom( x, 2, -1, true, false ); - - 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' ); - t.end(); -}); - -tape( 'if a provided ndarray has a constructor supporting read-only instances, the function returns a read-only instance', function test( t ) { - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - x = new baseCtor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports returning writable views', function test( t ) { - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - x = new baseCtor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - t.end(); -}); From 00528daf8e2fc3b8e8b99538a14ec29fb4b7a050 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Nov 2023 17:19:55 +0000 Subject: [PATCH 06/92] Transform error messages --- lib/main.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index 2b8e198..e51e511 100644 --- a/lib/main.js +++ b/lib/main.js @@ -26,7 +26,7 @@ var ndims = require( '@stdlib/ndarray-base-ndims' ); var slice = require( '@stdlib/ndarray-base-slice' ); var normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' ); var filled = require( '@stdlib/array-base-filled' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // diff --git a/package.json b/package.json index da4e09b..3c963c7 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/ndarray-base-slice": "^0.1.0", "@stdlib/slice-base-args2multislice": "^0.1.0", "@stdlib/slice-ctor": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.1.0" }, "devDependencies": { From 65420d386f148dcedbf5902bccb51ce8ab4443fa Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 3 Nov 2023 01:48:37 +0000 Subject: [PATCH 07/92] Remove files --- index.d.ts | 534 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6716 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 1248b30..0000000 --- a/index.d.ts +++ /dev/null @@ -1,534 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceDimensionFrom( x: float64ndarray, dim: number, start: number, strict: boolean, writable: boolean ): float64ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceDimensionFrom( x: float32ndarray, dim: number, start: number, strict: boolean, writable: boolean ): float32ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: int32ndarray, dim: number, start: number, strict: boolean, writable: boolean ): int32ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: int16ndarray, dim: number, start: number, strict: boolean, writable: boolean ): int16ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: int8ndarray, dim: number, start: number, strict: boolean, writable: boolean ): int8ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint32ndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint32ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint16ndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint16ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint8ndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint8ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint8cndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint8cndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceDimensionFrom( x: complex128ndarray, dim: number, start: number, strict: boolean, writable: boolean ): complex128ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceDimensionFrom( x: complex64ndarray, dim: number, start: number, strict: boolean, writable: boolean ): complex64ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: genericndarray, dim: number, start: number, strict: boolean, writable: boolean ): genericndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: typedndarray, dim: number, start: number, strict: boolean, writable: boolean ): typedndarray; - - -// EXPORTS // - -export = sliceDimensionFrom; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 21713c6..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-ctor@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndims@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-normalize-index@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-filled@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function m(m,o,a,l,j){var h,v,b;if(0===(v=i(m)))throw new TypeError(d("invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.",v));if(-1===(b=r(o,v-1)))throw new RangeError(d("invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.",v,o));return(h=t(null,v))[b]=new s(a,null),n(m,e(h),l,j)}export{m as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 11cf251..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport Slice from '@stdlib/slice-ctor';\nimport ndims from '@stdlib/ndarray-base-ndims';\nimport slice from '@stdlib/ndarray-base-slice';\nimport normalizeIndex from '@stdlib/ndarray-base-normalize-index';\nimport filled from '@stdlib/array-base-filled';\nimport format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Returns a shifted view of an input ndarray along a specified dimension.\n*\n* @param {ndarray} x - input array\n* @param {integer} dim - index of dimension to slice\n* @param {integer} start - starting index (inclusive)\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {TypeError} first argument must be an ndarray having one or more dimensions\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\n*\n* @example\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceDimensionFrom( x, 0, 1, false, false );\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 sliceDimensionFrom( x, dim, start, strict, writable ) {\n\tvar args;\n\tvar N;\n\tvar d;\n\n\t// Retrieve array meta data:\n\tN = ndims( x );\n\n\t// Check whether we were provided a zero-dimensional array...\n\tif ( N === 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.', N ) );\n\t}\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, N-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', N, dim ) );\n\t}\n\t// Define a list of slice arguments:\n\targs = filled( null, N );\n\targs[ d ] = new Slice( start, null );\n\n\t// Return a new array view:\n\treturn slice( x, args2multislice( args ), strict, writable );\n}\n\n\n// EXPORTS //\n\nexport default sliceDimensionFrom;\n"],"names":["sliceDimensionFrom","x","dim","start","strict","writable","args","N","d","ndims","TypeError","format","normalizeIndex","RangeError","filled","Slice","slice","args2multislice"],"mappings":";;woBAyEA,SAASA,EAAoBC,EAAGC,EAAKC,EAAOC,EAAQC,GACnD,IAAIC,EACAC,EACAC,EAMJ,GAAW,KAHXD,EAAIE,EAAOR,IAIV,MAAM,IAAIS,UAAWC,EAAQ,+GAAgHJ,IAI9I,IAAY,KADZC,EAAII,EAAgBV,EAAKK,EAAE,IAE1B,MAAM,IAAIM,WAAYF,EAAQ,6GAA8GJ,EAAGL,IAOhJ,OAJAI,EAAOQ,EAAQ,KAAMP,IACfC,GAAM,IAAIO,EAAOZ,EAAO,MAGvBa,EAAOf,EAAGgB,EAAiBX,GAAQF,EAAQC,EACnD"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 33ade19..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 3ce3c82e7ebf420910003ee2d7205d15e50a7e4d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 3 Nov 2023 01:50:10 +0000 Subject: [PATCH 08/92] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 43 +- benchmark/benchmark.js | 681 --- branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 49 - docs/types/test.ts | 164 - 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 | 102 - package.json | 70 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 616 -- 42 files changed, 6203 insertions(+), 5093 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 40fe5c2..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-11-01T05:35:43.783Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 05d1840..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-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 ab56cca..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index ced95ae..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-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 c1c45e7..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 2dd36ec..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: '38 14 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -200,7 +193,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]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index b906eff..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,681 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var baseEmpty = require( '@stdlib/ndarray-base-empty' ); -var empty = require( '@stdlib/ndarray-empty' ); -var pkg = require( './../package.json' ).name; -var sliceDimensionFrom = require( './../lib' ); - - -// MAIN // - -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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2 ], { 'dtype': 'float64' } ), - empty( [ 2 ], { 'dtype': 'float32' } ), - empty( [ 2 ], { 'dtype': 'int32' } ), - empty( [ 2 ], { 'dtype': 'complex128' } ), - empty( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== '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 d8a1299..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-from" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-from -[production-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-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 2ab577a..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import sliceDimensionFrom from '../docs/types/index'; -export = sliceDimensionFrom; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 1b0db5f..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var l=function(i,r){return function(){return r||i((r={exports:{}}).exports,r),r.exports}};var o=l(function(p,u){ -var v=require('@stdlib/slice-base-args2multislice/dist'),c=require('@stdlib/slice-ctor/dist'),f=require('@stdlib/ndarray-base-ndims/dist'),q=require('@stdlib/ndarray-base-slice/dist'),g=require('@stdlib/ndarray-base-normalize-index/dist'),w=require('@stdlib/array-base-filled/dist'),s=require('@stdlib/error-tools-fmtprodmsg/dist');function b(i,r,m,t,d){var n,e,a;if(e=f(i),e===0)throw new TypeError(s('nullF7',e));if(a=g(r,e-1),a===-1)throw new RangeError(s('nullF8',e,r));return n=w(null,e),n[a]=new c(m,null),q(i,v(n),t,d)}u.exports=b -});var h=o();module.exports=h; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index a75b3e0..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar args2multislice = require( '@stdlib/slice-base-args2multislice' );\nvar Slice = require( '@stdlib/slice-ctor' );\nvar ndims = require( '@stdlib/ndarray-base-ndims' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' );\nvar filled = require( '@stdlib/array-base-filled' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns a shifted view of an input ndarray along a specified dimension.\n*\n* @param {ndarray} x - input array\n* @param {integer} dim - index of dimension to slice\n* @param {integer} start - starting index (inclusive)\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {TypeError} first argument must be an ndarray having one or more dimensions\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceDimensionFrom( x, 0, 1, false, false );\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 sliceDimensionFrom( x, dim, start, strict, writable ) {\n\tvar args;\n\tvar N;\n\tvar d;\n\n\t// Retrieve array meta data:\n\tN = ndims( x );\n\n\t// Check whether we were provided a zero-dimensional array...\n\tif ( N === 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.', N ) );\n\t}\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, N-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', N, dim ) );\n\t}\n\t// Define a list of slice arguments:\n\targs = filled( null, N );\n\targs[ d ] = new Slice( start, null );\n\n\t// Return a new array view:\n\treturn slice( x, args2multislice( args ), strict, writable );\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceDimensionFrom;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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 shifted view of an input ndarray along a specified dimension.\n*\n* @module @stdlib/ndarray-base-slice-dimension-from\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var sliceDimensionFrom = require( '@stdlib/ndarray-base-slice-dimension-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 = sliceDimensionFrom( x, 0, 1, false, false );\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,EAAkB,QAAS,oCAAqC,EAChEC,EAAQ,QAAS,oBAAqB,EACtCC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAiB,QAAS,sCAAuC,EACjEC,EAAS,QAAS,2BAA4B,EAC9CC,EAAS,QAAS,uBAAwB,EA6C9C,SAASC,EAAoBC,EAAGC,EAAKC,EAAOC,EAAQC,EAAW,CAC9D,IAAIC,EACAC,EACAC,EAMJ,GAHAD,EAAIZ,EAAOM,CAAE,EAGRM,IAAM,EACV,MAAM,IAAI,UAAWR,EAAQ,+GAAgHQ,CAAE,CAAE,EAIlJ,GADAC,EAAIX,EAAgBK,EAAKK,EAAE,CAAE,EACxBC,IAAM,GACV,MAAM,IAAI,WAAYT,EAAQ,6GAA8GQ,EAAGL,CAAI,CAAE,EAGtJ,OAAAI,EAAOR,EAAQ,KAAMS,CAAE,EACvBD,EAAME,CAAE,EAAI,IAAId,EAAOS,EAAO,IAAK,EAG5BP,EAAOK,EAAGR,EAAiBa,CAAK,EAAGF,EAAQC,CAAS,CAC5D,CAKAb,EAAO,QAAUQ,IC7CjB,IAAIS,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "args2multislice", "Slice", "ndims", "slice", "normalizeIndex", "filled", "format", "sliceDimensionFrom", "x", "dim", "start", "strict", "writable", "args", "N", "d", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ffc1f03..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,49 +0,0 @@ - -{{alias}}( x, dim, start, strict, writable ) - Returns a shifted view of an input ndarray along a specified dimension. - - Parameters - ---------- - x: ndarray - Input array. - - dim: integer - Index of dimension to slice. If less than zero, the index is resolved - relative to the last dimension, with the last dimension corresponding to - the value `-1`. - - start: integer - Starting index (inclusive). If less than zero, the corresponding element - along the specified dimension is resolved relative to the last element - along that dimension. For negative integers, the last element - corresponds to the value `-1`. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - writable: boolean - Boolean indicating whether a returned ndarray should be writable. This - parameter only applies to ndarray constructors which support read-only - instances. - - Returns - ------- - out: ndarray - Output array view. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > x.shape - [ 2, 2 ] - > var y = {{alias}}( x, 1, 1, false, false ) - - > 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 9dfeaf3..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,164 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sliceDimensionFrom = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = 0; - - sliceDimensionFrom( empty( 'float64', sh, order ), 1, s, false, false ); // $ExpectType float64ndarray - sliceDimensionFrom( empty( 'float32', sh, order ), 1, s, false, false ); // $ExpectType float32ndarray - sliceDimensionFrom( empty( 'complex128', sh, order ), 1, s, false, false ); // $ExpectType complex128ndarray - sliceDimensionFrom( empty( 'complex64', sh, order ), 1, s, false, false ); // $ExpectType complex64ndarray - sliceDimensionFrom( empty( 'int32', sh, order ), 1, s, false, false ); // $ExpectType int32ndarray - sliceDimensionFrom( empty( 'int16', sh, order ), 1, s, false, false ); // $ExpectType int16ndarray - sliceDimensionFrom( empty( 'int8', sh, order ), 1, s, false, false ); // $ExpectType int8ndarray - sliceDimensionFrom( empty( 'uint32', sh, order ), 1, s, false, false ); // $ExpectType uint32ndarray - sliceDimensionFrom( empty( 'uint16', sh, order ), 1, s, false, false ); // $ExpectType uint16ndarray - sliceDimensionFrom( empty( 'uint8', sh, order ), 1, s, false, false ); // $ExpectType uint8ndarray - sliceDimensionFrom( empty( 'uint8c', sh, order ), 1, s, false, false ); // $ExpectType uint8cndarray - - sliceDimensionFrom( empty( 'float64', sh, order ), 1, s, true, true ); // $ExpectType float64ndarray - sliceDimensionFrom( empty( 'float32', sh, order ), 1, s, true, true ); // $ExpectType float32ndarray - sliceDimensionFrom( empty( 'complex128', sh, order ), 1, s, true, true ); // $ExpectType complex128ndarray - sliceDimensionFrom( empty( 'complex64', sh, order ), 1, s, true, true ); // $ExpectType complex64ndarray - sliceDimensionFrom( empty( 'int32', sh, order ), 1, s, true, true ); // $ExpectType int32ndarray - sliceDimensionFrom( empty( 'int16', sh, order ), 1, s, true, true ); // $ExpectType int16ndarray - sliceDimensionFrom( empty( 'int8', sh, order ), 1, s, true, true ); // $ExpectType int8ndarray - sliceDimensionFrom( empty( 'uint32', sh, order ), 1, s, true, true ); // $ExpectType uint32ndarray - sliceDimensionFrom( empty( 'uint16', sh, order ), 1, s, true, true ); // $ExpectType uint16ndarray - sliceDimensionFrom( empty( 'uint8', sh, order ), 1, s, true, true ); // $ExpectType uint8ndarray - sliceDimensionFrom( empty( 'uint8c', sh, order ), 1, s, true, true ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const s = 0; - - sliceDimensionFrom( '10', 1, s, false, false ); // $ExpectError - sliceDimensionFrom( 10, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( false, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( true, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( null, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( [], 1, s, false, false ); // $ExpectError - sliceDimensionFrom( {}, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( ( x: number ): number => x, 1, s, false, false ); // $ExpectError - - sliceDimensionFrom( '10', 1, s, true, true ); // $ExpectError - sliceDimensionFrom( 10, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( false, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( true, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( null, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( [], 1, s, true, true ); // $ExpectError - sliceDimensionFrom( {}, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( ( x: number ): number => x, 1, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a number... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 1; - - sliceDimensionFrom( x, '5', s, false, false ); // $ExpectError - sliceDimensionFrom( x, false, s, false, false ); // $ExpectError - sliceDimensionFrom( x, true, s, false, false ); // $ExpectError - sliceDimensionFrom( x, null, s, false, false ); // $ExpectError - sliceDimensionFrom( x, undefined, s, false, false ); // $ExpectError - sliceDimensionFrom( x, [ '5' ], s, false, false ); // $ExpectError - sliceDimensionFrom( x, {}, s, false, false ); // $ExpectError - sliceDimensionFrom( x, ( x: number ): number => x, s, false, false ); // $ExpectError - - sliceDimensionFrom( x, '5', s, true, true ); // $ExpectError - sliceDimensionFrom( x, false, s, true, true ); // $ExpectError - sliceDimensionFrom( x, true, s, true, true ); // $ExpectError - sliceDimensionFrom( x, null, s, true, true ); // $ExpectError - sliceDimensionFrom( x, undefined, s, true, true ); // $ExpectError - sliceDimensionFrom( x, [ '5' ], s, true, true ); // $ExpectError - sliceDimensionFrom( x, {}, s, true, true ); // $ExpectError - sliceDimensionFrom( x, ( x: number ): number => x, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceDimensionFrom( x, 1, '5', false, false ); // $ExpectError - sliceDimensionFrom( x, 1, false, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, true, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, null, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, undefined, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, [ '5' ], false, false ); // $ExpectError - sliceDimensionFrom( x, 1, {}, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, ( x: number ): number => x, 1, false, false ); // $ExpectError - - sliceDimensionFrom( x, 1, '5', true, true ); // $ExpectError - sliceDimensionFrom( x, 1, false, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, true, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, null, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, undefined, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, [ '5' ], true, true ); // $ExpectError - sliceDimensionFrom( x, 1, {}, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, ( x: number ): number => x, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x, 1, s, '5', false ); // $ExpectError - sliceDimensionFrom( x, 1, s, 5, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, null, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, undefined, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, [ '5' ], false ); // $ExpectError - sliceDimensionFrom( x, 1, s, {}, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x, 1, s, false, '5' ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, 5 ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, null ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, undefined ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, [ '5' ] ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, {} ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x ); // $ExpectError - sliceDimensionFrom( x, 1 ); // $ExpectError - sliceDimensionFrom( x, 1, s ); // $ExpectError - sliceDimensionFrom( x, 1, s, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index b17162a..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 sliceDimensionFrom = 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 = sliceDimensionFrom( x, 1, 1, false, false ); -// 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 columns of each matrix: -var y2 = sliceDimensionFrom( x, 2, 1, false, false ); -// returns - -var a2 = ndarray2array( y2 ); -console.log( a2 ); -// => [ [ [ 1, 2 ], [ 4, 5 ], [ 7, 8 ] ], [ [ 10, 11 ], [ 13, 14 ], [ 16, 17 ] ], [ [ 19, 20 ], [ 22, 23 ], [ 25, 26 ] ] ] - -// Get the last two matrices: -var y3 = sliceDimensionFrom( x, 0, 1, false, false ); -// returns - -var a3 = ndarray2array( y3 ); -console.log( a3 ); -// => [ [ [ 9, 10, 11 ], [ 12, 13, 14 ], [ 15, 16, 17 ] ], [ [ 18, 19, 20 ], [ 21, 22, 23 ], [ 24, 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 2d4595f..1248b30 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..c5d53d1 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-ctor@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndims@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-normalize-index@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-filled@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";function m(m,o,l,a,j){var h,p,v;if(0===(p=r(m)))throw new TypeError(d("invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.",p));if(-1===(v=n(o,p-1)))throw new RangeError(d("invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.",p,o));return(h=t(null,p))[v]=new s(l,null),i(m,e(h),a,j)}export{m as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..f450114 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport Slice from '@stdlib/slice-ctor';\nimport ndims from '@stdlib/ndarray-base-ndims';\nimport slice from '@stdlib/ndarray-base-slice';\nimport normalizeIndex from '@stdlib/ndarray-base-normalize-index';\nimport filled from '@stdlib/array-base-filled';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns a shifted view of an input ndarray along a specified dimension.\n*\n* @param {ndarray} x - input array\n* @param {integer} dim - index of dimension to slice\n* @param {integer} start - starting index (inclusive)\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {TypeError} first argument must be an ndarray having one or more dimensions\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\n*\n* @example\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceDimensionFrom( x, 0, 1, false, false );\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 sliceDimensionFrom( x, dim, start, strict, writable ) {\n\tvar args;\n\tvar N;\n\tvar d;\n\n\t// Retrieve array meta data:\n\tN = ndims( x );\n\n\t// Check whether we were provided a zero-dimensional array...\n\tif ( N === 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.', N ) );\n\t}\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, N-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', N, dim ) );\n\t}\n\t// Define a list of slice arguments:\n\targs = filled( null, N );\n\targs[ d ] = new Slice( start, null );\n\n\t// Return a new array view:\n\treturn slice( x, args2multislice( args ), strict, writable );\n}\n\n\n// EXPORTS //\n\nexport default sliceDimensionFrom;\n"],"names":["sliceDimensionFrom","x","dim","start","strict","writable","args","N","d","ndims","TypeError","format","normalizeIndex","RangeError","filled","Slice","slice","args2multislice"],"mappings":";;ipBAyEA,SAASA,EAAoBC,EAAGC,EAAKC,EAAOC,EAAQC,GACnD,IAAIC,EACAC,EACAC,EAMJ,GAAW,KAHXD,EAAIE,EAAOR,IAIV,MAAM,IAAIS,UAAWC,EAAQ,+GAAgHJ,IAI9I,IAAY,KADZC,EAAII,EAAgBV,EAAKK,EAAE,IAE1B,MAAM,IAAIM,WAAYF,EAAQ,6GAA8GJ,EAAGL,IAOhJ,OAJAI,EAAOQ,EAAQ,KAAMP,IACfC,GAAM,IAAIO,EAAOZ,EAAO,MAGvBa,EAAOf,EAAGgB,EAAiBX,GAAQF,EAAQC,EACnD"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index b3f97b2..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 shifted view of an input ndarray along a specified dimension. -* -* @module @stdlib/ndarray-base-slice-dimension-from -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var sliceDimensionFrom = require( '@stdlib/ndarray-base-slice-dimension-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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // 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 e51e511..0000000 --- a/lib/main.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var Slice = require( '@stdlib/slice-ctor' ); -var ndims = require( '@stdlib/ndarray-base-ndims' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' ); -var filled = require( '@stdlib/array-base-filled' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param {ndarray} x - input array -* @param {integer} dim - index of dimension to slice -* @param {integer} start - starting index (inclusive) -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @param {boolean} writable - boolean indicating whether a returned array should be writable -* @throws {TypeError} first argument must be an ndarray having one or more dimensions -* @throws {RangeError} dimension index exceeds the number of dimensions -* @throws {RangeError} slice 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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -function sliceDimensionFrom( x, dim, start, strict, writable ) { - var args; - var N; - var d; - - // Retrieve array meta data: - N = ndims( x ); - - // Check whether we were provided a zero-dimensional array... - if ( N === 0 ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.', N ) ); - } - // Normalize the dimension index: - d = normalizeIndex( dim, N-1 ); - if ( d === -1 ) { - throw new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', N, dim ) ); - } - // Define a list of slice arguments: - args = filled( null, N ); - args[ d ] = new Slice( start, null ); - - // Return a new array view: - return slice( x, args2multislice( args ), strict, writable ); -} - - -// EXPORTS // - -module.exports = sliceDimensionFrom; diff --git a/package.json b/package.json index 3c963c7..c50f860 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Return a shifted view of an input ndarray along a specific dimension.", "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,49 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-filled": "^0.1.0", - "@stdlib/ndarray-base-ndims": "^0.1.0", - "@stdlib/ndarray-base-normalize-index": "github:stdlib-js/ndarray-base-normalize-index#main", - "@stdlib/ndarray-base-slice": "^0.1.0", - "@stdlib/slice-base-args2multislice": "^0.1.0", - "@stdlib/slice-ctor": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.1.0" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/array-typed": "^0.1.0", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/bench": "^0.1.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-base-assert-is-read-only": "^0.1.1", - "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/ndarray-base-empty": "^0.1.0", - "@stdlib/ndarray-base-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" - }, - "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..6eb1e66 --- /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 28703b5..0000000 --- a/test/test.js +++ /dev/null @@ -1,616 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 ndarray2array = require( '@stdlib/ndarray-to-array' ); -var baseCtor = require( '@stdlib/ndarray-base-ctor' ); -var ctor = require( '@stdlib/ndarray-ctor' ); -var sliceDimensionFrom = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sliceDimensionFrom, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a zero-dimensional array (strict=false)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error' ); - } - t.end(); - - function badValue( x ) { - return function badValue() { - sliceDimensionFrom( x, 0, 0, false, false ); - }; - } -}); - -tape( 'the function throws an error if provided a zero-dimensional array (strict=true)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error' ); - } - t.end(); - - function badValue( x ) { - return function badValue() { - sliceDimensionFrom( x, 0, 0, true, false ); - }; - } -}); - -tape( 'the function throws an error if the dimension index exceeds the number of dimensions (strict=false)', 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 ], 10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - t.throws( badValue( values[ i ], -10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - } - t.end(); - - function badValue( x, dim ) { - return function badValue() { - sliceDimensionFrom( x, dim, 0, false, false ); - }; - } -}); - -tape( 'the function throws an error if the dimension index exceeds the number of dimensions (strict=true)', 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 ], 10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - t.throws( badValue( values[ i ], -10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - } - t.end(); - - function badValue( x, dim ) { - return function badValue() { - sliceDimensionFrom( x, dim, 0, true, false ); - }; - } -}); - -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, - 20, - 20, - 20 - ]; - 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() { - sliceDimensionFrom( x, 0, s, true, false ); - }; - } -}); - -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, - 20, - 20, - 20, - 10 - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceDimensionFrom( values[ i ], 0, start[ i ], false, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), 0, 'returns expected value' ); - t.strictEqual( actual.dtype, values[ i ].dtype, 'returns expected value' ); - } - t.end(); -}); - -tape( 'in non-strict mode, the function returns an empty array when a starting index is the one more than the last index along a dimension', function test( t ) { - var actual; - var values; - var start; - var dim; - 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' } ) - ]; - - dim = [ - 0, - 1, - 0, - 1, - 4 - ]; - - start = [ - 1, - 1, - 1, - 1, - 1 - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceDimensionFrom( values[ i ], dim[ i ], start[ i ], false, false ); // eslint-disable-line max-len - 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 a shifted view of a provided input array (ndims=1)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 2, true, false ); - - 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 = sliceDimensionFrom( x, 0, -4, true, false ); - - 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)', 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 1, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 2, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, -2, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 1, 1, true, false ); - - 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 = sliceDimensionFrom( x, 1, -2, true, false ); - - 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' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=3)', 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 1, true, false ); - - 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 = sliceDimensionFrom( x, 1, 1, true, false ); - - 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 = sliceDimensionFrom( x, 2, 2, true, false ); - - 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 = sliceDimensionFrom( x, 2, -1, true, false ); - - 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' ); - t.end(); -}); - -tape( 'if a provided ndarray has a constructor supporting read-only instances, the function returns a read-only instance', function test( t ) { - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - x = new baseCtor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports returning writable views', function test( t ) { - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - x = new baseCtor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - t.end(); -}); From fa82287c43e5b709dd865786d960c1aa63fce1ae Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 5 Nov 2023 13:44:09 +0000 Subject: [PATCH 09/92] Transform error messages --- lib/main.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index 2b8e198..e51e511 100644 --- a/lib/main.js +++ b/lib/main.js @@ -26,7 +26,7 @@ var ndims = require( '@stdlib/ndarray-base-ndims' ); var slice = require( '@stdlib/ndarray-base-slice' ); var normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' ); var filled = require( '@stdlib/array-base-filled' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // diff --git a/package.json b/package.json index 7afa0cb..ab26260 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/ndarray-base-slice": "^0.1.0", "@stdlib/slice-base-args2multislice": "^0.1.0", "@stdlib/slice-ctor": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.1.0" }, "devDependencies": { From c199917d341de043ad7fa334ab2bf11f95ca9be7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 5 Nov 2023 13:46:39 +0000 Subject: [PATCH 10/92] Remove files --- index.d.ts | 534 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6716 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 1248b30..0000000 --- a/index.d.ts +++ /dev/null @@ -1,534 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceDimensionFrom( x: float64ndarray, dim: number, start: number, strict: boolean, writable: boolean ): float64ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceDimensionFrom( x: float32ndarray, dim: number, start: number, strict: boolean, writable: boolean ): float32ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: int32ndarray, dim: number, start: number, strict: boolean, writable: boolean ): int32ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: int16ndarray, dim: number, start: number, strict: boolean, writable: boolean ): int16ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: int8ndarray, dim: number, start: number, strict: boolean, writable: boolean ): int8ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint32ndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint32ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint16ndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint16ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint8ndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint8ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint8cndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint8cndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceDimensionFrom( x: complex128ndarray, dim: number, start: number, strict: boolean, writable: boolean ): complex128ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceDimensionFrom( x: complex64ndarray, dim: number, start: number, strict: boolean, writable: boolean ): complex64ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: genericndarray, dim: number, start: number, strict: boolean, writable: boolean ): genericndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: typedndarray, dim: number, start: number, strict: boolean, writable: boolean ): typedndarray; - - -// EXPORTS // - -export = sliceDimensionFrom; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index c5d53d1..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-ctor@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndims@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-normalize-index@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-filled@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";function m(m,o,l,a,j){var h,p,v;if(0===(p=r(m)))throw new TypeError(d("invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.",p));if(-1===(v=n(o,p-1)))throw new RangeError(d("invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.",p,o));return(h=t(null,p))[v]=new s(l,null),i(m,e(h),a,j)}export{m as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index f450114..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport Slice from '@stdlib/slice-ctor';\nimport ndims from '@stdlib/ndarray-base-ndims';\nimport slice from '@stdlib/ndarray-base-slice';\nimport normalizeIndex from '@stdlib/ndarray-base-normalize-index';\nimport filled from '@stdlib/array-base-filled';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns a shifted view of an input ndarray along a specified dimension.\n*\n* @param {ndarray} x - input array\n* @param {integer} dim - index of dimension to slice\n* @param {integer} start - starting index (inclusive)\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {TypeError} first argument must be an ndarray having one or more dimensions\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\n*\n* @example\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceDimensionFrom( x, 0, 1, false, false );\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 sliceDimensionFrom( x, dim, start, strict, writable ) {\n\tvar args;\n\tvar N;\n\tvar d;\n\n\t// Retrieve array meta data:\n\tN = ndims( x );\n\n\t// Check whether we were provided a zero-dimensional array...\n\tif ( N === 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.', N ) );\n\t}\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, N-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', N, dim ) );\n\t}\n\t// Define a list of slice arguments:\n\targs = filled( null, N );\n\targs[ d ] = new Slice( start, null );\n\n\t// Return a new array view:\n\treturn slice( x, args2multislice( args ), strict, writable );\n}\n\n\n// EXPORTS //\n\nexport default sliceDimensionFrom;\n"],"names":["sliceDimensionFrom","x","dim","start","strict","writable","args","N","d","ndims","TypeError","format","normalizeIndex","RangeError","filled","Slice","slice","args2multislice"],"mappings":";;ipBAyEA,SAASA,EAAoBC,EAAGC,EAAKC,EAAOC,EAAQC,GACnD,IAAIC,EACAC,EACAC,EAMJ,GAAW,KAHXD,EAAIE,EAAOR,IAIV,MAAM,IAAIS,UAAWC,EAAQ,+GAAgHJ,IAI9I,IAAY,KADZC,EAAII,EAAgBV,EAAKK,EAAE,IAE1B,MAAM,IAAIM,WAAYF,EAAQ,6GAA8GJ,EAAGL,IAOhJ,OAJAI,EAAOQ,EAAQ,KAAMP,IACfC,GAAM,IAAIO,EAAOZ,EAAO,MAGvBa,EAAOf,EAAGgB,EAAiBX,GAAQF,EAAQC,EACnD"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 6eb1e66..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 56064f714db20b77054ff105b05a01cbe6837328 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 5 Nov 2023 13:47:52 +0000 Subject: [PATCH 11/92] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 43 +- benchmark/benchmark.js | 681 --- branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 49 - docs/types/test.ts | 164 - 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 | 102 - package.json | 70 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 616 -- 41 files changed, 6203 insertions(+), 5092 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 05d1840..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-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 ab56cca..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index ced95ae..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-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 c1c45e7..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 2dd36ec..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: '38 14 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -200,7 +193,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]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index b906eff..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,681 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var baseEmpty = require( '@stdlib/ndarray-base-empty' ); -var empty = require( '@stdlib/ndarray-empty' ); -var pkg = require( './../package.json' ).name; -var sliceDimensionFrom = require( './../lib' ); - - -// MAIN // - -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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2 ], { 'dtype': 'float64' } ), - empty( [ 2 ], { 'dtype': 'float32' } ), - empty( [ 2 ], { 'dtype': 'int32' } ), - empty( [ 2 ], { 'dtype': 'complex128' } ), - empty( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== '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 d8a1299..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-from" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-from -[production-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-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 2ab577a..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import sliceDimensionFrom from '../docs/types/index'; -export = sliceDimensionFrom; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 1b0db5f..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var l=function(i,r){return function(){return r||i((r={exports:{}}).exports,r),r.exports}};var o=l(function(p,u){ -var v=require('@stdlib/slice-base-args2multislice/dist'),c=require('@stdlib/slice-ctor/dist'),f=require('@stdlib/ndarray-base-ndims/dist'),q=require('@stdlib/ndarray-base-slice/dist'),g=require('@stdlib/ndarray-base-normalize-index/dist'),w=require('@stdlib/array-base-filled/dist'),s=require('@stdlib/error-tools-fmtprodmsg/dist');function b(i,r,m,t,d){var n,e,a;if(e=f(i),e===0)throw new TypeError(s('nullF7',e));if(a=g(r,e-1),a===-1)throw new RangeError(s('nullF8',e,r));return n=w(null,e),n[a]=new c(m,null),q(i,v(n),t,d)}u.exports=b -});var h=o();module.exports=h; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index a75b3e0..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar args2multislice = require( '@stdlib/slice-base-args2multislice' );\nvar Slice = require( '@stdlib/slice-ctor' );\nvar ndims = require( '@stdlib/ndarray-base-ndims' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' );\nvar filled = require( '@stdlib/array-base-filled' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns a shifted view of an input ndarray along a specified dimension.\n*\n* @param {ndarray} x - input array\n* @param {integer} dim - index of dimension to slice\n* @param {integer} start - starting index (inclusive)\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {TypeError} first argument must be an ndarray having one or more dimensions\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceDimensionFrom( x, 0, 1, false, false );\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 sliceDimensionFrom( x, dim, start, strict, writable ) {\n\tvar args;\n\tvar N;\n\tvar d;\n\n\t// Retrieve array meta data:\n\tN = ndims( x );\n\n\t// Check whether we were provided a zero-dimensional array...\n\tif ( N === 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.', N ) );\n\t}\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, N-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', N, dim ) );\n\t}\n\t// Define a list of slice arguments:\n\targs = filled( null, N );\n\targs[ d ] = new Slice( start, null );\n\n\t// Return a new array view:\n\treturn slice( x, args2multislice( args ), strict, writable );\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceDimensionFrom;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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 shifted view of an input ndarray along a specified dimension.\n*\n* @module @stdlib/ndarray-base-slice-dimension-from\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var sliceDimensionFrom = require( '@stdlib/ndarray-base-slice-dimension-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 = sliceDimensionFrom( x, 0, 1, false, false );\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,EAAkB,QAAS,oCAAqC,EAChEC,EAAQ,QAAS,oBAAqB,EACtCC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAiB,QAAS,sCAAuC,EACjEC,EAAS,QAAS,2BAA4B,EAC9CC,EAAS,QAAS,uBAAwB,EA6C9C,SAASC,EAAoBC,EAAGC,EAAKC,EAAOC,EAAQC,EAAW,CAC9D,IAAIC,EACAC,EACAC,EAMJ,GAHAD,EAAIZ,EAAOM,CAAE,EAGRM,IAAM,EACV,MAAM,IAAI,UAAWR,EAAQ,+GAAgHQ,CAAE,CAAE,EAIlJ,GADAC,EAAIX,EAAgBK,EAAKK,EAAE,CAAE,EACxBC,IAAM,GACV,MAAM,IAAI,WAAYT,EAAQ,6GAA8GQ,EAAGL,CAAI,CAAE,EAGtJ,OAAAI,EAAOR,EAAQ,KAAMS,CAAE,EACvBD,EAAME,CAAE,EAAI,IAAId,EAAOS,EAAO,IAAK,EAG5BP,EAAOK,EAAGR,EAAiBa,CAAK,EAAGF,EAAQC,CAAS,CAC5D,CAKAb,EAAO,QAAUQ,IC7CjB,IAAIS,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "args2multislice", "Slice", "ndims", "slice", "normalizeIndex", "filled", "format", "sliceDimensionFrom", "x", "dim", "start", "strict", "writable", "args", "N", "d", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ffc1f03..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,49 +0,0 @@ - -{{alias}}( x, dim, start, strict, writable ) - Returns a shifted view of an input ndarray along a specified dimension. - - Parameters - ---------- - x: ndarray - Input array. - - dim: integer - Index of dimension to slice. If less than zero, the index is resolved - relative to the last dimension, with the last dimension corresponding to - the value `-1`. - - start: integer - Starting index (inclusive). If less than zero, the corresponding element - along the specified dimension is resolved relative to the last element - along that dimension. For negative integers, the last element - corresponds to the value `-1`. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - writable: boolean - Boolean indicating whether a returned ndarray should be writable. This - parameter only applies to ndarray constructors which support read-only - instances. - - Returns - ------- - out: ndarray - Output array view. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > x.shape - [ 2, 2 ] - > var y = {{alias}}( x, 1, 1, false, false ) - - > 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 9dfeaf3..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,164 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sliceDimensionFrom = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = 0; - - sliceDimensionFrom( empty( 'float64', sh, order ), 1, s, false, false ); // $ExpectType float64ndarray - sliceDimensionFrom( empty( 'float32', sh, order ), 1, s, false, false ); // $ExpectType float32ndarray - sliceDimensionFrom( empty( 'complex128', sh, order ), 1, s, false, false ); // $ExpectType complex128ndarray - sliceDimensionFrom( empty( 'complex64', sh, order ), 1, s, false, false ); // $ExpectType complex64ndarray - sliceDimensionFrom( empty( 'int32', sh, order ), 1, s, false, false ); // $ExpectType int32ndarray - sliceDimensionFrom( empty( 'int16', sh, order ), 1, s, false, false ); // $ExpectType int16ndarray - sliceDimensionFrom( empty( 'int8', sh, order ), 1, s, false, false ); // $ExpectType int8ndarray - sliceDimensionFrom( empty( 'uint32', sh, order ), 1, s, false, false ); // $ExpectType uint32ndarray - sliceDimensionFrom( empty( 'uint16', sh, order ), 1, s, false, false ); // $ExpectType uint16ndarray - sliceDimensionFrom( empty( 'uint8', sh, order ), 1, s, false, false ); // $ExpectType uint8ndarray - sliceDimensionFrom( empty( 'uint8c', sh, order ), 1, s, false, false ); // $ExpectType uint8cndarray - - sliceDimensionFrom( empty( 'float64', sh, order ), 1, s, true, true ); // $ExpectType float64ndarray - sliceDimensionFrom( empty( 'float32', sh, order ), 1, s, true, true ); // $ExpectType float32ndarray - sliceDimensionFrom( empty( 'complex128', sh, order ), 1, s, true, true ); // $ExpectType complex128ndarray - sliceDimensionFrom( empty( 'complex64', sh, order ), 1, s, true, true ); // $ExpectType complex64ndarray - sliceDimensionFrom( empty( 'int32', sh, order ), 1, s, true, true ); // $ExpectType int32ndarray - sliceDimensionFrom( empty( 'int16', sh, order ), 1, s, true, true ); // $ExpectType int16ndarray - sliceDimensionFrom( empty( 'int8', sh, order ), 1, s, true, true ); // $ExpectType int8ndarray - sliceDimensionFrom( empty( 'uint32', sh, order ), 1, s, true, true ); // $ExpectType uint32ndarray - sliceDimensionFrom( empty( 'uint16', sh, order ), 1, s, true, true ); // $ExpectType uint16ndarray - sliceDimensionFrom( empty( 'uint8', sh, order ), 1, s, true, true ); // $ExpectType uint8ndarray - sliceDimensionFrom( empty( 'uint8c', sh, order ), 1, s, true, true ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const s = 0; - - sliceDimensionFrom( '10', 1, s, false, false ); // $ExpectError - sliceDimensionFrom( 10, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( false, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( true, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( null, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( [], 1, s, false, false ); // $ExpectError - sliceDimensionFrom( {}, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( ( x: number ): number => x, 1, s, false, false ); // $ExpectError - - sliceDimensionFrom( '10', 1, s, true, true ); // $ExpectError - sliceDimensionFrom( 10, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( false, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( true, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( null, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( [], 1, s, true, true ); // $ExpectError - sliceDimensionFrom( {}, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( ( x: number ): number => x, 1, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a number... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 1; - - sliceDimensionFrom( x, '5', s, false, false ); // $ExpectError - sliceDimensionFrom( x, false, s, false, false ); // $ExpectError - sliceDimensionFrom( x, true, s, false, false ); // $ExpectError - sliceDimensionFrom( x, null, s, false, false ); // $ExpectError - sliceDimensionFrom( x, undefined, s, false, false ); // $ExpectError - sliceDimensionFrom( x, [ '5' ], s, false, false ); // $ExpectError - sliceDimensionFrom( x, {}, s, false, false ); // $ExpectError - sliceDimensionFrom( x, ( x: number ): number => x, s, false, false ); // $ExpectError - - sliceDimensionFrom( x, '5', s, true, true ); // $ExpectError - sliceDimensionFrom( x, false, s, true, true ); // $ExpectError - sliceDimensionFrom( x, true, s, true, true ); // $ExpectError - sliceDimensionFrom( x, null, s, true, true ); // $ExpectError - sliceDimensionFrom( x, undefined, s, true, true ); // $ExpectError - sliceDimensionFrom( x, [ '5' ], s, true, true ); // $ExpectError - sliceDimensionFrom( x, {}, s, true, true ); // $ExpectError - sliceDimensionFrom( x, ( x: number ): number => x, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceDimensionFrom( x, 1, '5', false, false ); // $ExpectError - sliceDimensionFrom( x, 1, false, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, true, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, null, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, undefined, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, [ '5' ], false, false ); // $ExpectError - sliceDimensionFrom( x, 1, {}, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, ( x: number ): number => x, 1, false, false ); // $ExpectError - - sliceDimensionFrom( x, 1, '5', true, true ); // $ExpectError - sliceDimensionFrom( x, 1, false, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, true, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, null, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, undefined, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, [ '5' ], true, true ); // $ExpectError - sliceDimensionFrom( x, 1, {}, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, ( x: number ): number => x, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x, 1, s, '5', false ); // $ExpectError - sliceDimensionFrom( x, 1, s, 5, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, null, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, undefined, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, [ '5' ], false ); // $ExpectError - sliceDimensionFrom( x, 1, s, {}, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x, 1, s, false, '5' ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, 5 ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, null ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, undefined ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, [ '5' ] ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, {} ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x ); // $ExpectError - sliceDimensionFrom( x, 1 ); // $ExpectError - sliceDimensionFrom( x, 1, s ); // $ExpectError - sliceDimensionFrom( x, 1, s, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index b17162a..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 sliceDimensionFrom = 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 = sliceDimensionFrom( x, 1, 1, false, false ); -// 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 columns of each matrix: -var y2 = sliceDimensionFrom( x, 2, 1, false, false ); -// returns - -var a2 = ndarray2array( y2 ); -console.log( a2 ); -// => [ [ [ 1, 2 ], [ 4, 5 ], [ 7, 8 ] ], [ [ 10, 11 ], [ 13, 14 ], [ 16, 17 ] ], [ [ 19, 20 ], [ 22, 23 ], [ 25, 26 ] ] ] - -// Get the last two matrices: -var y3 = sliceDimensionFrom( x, 0, 1, false, false ); -// returns - -var a3 = ndarray2array( y3 ); -console.log( a3 ); -// => [ [ [ 9, 10, 11 ], [ 12, 13, 14 ], [ 15, 16, 17 ] ], [ [ 18, 19, 20 ], [ 21, 22, 23 ], [ 24, 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 2d4595f..1248b30 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..c5d53d1 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-ctor@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndims@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-normalize-index@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-filled@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";function m(m,o,l,a,j){var h,p,v;if(0===(p=r(m)))throw new TypeError(d("invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.",p));if(-1===(v=n(o,p-1)))throw new RangeError(d("invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.",p,o));return(h=t(null,p))[v]=new s(l,null),i(m,e(h),a,j)}export{m as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..f450114 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport Slice from '@stdlib/slice-ctor';\nimport ndims from '@stdlib/ndarray-base-ndims';\nimport slice from '@stdlib/ndarray-base-slice';\nimport normalizeIndex from '@stdlib/ndarray-base-normalize-index';\nimport filled from '@stdlib/array-base-filled';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns a shifted view of an input ndarray along a specified dimension.\n*\n* @param {ndarray} x - input array\n* @param {integer} dim - index of dimension to slice\n* @param {integer} start - starting index (inclusive)\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {TypeError} first argument must be an ndarray having one or more dimensions\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\n*\n* @example\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceDimensionFrom( x, 0, 1, false, false );\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 sliceDimensionFrom( x, dim, start, strict, writable ) {\n\tvar args;\n\tvar N;\n\tvar d;\n\n\t// Retrieve array meta data:\n\tN = ndims( x );\n\n\t// Check whether we were provided a zero-dimensional array...\n\tif ( N === 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.', N ) );\n\t}\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, N-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', N, dim ) );\n\t}\n\t// Define a list of slice arguments:\n\targs = filled( null, N );\n\targs[ d ] = new Slice( start, null );\n\n\t// Return a new array view:\n\treturn slice( x, args2multislice( args ), strict, writable );\n}\n\n\n// EXPORTS //\n\nexport default sliceDimensionFrom;\n"],"names":["sliceDimensionFrom","x","dim","start","strict","writable","args","N","d","ndims","TypeError","format","normalizeIndex","RangeError","filled","Slice","slice","args2multislice"],"mappings":";;ipBAyEA,SAASA,EAAoBC,EAAGC,EAAKC,EAAOC,EAAQC,GACnD,IAAIC,EACAC,EACAC,EAMJ,GAAW,KAHXD,EAAIE,EAAOR,IAIV,MAAM,IAAIS,UAAWC,EAAQ,+GAAgHJ,IAI9I,IAAY,KADZC,EAAII,EAAgBV,EAAKK,EAAE,IAE1B,MAAM,IAAIM,WAAYF,EAAQ,6GAA8GJ,EAAGL,IAOhJ,OAJAI,EAAOQ,EAAQ,KAAMP,IACfC,GAAM,IAAIO,EAAOZ,EAAO,MAGvBa,EAAOf,EAAGgB,EAAiBX,GAAQF,EAAQC,EACnD"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index b3f97b2..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 shifted view of an input ndarray along a specified dimension. -* -* @module @stdlib/ndarray-base-slice-dimension-from -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var sliceDimensionFrom = require( '@stdlib/ndarray-base-slice-dimension-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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // 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 e51e511..0000000 --- a/lib/main.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var Slice = require( '@stdlib/slice-ctor' ); -var ndims = require( '@stdlib/ndarray-base-ndims' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' ); -var filled = require( '@stdlib/array-base-filled' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param {ndarray} x - input array -* @param {integer} dim - index of dimension to slice -* @param {integer} start - starting index (inclusive) -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @param {boolean} writable - boolean indicating whether a returned array should be writable -* @throws {TypeError} first argument must be an ndarray having one or more dimensions -* @throws {RangeError} dimension index exceeds the number of dimensions -* @throws {RangeError} slice 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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -function sliceDimensionFrom( x, dim, start, strict, writable ) { - var args; - var N; - var d; - - // Retrieve array meta data: - N = ndims( x ); - - // Check whether we were provided a zero-dimensional array... - if ( N === 0 ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.', N ) ); - } - // Normalize the dimension index: - d = normalizeIndex( dim, N-1 ); - if ( d === -1 ) { - throw new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', N, dim ) ); - } - // Define a list of slice arguments: - args = filled( null, N ); - args[ d ] = new Slice( start, null ); - - // Return a new array view: - return slice( x, args2multislice( args ), strict, writable ); -} - - -// EXPORTS // - -module.exports = sliceDimensionFrom; diff --git a/package.json b/package.json index ab26260..c42fa88 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Return a shifted view of an input ndarray along a specific dimension.", "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,49 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-filled": "^0.1.0", - "@stdlib/ndarray-base-ndims": "^0.1.0", - "@stdlib/ndarray-base-normalize-index": "^0.1.0", - "@stdlib/ndarray-base-slice": "^0.1.0", - "@stdlib/slice-base-args2multislice": "^0.1.0", - "@stdlib/slice-ctor": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.1.0" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/array-typed": "^0.1.0", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/bench": "^0.1.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-base-assert-is-read-only": "^0.1.1", - "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/ndarray-base-empty": "^0.1.0", - "@stdlib/ndarray-base-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" - }, - "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..01584b3 --- /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 28703b5..0000000 --- a/test/test.js +++ /dev/null @@ -1,616 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 ndarray2array = require( '@stdlib/ndarray-to-array' ); -var baseCtor = require( '@stdlib/ndarray-base-ctor' ); -var ctor = require( '@stdlib/ndarray-ctor' ); -var sliceDimensionFrom = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sliceDimensionFrom, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a zero-dimensional array (strict=false)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error' ); - } - t.end(); - - function badValue( x ) { - return function badValue() { - sliceDimensionFrom( x, 0, 0, false, false ); - }; - } -}); - -tape( 'the function throws an error if provided a zero-dimensional array (strict=true)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error' ); - } - t.end(); - - function badValue( x ) { - return function badValue() { - sliceDimensionFrom( x, 0, 0, true, false ); - }; - } -}); - -tape( 'the function throws an error if the dimension index exceeds the number of dimensions (strict=false)', 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 ], 10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - t.throws( badValue( values[ i ], -10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - } - t.end(); - - function badValue( x, dim ) { - return function badValue() { - sliceDimensionFrom( x, dim, 0, false, false ); - }; - } -}); - -tape( 'the function throws an error if the dimension index exceeds the number of dimensions (strict=true)', 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 ], 10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - t.throws( badValue( values[ i ], -10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - } - t.end(); - - function badValue( x, dim ) { - return function badValue() { - sliceDimensionFrom( x, dim, 0, true, false ); - }; - } -}); - -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, - 20, - 20, - 20 - ]; - 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() { - sliceDimensionFrom( x, 0, s, true, false ); - }; - } -}); - -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, - 20, - 20, - 20, - 10 - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceDimensionFrom( values[ i ], 0, start[ i ], false, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), 0, 'returns expected value' ); - t.strictEqual( actual.dtype, values[ i ].dtype, 'returns expected value' ); - } - t.end(); -}); - -tape( 'in non-strict mode, the function returns an empty array when a starting index is the one more than the last index along a dimension', function test( t ) { - var actual; - var values; - var start; - var dim; - 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' } ) - ]; - - dim = [ - 0, - 1, - 0, - 1, - 4 - ]; - - start = [ - 1, - 1, - 1, - 1, - 1 - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceDimensionFrom( values[ i ], dim[ i ], start[ i ], false, false ); // eslint-disable-line max-len - 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 a shifted view of a provided input array (ndims=1)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 2, true, false ); - - 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 = sliceDimensionFrom( x, 0, -4, true, false ); - - 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)', 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 1, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 2, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, -2, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 1, 1, true, false ); - - 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 = sliceDimensionFrom( x, 1, -2, true, false ); - - 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' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=3)', 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 1, true, false ); - - 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 = sliceDimensionFrom( x, 1, 1, true, false ); - - 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 = sliceDimensionFrom( x, 2, 2, true, false ); - - 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 = sliceDimensionFrom( x, 2, -1, true, false ); - - 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' ); - t.end(); -}); - -tape( 'if a provided ndarray has a constructor supporting read-only instances, the function returns a read-only instance', function test( t ) { - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - x = new baseCtor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports returning writable views', function test( t ) { - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - x = new baseCtor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - t.end(); -}); From bd595a7ce81a641b21d9146ca704a1b1d5453a7f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 5 Nov 2023 13:54:53 +0000 Subject: [PATCH 12/92] 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 fcee881..dce8dcd 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import sliceDimensionFrom from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-dimension-from@esm/index.mjs'; +import sliceDimensionFrom from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-dimension-from@v0.1.0-esm/index.mjs'; ``` #### sliceDimensionFrom( x, dim, start, strict, writable ) @@ -128,7 +128,7 @@ The function accepts the following arguments: 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 sliceDimensionFrom from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-dimension-from@esm/index.mjs'; +import sliceDimensionFrom from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-dimension-from@v0.1.0-esm/index.mjs'; // Create a linear ndarray buffer: var buf = zeroTo( 27 ); From 84514a022adff667a0ff9fa9be0b8976a947ca34 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 5 Nov 2023 13:54:54 +0000 Subject: [PATCH 13/92] Auto-generated commit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index dce8dcd..9802a7b 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,11 @@ limitations under the License. ## Usage +```javascript +import sliceDimensionFrom from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-dimension-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-base-slice-dimension-from/tags). For example, + ```javascript import sliceDimensionFrom from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-dimension-from@v0.1.0-esm/index.mjs'; ``` @@ -128,7 +133,7 @@ The function accepts the following arguments: 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 sliceDimensionFrom from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-dimension-from@v0.1.0-esm/index.mjs'; +import sliceDimensionFrom from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-dimension-from@esm/index.mjs'; // Create a linear ndarray buffer: var buf = zeroTo( 27 ); From 956cf1ee48707ae9a41df78507b402eb2d86d52f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Dec 2023 13:29:13 +0000 Subject: [PATCH 14/92] Transform error messages --- lib/main.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index 2b8e198..e51e511 100644 --- a/lib/main.js +++ b/lib/main.js @@ -26,7 +26,7 @@ var ndims = require( '@stdlib/ndarray-base-ndims' ); var slice = require( '@stdlib/ndarray-base-slice' ); var normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' ); var filled = require( '@stdlib/array-base-filled' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // diff --git a/package.json b/package.json index 25f0208..7794710 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/ndarray-base-slice": "^0.1.0", "@stdlib/slice-base-args2multislice": "^0.1.0", "@stdlib/slice-ctor": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.2.0" }, "devDependencies": { From a483030cf29ec1ab5f23bcadfecc8065f4998717 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 2 Dec 2023 11:39:19 +0000 Subject: [PATCH 15/92] Remove files --- index.d.ts | 534 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6716 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 1248b30..0000000 --- a/index.d.ts +++ /dev/null @@ -1,534 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceDimensionFrom( x: float64ndarray, dim: number, start: number, strict: boolean, writable: boolean ): float64ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceDimensionFrom( x: float32ndarray, dim: number, start: number, strict: boolean, writable: boolean ): float32ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: int32ndarray, dim: number, start: number, strict: boolean, writable: boolean ): int32ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: int16ndarray, dim: number, start: number, strict: boolean, writable: boolean ): int16ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: int8ndarray, dim: number, start: number, strict: boolean, writable: boolean ): int8ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint32ndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint32ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint16ndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint16ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint8ndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint8ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint8cndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint8cndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceDimensionFrom( x: complex128ndarray, dim: number, start: number, strict: boolean, writable: boolean ): complex128ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceDimensionFrom( x: complex64ndarray, dim: number, start: number, strict: boolean, writable: boolean ): complex64ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: genericndarray, dim: number, start: number, strict: boolean, writable: boolean ): genericndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: typedndarray, dim: number, start: number, strict: boolean, writable: boolean ): typedndarray; - - -// EXPORTS // - -export = sliceDimensionFrom; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index c5d53d1..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-ctor@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndims@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-normalize-index@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-filled@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";function m(m,o,l,a,j){var h,p,v;if(0===(p=r(m)))throw new TypeError(d("invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.",p));if(-1===(v=n(o,p-1)))throw new RangeError(d("invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.",p,o));return(h=t(null,p))[v]=new s(l,null),i(m,e(h),a,j)}export{m as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index f450114..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport Slice from '@stdlib/slice-ctor';\nimport ndims from '@stdlib/ndarray-base-ndims';\nimport slice from '@stdlib/ndarray-base-slice';\nimport normalizeIndex from '@stdlib/ndarray-base-normalize-index';\nimport filled from '@stdlib/array-base-filled';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns a shifted view of an input ndarray along a specified dimension.\n*\n* @param {ndarray} x - input array\n* @param {integer} dim - index of dimension to slice\n* @param {integer} start - starting index (inclusive)\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {TypeError} first argument must be an ndarray having one or more dimensions\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\n*\n* @example\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceDimensionFrom( x, 0, 1, false, false );\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 sliceDimensionFrom( x, dim, start, strict, writable ) {\n\tvar args;\n\tvar N;\n\tvar d;\n\n\t// Retrieve array meta data:\n\tN = ndims( x );\n\n\t// Check whether we were provided a zero-dimensional array...\n\tif ( N === 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.', N ) );\n\t}\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, N-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', N, dim ) );\n\t}\n\t// Define a list of slice arguments:\n\targs = filled( null, N );\n\targs[ d ] = new Slice( start, null );\n\n\t// Return a new array view:\n\treturn slice( x, args2multislice( args ), strict, writable );\n}\n\n\n// EXPORTS //\n\nexport default sliceDimensionFrom;\n"],"names":["sliceDimensionFrom","x","dim","start","strict","writable","args","N","d","ndims","TypeError","format","normalizeIndex","RangeError","filled","Slice","slice","args2multislice"],"mappings":";;ipBAyEA,SAASA,EAAoBC,EAAGC,EAAKC,EAAOC,EAAQC,GACnD,IAAIC,EACAC,EACAC,EAMJ,GAAW,KAHXD,EAAIE,EAAOR,IAIV,MAAM,IAAIS,UAAWC,EAAQ,+GAAgHJ,IAI9I,IAAY,KADZC,EAAII,EAAgBV,EAAKK,EAAE,IAE1B,MAAM,IAAIM,WAAYF,EAAQ,6GAA8GJ,EAAGL,IAOhJ,OAJAI,EAAOQ,EAAQ,KAAMP,IACfC,GAAM,IAAIO,EAAOZ,EAAO,MAGvBa,EAAOf,EAAGgB,EAAiBX,GAAQF,EAAQC,EACnD"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 01584b3..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From ce9350d9c2bb59426edc2ee4bdaa1dbd7bab5bb9 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 2 Dec 2023 11:40:33 +0000 Subject: [PATCH 16/92] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 43 +- benchmark/benchmark.js | 681 --- branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 49 - docs/types/test.ts | 164 - 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 | 102 - package.json | 70 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 616 -- 42 files changed, 6203 insertions(+), 5088 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index bed4f32..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-12-01T05:41:04.683Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 05d1840..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-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 ab56cca..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index ced95ae..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-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 c1c45e7..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 2dd36ec..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: '38 14 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -200,7 +193,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]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index b906eff..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,681 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var baseEmpty = require( '@stdlib/ndarray-base-empty' ); -var empty = require( '@stdlib/ndarray-empty' ); -var pkg = require( './../package.json' ).name; -var sliceDimensionFrom = require( './../lib' ); - - -// MAIN // - -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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2 ], { 'dtype': 'float64' } ), - empty( [ 2 ], { 'dtype': 'float32' } ), - empty( [ 2 ], { 'dtype': 'int32' } ), - empty( [ 2 ], { 'dtype': 'complex128' } ), - empty( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== '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 d8a1299..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-from" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-from -[production-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-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 2ab577a..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import sliceDimensionFrom from '../docs/types/index'; -export = sliceDimensionFrom; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 0f7ac9a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var l=function(i,r){return function(){return r||i((r={exports:{}}).exports,r),r.exports}};var o=l(function(p,u){ -var v=require('@stdlib/slice-base-args2multislice/dist'),c=require('@stdlib/slice-ctor/dist'),f=require('@stdlib/ndarray-base-ndims/dist'),q=require('@stdlib/ndarray-base-slice/dist'),g=require('@stdlib/ndarray-base-normalize-index/dist'),w=require('@stdlib/array-base-filled/dist'),s=require('@stdlib/error-tools-fmtprodmsg/dist');function b(i,r,m,t,d){var n,e,a;if(e=f(i),e===0)throw new TypeError(s('1lDF7',e));if(a=g(r,e-1),a===-1)throw new RangeError(s('1lDF8',e,r));return n=w(null,e),n[a]=new c(m,null),q(i,v(n),t,d)}u.exports=b -});var h=o();module.exports=h; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index a75b3e0..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar args2multislice = require( '@stdlib/slice-base-args2multislice' );\nvar Slice = require( '@stdlib/slice-ctor' );\nvar ndims = require( '@stdlib/ndarray-base-ndims' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' );\nvar filled = require( '@stdlib/array-base-filled' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns a shifted view of an input ndarray along a specified dimension.\n*\n* @param {ndarray} x - input array\n* @param {integer} dim - index of dimension to slice\n* @param {integer} start - starting index (inclusive)\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {TypeError} first argument must be an ndarray having one or more dimensions\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceDimensionFrom( x, 0, 1, false, false );\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 sliceDimensionFrom( x, dim, start, strict, writable ) {\n\tvar args;\n\tvar N;\n\tvar d;\n\n\t// Retrieve array meta data:\n\tN = ndims( x );\n\n\t// Check whether we were provided a zero-dimensional array...\n\tif ( N === 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.', N ) );\n\t}\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, N-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', N, dim ) );\n\t}\n\t// Define a list of slice arguments:\n\targs = filled( null, N );\n\targs[ d ] = new Slice( start, null );\n\n\t// Return a new array view:\n\treturn slice( x, args2multislice( args ), strict, writable );\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceDimensionFrom;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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 shifted view of an input ndarray along a specified dimension.\n*\n* @module @stdlib/ndarray-base-slice-dimension-from\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var sliceDimensionFrom = require( '@stdlib/ndarray-base-slice-dimension-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 = sliceDimensionFrom( x, 0, 1, false, false );\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,EAAkB,QAAS,oCAAqC,EAChEC,EAAQ,QAAS,oBAAqB,EACtCC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAiB,QAAS,sCAAuC,EACjEC,EAAS,QAAS,2BAA4B,EAC9CC,EAAS,QAAS,uBAAwB,EA6C9C,SAASC,EAAoBC,EAAGC,EAAKC,EAAOC,EAAQC,EAAW,CAC9D,IAAIC,EACAC,EACAC,EAMJ,GAHAD,EAAIZ,EAAOM,CAAE,EAGRM,IAAM,EACV,MAAM,IAAI,UAAWR,EAAQ,+GAAgHQ,CAAE,CAAE,EAIlJ,GADAC,EAAIX,EAAgBK,EAAKK,EAAE,CAAE,EACxBC,IAAM,GACV,MAAM,IAAI,WAAYT,EAAQ,6GAA8GQ,EAAGL,CAAI,CAAE,EAGtJ,OAAAI,EAAOR,EAAQ,KAAMS,CAAE,EACvBD,EAAME,CAAE,EAAI,IAAId,EAAOS,EAAO,IAAK,EAG5BP,EAAOK,EAAGR,EAAiBa,CAAK,EAAGF,EAAQC,CAAS,CAC5D,CAKAb,EAAO,QAAUQ,IC7CjB,IAAIS,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "args2multislice", "Slice", "ndims", "slice", "normalizeIndex", "filled", "format", "sliceDimensionFrom", "x", "dim", "start", "strict", "writable", "args", "N", "d", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ffc1f03..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,49 +0,0 @@ - -{{alias}}( x, dim, start, strict, writable ) - Returns a shifted view of an input ndarray along a specified dimension. - - Parameters - ---------- - x: ndarray - Input array. - - dim: integer - Index of dimension to slice. If less than zero, the index is resolved - relative to the last dimension, with the last dimension corresponding to - the value `-1`. - - start: integer - Starting index (inclusive). If less than zero, the corresponding element - along the specified dimension is resolved relative to the last element - along that dimension. For negative integers, the last element - corresponds to the value `-1`. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - writable: boolean - Boolean indicating whether a returned ndarray should be writable. This - parameter only applies to ndarray constructors which support read-only - instances. - - Returns - ------- - out: ndarray - Output array view. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > x.shape - [ 2, 2 ] - > var y = {{alias}}( x, 1, 1, false, false ) - - > 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 9dfeaf3..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,164 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sliceDimensionFrom = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = 0; - - sliceDimensionFrom( empty( 'float64', sh, order ), 1, s, false, false ); // $ExpectType float64ndarray - sliceDimensionFrom( empty( 'float32', sh, order ), 1, s, false, false ); // $ExpectType float32ndarray - sliceDimensionFrom( empty( 'complex128', sh, order ), 1, s, false, false ); // $ExpectType complex128ndarray - sliceDimensionFrom( empty( 'complex64', sh, order ), 1, s, false, false ); // $ExpectType complex64ndarray - sliceDimensionFrom( empty( 'int32', sh, order ), 1, s, false, false ); // $ExpectType int32ndarray - sliceDimensionFrom( empty( 'int16', sh, order ), 1, s, false, false ); // $ExpectType int16ndarray - sliceDimensionFrom( empty( 'int8', sh, order ), 1, s, false, false ); // $ExpectType int8ndarray - sliceDimensionFrom( empty( 'uint32', sh, order ), 1, s, false, false ); // $ExpectType uint32ndarray - sliceDimensionFrom( empty( 'uint16', sh, order ), 1, s, false, false ); // $ExpectType uint16ndarray - sliceDimensionFrom( empty( 'uint8', sh, order ), 1, s, false, false ); // $ExpectType uint8ndarray - sliceDimensionFrom( empty( 'uint8c', sh, order ), 1, s, false, false ); // $ExpectType uint8cndarray - - sliceDimensionFrom( empty( 'float64', sh, order ), 1, s, true, true ); // $ExpectType float64ndarray - sliceDimensionFrom( empty( 'float32', sh, order ), 1, s, true, true ); // $ExpectType float32ndarray - sliceDimensionFrom( empty( 'complex128', sh, order ), 1, s, true, true ); // $ExpectType complex128ndarray - sliceDimensionFrom( empty( 'complex64', sh, order ), 1, s, true, true ); // $ExpectType complex64ndarray - sliceDimensionFrom( empty( 'int32', sh, order ), 1, s, true, true ); // $ExpectType int32ndarray - sliceDimensionFrom( empty( 'int16', sh, order ), 1, s, true, true ); // $ExpectType int16ndarray - sliceDimensionFrom( empty( 'int8', sh, order ), 1, s, true, true ); // $ExpectType int8ndarray - sliceDimensionFrom( empty( 'uint32', sh, order ), 1, s, true, true ); // $ExpectType uint32ndarray - sliceDimensionFrom( empty( 'uint16', sh, order ), 1, s, true, true ); // $ExpectType uint16ndarray - sliceDimensionFrom( empty( 'uint8', sh, order ), 1, s, true, true ); // $ExpectType uint8ndarray - sliceDimensionFrom( empty( 'uint8c', sh, order ), 1, s, true, true ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const s = 0; - - sliceDimensionFrom( '10', 1, s, false, false ); // $ExpectError - sliceDimensionFrom( 10, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( false, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( true, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( null, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( [], 1, s, false, false ); // $ExpectError - sliceDimensionFrom( {}, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( ( x: number ): number => x, 1, s, false, false ); // $ExpectError - - sliceDimensionFrom( '10', 1, s, true, true ); // $ExpectError - sliceDimensionFrom( 10, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( false, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( true, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( null, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( [], 1, s, true, true ); // $ExpectError - sliceDimensionFrom( {}, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( ( x: number ): number => x, 1, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a number... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 1; - - sliceDimensionFrom( x, '5', s, false, false ); // $ExpectError - sliceDimensionFrom( x, false, s, false, false ); // $ExpectError - sliceDimensionFrom( x, true, s, false, false ); // $ExpectError - sliceDimensionFrom( x, null, s, false, false ); // $ExpectError - sliceDimensionFrom( x, undefined, s, false, false ); // $ExpectError - sliceDimensionFrom( x, [ '5' ], s, false, false ); // $ExpectError - sliceDimensionFrom( x, {}, s, false, false ); // $ExpectError - sliceDimensionFrom( x, ( x: number ): number => x, s, false, false ); // $ExpectError - - sliceDimensionFrom( x, '5', s, true, true ); // $ExpectError - sliceDimensionFrom( x, false, s, true, true ); // $ExpectError - sliceDimensionFrom( x, true, s, true, true ); // $ExpectError - sliceDimensionFrom( x, null, s, true, true ); // $ExpectError - sliceDimensionFrom( x, undefined, s, true, true ); // $ExpectError - sliceDimensionFrom( x, [ '5' ], s, true, true ); // $ExpectError - sliceDimensionFrom( x, {}, s, true, true ); // $ExpectError - sliceDimensionFrom( x, ( x: number ): number => x, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceDimensionFrom( x, 1, '5', false, false ); // $ExpectError - sliceDimensionFrom( x, 1, false, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, true, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, null, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, undefined, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, [ '5' ], false, false ); // $ExpectError - sliceDimensionFrom( x, 1, {}, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, ( x: number ): number => x, 1, false, false ); // $ExpectError - - sliceDimensionFrom( x, 1, '5', true, true ); // $ExpectError - sliceDimensionFrom( x, 1, false, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, true, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, null, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, undefined, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, [ '5' ], true, true ); // $ExpectError - sliceDimensionFrom( x, 1, {}, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, ( x: number ): number => x, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x, 1, s, '5', false ); // $ExpectError - sliceDimensionFrom( x, 1, s, 5, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, null, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, undefined, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, [ '5' ], false ); // $ExpectError - sliceDimensionFrom( x, 1, s, {}, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x, 1, s, false, '5' ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, 5 ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, null ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, undefined ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, [ '5' ] ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, {} ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x ); // $ExpectError - sliceDimensionFrom( x, 1 ); // $ExpectError - sliceDimensionFrom( x, 1, s ); // $ExpectError - sliceDimensionFrom( x, 1, s, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index b17162a..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 sliceDimensionFrom = 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 = sliceDimensionFrom( x, 1, 1, false, false ); -// 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 columns of each matrix: -var y2 = sliceDimensionFrom( x, 2, 1, false, false ); -// returns - -var a2 = ndarray2array( y2 ); -console.log( a2 ); -// => [ [ [ 1, 2 ], [ 4, 5 ], [ 7, 8 ] ], [ [ 10, 11 ], [ 13, 14 ], [ 16, 17 ] ], [ [ 19, 20 ], [ 22, 23 ], [ 25, 26 ] ] ] - -// Get the last two matrices: -var y3 = sliceDimensionFrom( x, 0, 1, false, false ); -// returns - -var a3 = ndarray2array( y3 ); -console.log( a3 ); -// => [ [ [ 9, 10, 11 ], [ 12, 13, 14 ], [ 15, 16, 17 ] ], [ [ 18, 19, 20 ], [ 21, 22, 23 ], [ 24, 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 2d4595f..1248b30 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..085cfde --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-ctor@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndims@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-normalize-index@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-filled@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";function m(m,o,l,a,j){var h,v,p;if(0===(v=r(m)))throw new TypeError(d("invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.",v));if(-1===(p=n(o,v-1)))throw new RangeError(d("invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.",v,o));return(h=t(null,v))[p]=new s(l,null),i(m,e(h),a,j)}export{m as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..f5d4091 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport Slice from '@stdlib/slice-ctor';\nimport ndims from '@stdlib/ndarray-base-ndims';\nimport slice from '@stdlib/ndarray-base-slice';\nimport normalizeIndex from '@stdlib/ndarray-base-normalize-index';\nimport filled from '@stdlib/array-base-filled';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns a shifted view of an input ndarray along a specified dimension.\n*\n* @param {ndarray} x - input array\n* @param {integer} dim - index of dimension to slice\n* @param {integer} start - starting index (inclusive)\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {TypeError} first argument must be an ndarray having one or more dimensions\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\n*\n* @example\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceDimensionFrom( x, 0, 1, false, false );\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 sliceDimensionFrom( x, dim, start, strict, writable ) {\n\tvar args;\n\tvar N;\n\tvar d;\n\n\t// Retrieve array meta data:\n\tN = ndims( x );\n\n\t// Check whether we were provided a zero-dimensional array...\n\tif ( N === 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.', N ) );\n\t}\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, N-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', N, dim ) );\n\t}\n\t// Define a list of slice arguments:\n\targs = filled( null, N );\n\targs[ d ] = new Slice( start, null );\n\n\t// Return a new array view:\n\treturn slice( x, args2multislice( args ), strict, writable );\n}\n\n\n// EXPORTS //\n\nexport default sliceDimensionFrom;\n"],"names":["sliceDimensionFrom","x","dim","start","strict","writable","args","N","d","ndims","TypeError","format","normalizeIndex","RangeError","filled","Slice","slice","args2multislice"],"mappings":";;wpBAyEA,SAASA,EAAoBC,EAAGC,EAAKC,EAAOC,EAAQC,GACnD,IAAIC,EACAC,EACAC,EAMJ,GAAW,KAHXD,EAAIE,EAAOR,IAIV,MAAM,IAAIS,UAAWC,EAAQ,+GAAgHJ,IAI9I,IAAY,KADZC,EAAII,EAAgBV,EAAKK,EAAE,IAE1B,MAAM,IAAIM,WAAYF,EAAQ,6GAA8GJ,EAAGL,IAOhJ,OAJAI,EAAOQ,EAAQ,KAAMP,IACfC,GAAM,IAAIO,EAAOZ,EAAO,MAGvBa,EAAOf,EAAGgB,EAAiBX,GAAQF,EAAQC,EACnD"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index b3f97b2..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 shifted view of an input ndarray along a specified dimension. -* -* @module @stdlib/ndarray-base-slice-dimension-from -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var sliceDimensionFrom = require( '@stdlib/ndarray-base-slice-dimension-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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // 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 e51e511..0000000 --- a/lib/main.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var Slice = require( '@stdlib/slice-ctor' ); -var ndims = require( '@stdlib/ndarray-base-ndims' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' ); -var filled = require( '@stdlib/array-base-filled' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param {ndarray} x - input array -* @param {integer} dim - index of dimension to slice -* @param {integer} start - starting index (inclusive) -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @param {boolean} writable - boolean indicating whether a returned array should be writable -* @throws {TypeError} first argument must be an ndarray having one or more dimensions -* @throws {RangeError} dimension index exceeds the number of dimensions -* @throws {RangeError} slice 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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -function sliceDimensionFrom( x, dim, start, strict, writable ) { - var args; - var N; - var d; - - // Retrieve array meta data: - N = ndims( x ); - - // Check whether we were provided a zero-dimensional array... - if ( N === 0 ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.', N ) ); - } - // Normalize the dimension index: - d = normalizeIndex( dim, N-1 ); - if ( d === -1 ) { - throw new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', N, dim ) ); - } - // Define a list of slice arguments: - args = filled( null, N ); - args[ d ] = new Slice( start, null ); - - // Return a new array view: - return slice( x, args2multislice( args ), strict, writable ); -} - - -// EXPORTS // - -module.exports = sliceDimensionFrom; diff --git a/package.json b/package.json index 7794710..c42fa88 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Return a shifted view of an input ndarray along a specific dimension.", "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,49 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-filled": "^0.1.0", - "@stdlib/ndarray-base-ndims": "^0.1.0", - "@stdlib/ndarray-base-normalize-index": "^0.1.0", - "@stdlib/ndarray-base-slice": "^0.1.0", - "@stdlib/slice-base-args2multislice": "^0.1.0", - "@stdlib/slice-ctor": "^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/assert-is-ndarray-like": "^0.1.0", - "@stdlib/bench": "^0.2.1", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-base-assert-is-read-only": "^0.1.1", - "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/ndarray-base-empty": "^0.1.1", - "@stdlib/ndarray-base-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" - }, - "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..8de8235 --- /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 28703b5..0000000 --- a/test/test.js +++ /dev/null @@ -1,616 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 ndarray2array = require( '@stdlib/ndarray-to-array' ); -var baseCtor = require( '@stdlib/ndarray-base-ctor' ); -var ctor = require( '@stdlib/ndarray-ctor' ); -var sliceDimensionFrom = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sliceDimensionFrom, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a zero-dimensional array (strict=false)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error' ); - } - t.end(); - - function badValue( x ) { - return function badValue() { - sliceDimensionFrom( x, 0, 0, false, false ); - }; - } -}); - -tape( 'the function throws an error if provided a zero-dimensional array (strict=true)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error' ); - } - t.end(); - - function badValue( x ) { - return function badValue() { - sliceDimensionFrom( x, 0, 0, true, false ); - }; - } -}); - -tape( 'the function throws an error if the dimension index exceeds the number of dimensions (strict=false)', 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 ], 10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - t.throws( badValue( values[ i ], -10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - } - t.end(); - - function badValue( x, dim ) { - return function badValue() { - sliceDimensionFrom( x, dim, 0, false, false ); - }; - } -}); - -tape( 'the function throws an error if the dimension index exceeds the number of dimensions (strict=true)', 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 ], 10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - t.throws( badValue( values[ i ], -10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - } - t.end(); - - function badValue( x, dim ) { - return function badValue() { - sliceDimensionFrom( x, dim, 0, true, false ); - }; - } -}); - -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, - 20, - 20, - 20 - ]; - 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() { - sliceDimensionFrom( x, 0, s, true, false ); - }; - } -}); - -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, - 20, - 20, - 20, - 10 - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceDimensionFrom( values[ i ], 0, start[ i ], false, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), 0, 'returns expected value' ); - t.strictEqual( actual.dtype, values[ i ].dtype, 'returns expected value' ); - } - t.end(); -}); - -tape( 'in non-strict mode, the function returns an empty array when a starting index is the one more than the last index along a dimension', function test( t ) { - var actual; - var values; - var start; - var dim; - 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' } ) - ]; - - dim = [ - 0, - 1, - 0, - 1, - 4 - ]; - - start = [ - 1, - 1, - 1, - 1, - 1 - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceDimensionFrom( values[ i ], dim[ i ], start[ i ], false, false ); // eslint-disable-line max-len - 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 a shifted view of a provided input array (ndims=1)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 2, true, false ); - - 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 = sliceDimensionFrom( x, 0, -4, true, false ); - - 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)', 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 1, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 2, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, -2, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 1, 1, true, false ); - - 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 = sliceDimensionFrom( x, 1, -2, true, false ); - - 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' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=3)', 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 1, true, false ); - - 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 = sliceDimensionFrom( x, 1, 1, true, false ); - - 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 = sliceDimensionFrom( x, 2, 2, true, false ); - - 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 = sliceDimensionFrom( x, 2, -1, true, false ); - - 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' ); - t.end(); -}); - -tape( 'if a provided ndarray has a constructor supporting read-only instances, the function returns a read-only instance', function test( t ) { - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - x = new baseCtor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports returning writable views', function test( t ) { - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - x = new baseCtor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - t.end(); -}); From 25f41dcb79c17275c31004abd0a8c8c553791e80 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 08:01:42 +0000 Subject: [PATCH 17/92] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index fcc43fc..8c8fdb9 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/ndarray-base-slice": "^0.1.0", "@stdlib/slice-base-args2multislice": "^0.1.0", "@stdlib/slice-ctor": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.2.0" }, "devDependencies": { From 281434a0b485bc9baf70c977cf393090650e27dc Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 14:41:02 +0000 Subject: [PATCH 18/92] Remove files --- index.d.ts | 534 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6716 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 1248b30..0000000 --- a/index.d.ts +++ /dev/null @@ -1,534 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceDimensionFrom( x: float64ndarray, dim: number, start: number, strict: boolean, writable: boolean ): float64ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceDimensionFrom( x: float32ndarray, dim: number, start: number, strict: boolean, writable: boolean ): float32ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: int32ndarray, dim: number, start: number, strict: boolean, writable: boolean ): int32ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: int16ndarray, dim: number, start: number, strict: boolean, writable: boolean ): int16ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: int8ndarray, dim: number, start: number, strict: boolean, writable: boolean ): int8ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint32ndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint32ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint16ndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint16ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint8ndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint8ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint8cndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint8cndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceDimensionFrom( x: complex128ndarray, dim: number, start: number, strict: boolean, writable: boolean ): complex128ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceDimensionFrom( x: complex64ndarray, dim: number, start: number, strict: boolean, writable: boolean ): complex64ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: genericndarray, dim: number, start: number, strict: boolean, writable: boolean ): genericndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: typedndarray, dim: number, start: number, strict: boolean, writable: boolean ): typedndarray; - - -// EXPORTS // - -export = sliceDimensionFrom; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 085cfde..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-ctor@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndims@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-normalize-index@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-filled@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";function m(m,o,l,a,j){var h,v,p;if(0===(v=r(m)))throw new TypeError(d("invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.",v));if(-1===(p=n(o,v-1)))throw new RangeError(d("invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.",v,o));return(h=t(null,v))[p]=new s(l,null),i(m,e(h),a,j)}export{m as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index f5d4091..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport Slice from '@stdlib/slice-ctor';\nimport ndims from '@stdlib/ndarray-base-ndims';\nimport slice from '@stdlib/ndarray-base-slice';\nimport normalizeIndex from '@stdlib/ndarray-base-normalize-index';\nimport filled from '@stdlib/array-base-filled';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns a shifted view of an input ndarray along a specified dimension.\n*\n* @param {ndarray} x - input array\n* @param {integer} dim - index of dimension to slice\n* @param {integer} start - starting index (inclusive)\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {TypeError} first argument must be an ndarray having one or more dimensions\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\n*\n* @example\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceDimensionFrom( x, 0, 1, false, false );\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 sliceDimensionFrom( x, dim, start, strict, writable ) {\n\tvar args;\n\tvar N;\n\tvar d;\n\n\t// Retrieve array meta data:\n\tN = ndims( x );\n\n\t// Check whether we were provided a zero-dimensional array...\n\tif ( N === 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.', N ) );\n\t}\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, N-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', N, dim ) );\n\t}\n\t// Define a list of slice arguments:\n\targs = filled( null, N );\n\targs[ d ] = new Slice( start, null );\n\n\t// Return a new array view:\n\treturn slice( x, args2multislice( args ), strict, writable );\n}\n\n\n// EXPORTS //\n\nexport default sliceDimensionFrom;\n"],"names":["sliceDimensionFrom","x","dim","start","strict","writable","args","N","d","ndims","TypeError","format","normalizeIndex","RangeError","filled","Slice","slice","args2multislice"],"mappings":";;wpBAyEA,SAASA,EAAoBC,EAAGC,EAAKC,EAAOC,EAAQC,GACnD,IAAIC,EACAC,EACAC,EAMJ,GAAW,KAHXD,EAAIE,EAAOR,IAIV,MAAM,IAAIS,UAAWC,EAAQ,+GAAgHJ,IAI9I,IAAY,KADZC,EAAII,EAAgBV,EAAKK,EAAE,IAE1B,MAAM,IAAIM,WAAYF,EAAQ,6GAA8GJ,EAAGL,IAOhJ,OAJAI,EAAOQ,EAAQ,KAAMP,IACfC,GAAM,IAAIO,EAAOZ,EAAO,MAGvBa,EAAOf,EAAGgB,EAAiBX,GAAQF,EAAQC,EACnD"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 8de8235..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 1e7900dd7226388840ccfb14e6818706e0a278ce Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 14:41:33 +0000 Subject: [PATCH 19/92] 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 | 43 +- SECURITY.md | 5 - benchmark/benchmark.js | 681 --- branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 49 - docs/types/test.ts | 164 - 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 | 102 - package.json | 70 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 616 -- 43 files changed, 6203 insertions(+), 5094 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 8ccc16d..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-01-01T05:10:26.565Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 05d1840..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-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 ced95ae..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-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 e50b813..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: '38 14 * * 5' - - # 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 + + ```
@@ -200,7 +193,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]. diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 8a6b7a2..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,681 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 sliceDimensionFrom = require( './../lib' ); - - -// MAIN // - -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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2 ], { 'dtype': 'float64' } ), - empty( [ 2 ], { 'dtype': 'float32' } ), - empty( [ 2 ], { 'dtype': 'int32' } ), - empty( [ 2 ], { 'dtype': 'complex128' } ), - empty( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== '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 d8a1299..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-from" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-from -[production-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-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 2ab577a..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import sliceDimensionFrom from '../docs/types/index'; -export = sliceDimensionFrom; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 0f7ac9a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var l=function(i,r){return function(){return r||i((r={exports:{}}).exports,r),r.exports}};var o=l(function(p,u){ -var v=require('@stdlib/slice-base-args2multislice/dist'),c=require('@stdlib/slice-ctor/dist'),f=require('@stdlib/ndarray-base-ndims/dist'),q=require('@stdlib/ndarray-base-slice/dist'),g=require('@stdlib/ndarray-base-normalize-index/dist'),w=require('@stdlib/array-base-filled/dist'),s=require('@stdlib/error-tools-fmtprodmsg/dist');function b(i,r,m,t,d){var n,e,a;if(e=f(i),e===0)throw new TypeError(s('1lDF7',e));if(a=g(r,e-1),a===-1)throw new RangeError(s('1lDF8',e,r));return n=w(null,e),n[a]=new c(m,null),q(i,v(n),t,d)}u.exports=b -});var h=o();module.exports=h; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index a75b3e0..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar args2multislice = require( '@stdlib/slice-base-args2multislice' );\nvar Slice = require( '@stdlib/slice-ctor' );\nvar ndims = require( '@stdlib/ndarray-base-ndims' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' );\nvar filled = require( '@stdlib/array-base-filled' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns a shifted view of an input ndarray along a specified dimension.\n*\n* @param {ndarray} x - input array\n* @param {integer} dim - index of dimension to slice\n* @param {integer} start - starting index (inclusive)\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {TypeError} first argument must be an ndarray having one or more dimensions\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceDimensionFrom( x, 0, 1, false, false );\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 sliceDimensionFrom( x, dim, start, strict, writable ) {\n\tvar args;\n\tvar N;\n\tvar d;\n\n\t// Retrieve array meta data:\n\tN = ndims( x );\n\n\t// Check whether we were provided a zero-dimensional array...\n\tif ( N === 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.', N ) );\n\t}\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, N-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', N, dim ) );\n\t}\n\t// Define a list of slice arguments:\n\targs = filled( null, N );\n\targs[ d ] = new Slice( start, null );\n\n\t// Return a new array view:\n\treturn slice( x, args2multislice( args ), strict, writable );\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceDimensionFrom;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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 shifted view of an input ndarray along a specified dimension.\n*\n* @module @stdlib/ndarray-base-slice-dimension-from\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var sliceDimensionFrom = require( '@stdlib/ndarray-base-slice-dimension-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 = sliceDimensionFrom( x, 0, 1, false, false );\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,EAAkB,QAAS,oCAAqC,EAChEC,EAAQ,QAAS,oBAAqB,EACtCC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAiB,QAAS,sCAAuC,EACjEC,EAAS,QAAS,2BAA4B,EAC9CC,EAAS,QAAS,uBAAwB,EA6C9C,SAASC,EAAoBC,EAAGC,EAAKC,EAAOC,EAAQC,EAAW,CAC9D,IAAIC,EACAC,EACAC,EAMJ,GAHAD,EAAIZ,EAAOM,CAAE,EAGRM,IAAM,EACV,MAAM,IAAI,UAAWR,EAAQ,+GAAgHQ,CAAE,CAAE,EAIlJ,GADAC,EAAIX,EAAgBK,EAAKK,EAAE,CAAE,EACxBC,IAAM,GACV,MAAM,IAAI,WAAYT,EAAQ,6GAA8GQ,EAAGL,CAAI,CAAE,EAGtJ,OAAAI,EAAOR,EAAQ,KAAMS,CAAE,EACvBD,EAAME,CAAE,EAAI,IAAId,EAAOS,EAAO,IAAK,EAG5BP,EAAOK,EAAGR,EAAiBa,CAAK,EAAGF,EAAQC,CAAS,CAC5D,CAKAb,EAAO,QAAUQ,IC7CjB,IAAIS,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "args2multislice", "Slice", "ndims", "slice", "normalizeIndex", "filled", "format", "sliceDimensionFrom", "x", "dim", "start", "strict", "writable", "args", "N", "d", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ffc1f03..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,49 +0,0 @@ - -{{alias}}( x, dim, start, strict, writable ) - Returns a shifted view of an input ndarray along a specified dimension. - - Parameters - ---------- - x: ndarray - Input array. - - dim: integer - Index of dimension to slice. If less than zero, the index is resolved - relative to the last dimension, with the last dimension corresponding to - the value `-1`. - - start: integer - Starting index (inclusive). If less than zero, the corresponding element - along the specified dimension is resolved relative to the last element - along that dimension. For negative integers, the last element - corresponds to the value `-1`. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - writable: boolean - Boolean indicating whether a returned ndarray should be writable. This - parameter only applies to ndarray constructors which support read-only - instances. - - Returns - ------- - out: ndarray - Output array view. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > x.shape - [ 2, 2 ] - > var y = {{alias}}( x, 1, 1, false, false ) - - > 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 9dfeaf3..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,164 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sliceDimensionFrom = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = 0; - - sliceDimensionFrom( empty( 'float64', sh, order ), 1, s, false, false ); // $ExpectType float64ndarray - sliceDimensionFrom( empty( 'float32', sh, order ), 1, s, false, false ); // $ExpectType float32ndarray - sliceDimensionFrom( empty( 'complex128', sh, order ), 1, s, false, false ); // $ExpectType complex128ndarray - sliceDimensionFrom( empty( 'complex64', sh, order ), 1, s, false, false ); // $ExpectType complex64ndarray - sliceDimensionFrom( empty( 'int32', sh, order ), 1, s, false, false ); // $ExpectType int32ndarray - sliceDimensionFrom( empty( 'int16', sh, order ), 1, s, false, false ); // $ExpectType int16ndarray - sliceDimensionFrom( empty( 'int8', sh, order ), 1, s, false, false ); // $ExpectType int8ndarray - sliceDimensionFrom( empty( 'uint32', sh, order ), 1, s, false, false ); // $ExpectType uint32ndarray - sliceDimensionFrom( empty( 'uint16', sh, order ), 1, s, false, false ); // $ExpectType uint16ndarray - sliceDimensionFrom( empty( 'uint8', sh, order ), 1, s, false, false ); // $ExpectType uint8ndarray - sliceDimensionFrom( empty( 'uint8c', sh, order ), 1, s, false, false ); // $ExpectType uint8cndarray - - sliceDimensionFrom( empty( 'float64', sh, order ), 1, s, true, true ); // $ExpectType float64ndarray - sliceDimensionFrom( empty( 'float32', sh, order ), 1, s, true, true ); // $ExpectType float32ndarray - sliceDimensionFrom( empty( 'complex128', sh, order ), 1, s, true, true ); // $ExpectType complex128ndarray - sliceDimensionFrom( empty( 'complex64', sh, order ), 1, s, true, true ); // $ExpectType complex64ndarray - sliceDimensionFrom( empty( 'int32', sh, order ), 1, s, true, true ); // $ExpectType int32ndarray - sliceDimensionFrom( empty( 'int16', sh, order ), 1, s, true, true ); // $ExpectType int16ndarray - sliceDimensionFrom( empty( 'int8', sh, order ), 1, s, true, true ); // $ExpectType int8ndarray - sliceDimensionFrom( empty( 'uint32', sh, order ), 1, s, true, true ); // $ExpectType uint32ndarray - sliceDimensionFrom( empty( 'uint16', sh, order ), 1, s, true, true ); // $ExpectType uint16ndarray - sliceDimensionFrom( empty( 'uint8', sh, order ), 1, s, true, true ); // $ExpectType uint8ndarray - sliceDimensionFrom( empty( 'uint8c', sh, order ), 1, s, true, true ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const s = 0; - - sliceDimensionFrom( '10', 1, s, false, false ); // $ExpectError - sliceDimensionFrom( 10, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( false, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( true, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( null, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( [], 1, s, false, false ); // $ExpectError - sliceDimensionFrom( {}, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( ( x: number ): number => x, 1, s, false, false ); // $ExpectError - - sliceDimensionFrom( '10', 1, s, true, true ); // $ExpectError - sliceDimensionFrom( 10, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( false, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( true, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( null, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( [], 1, s, true, true ); // $ExpectError - sliceDimensionFrom( {}, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( ( x: number ): number => x, 1, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a number... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 1; - - sliceDimensionFrom( x, '5', s, false, false ); // $ExpectError - sliceDimensionFrom( x, false, s, false, false ); // $ExpectError - sliceDimensionFrom( x, true, s, false, false ); // $ExpectError - sliceDimensionFrom( x, null, s, false, false ); // $ExpectError - sliceDimensionFrom( x, undefined, s, false, false ); // $ExpectError - sliceDimensionFrom( x, [ '5' ], s, false, false ); // $ExpectError - sliceDimensionFrom( x, {}, s, false, false ); // $ExpectError - sliceDimensionFrom( x, ( x: number ): number => x, s, false, false ); // $ExpectError - - sliceDimensionFrom( x, '5', s, true, true ); // $ExpectError - sliceDimensionFrom( x, false, s, true, true ); // $ExpectError - sliceDimensionFrom( x, true, s, true, true ); // $ExpectError - sliceDimensionFrom( x, null, s, true, true ); // $ExpectError - sliceDimensionFrom( x, undefined, s, true, true ); // $ExpectError - sliceDimensionFrom( x, [ '5' ], s, true, true ); // $ExpectError - sliceDimensionFrom( x, {}, s, true, true ); // $ExpectError - sliceDimensionFrom( x, ( x: number ): number => x, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceDimensionFrom( x, 1, '5', false, false ); // $ExpectError - sliceDimensionFrom( x, 1, false, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, true, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, null, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, undefined, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, [ '5' ], false, false ); // $ExpectError - sliceDimensionFrom( x, 1, {}, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, ( x: number ): number => x, 1, false, false ); // $ExpectError - - sliceDimensionFrom( x, 1, '5', true, true ); // $ExpectError - sliceDimensionFrom( x, 1, false, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, true, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, null, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, undefined, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, [ '5' ], true, true ); // $ExpectError - sliceDimensionFrom( x, 1, {}, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, ( x: number ): number => x, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x, 1, s, '5', false ); // $ExpectError - sliceDimensionFrom( x, 1, s, 5, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, null, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, undefined, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, [ '5' ], false ); // $ExpectError - sliceDimensionFrom( x, 1, s, {}, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x, 1, s, false, '5' ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, 5 ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, null ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, undefined ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, [ '5' ] ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, {} ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x ); // $ExpectError - sliceDimensionFrom( x, 1 ); // $ExpectError - sliceDimensionFrom( x, 1, s ); // $ExpectError - sliceDimensionFrom( x, 1, s, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index b17162a..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 sliceDimensionFrom = 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 = sliceDimensionFrom( x, 1, 1, false, false ); -// 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 columns of each matrix: -var y2 = sliceDimensionFrom( x, 2, 1, false, false ); -// returns - -var a2 = ndarray2array( y2 ); -console.log( a2 ); -// => [ [ [ 1, 2 ], [ 4, 5 ], [ 7, 8 ] ], [ [ 10, 11 ], [ 13, 14 ], [ 16, 17 ] ], [ [ 19, 20 ], [ 22, 23 ], [ 25, 26 ] ] ] - -// Get the last two matrices: -var y3 = sliceDimensionFrom( x, 0, 1, false, false ); -// returns - -var a3 = ndarray2array( y3 ); -console.log( a3 ); -// => [ [ [ 9, 10, 11 ], [ 12, 13, 14 ], [ 15, 16, 17 ] ], [ [ 18, 19, 20 ], [ 21, 22, 23 ], [ 24, 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 2d4595f..1248b30 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..04f9012 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-ctor@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndims@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-normalize-index@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-filled@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function m(m,o,a,l,j){var h,v,b;if(0===(v=i(m)))throw new TypeError(d("invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.",v));if(-1===(b=r(o,v-1)))throw new RangeError(d("invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.",v,o));return(h=t(null,v))[b]=new s(a,null),n(m,e(h),l,j)}export{m as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..8d8d253 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport Slice from '@stdlib/slice-ctor';\nimport ndims from '@stdlib/ndarray-base-ndims';\nimport slice from '@stdlib/ndarray-base-slice';\nimport normalizeIndex from '@stdlib/ndarray-base-normalize-index';\nimport filled from '@stdlib/array-base-filled';\nimport format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Returns a shifted view of an input ndarray along a specified dimension.\n*\n* @param {ndarray} x - input array\n* @param {integer} dim - index of dimension to slice\n* @param {integer} start - starting index (inclusive)\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {TypeError} first argument must be an ndarray having one or more dimensions\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\n*\n* @example\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceDimensionFrom( x, 0, 1, false, false );\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 sliceDimensionFrom( x, dim, start, strict, writable ) {\n\tvar args;\n\tvar N;\n\tvar d;\n\n\t// Retrieve array meta data:\n\tN = ndims( x );\n\n\t// Check whether we were provided a zero-dimensional array...\n\tif ( N === 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.', N ) );\n\t}\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, N-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', N, dim ) );\n\t}\n\t// Define a list of slice arguments:\n\targs = filled( null, N );\n\targs[ d ] = new Slice( start, null );\n\n\t// Return a new array view:\n\treturn slice( x, args2multislice( args ), strict, writable );\n}\n\n\n// EXPORTS //\n\nexport default sliceDimensionFrom;\n"],"names":["sliceDimensionFrom","x","dim","start","strict","writable","args","N","d","ndims","TypeError","format","normalizeIndex","RangeError","filled","Slice","slice","args2multislice"],"mappings":";;+oBAyEA,SAASA,EAAoBC,EAAGC,EAAKC,EAAOC,EAAQC,GACnD,IAAIC,EACAC,EACAC,EAMJ,GAAW,KAHXD,EAAIE,EAAOR,IAIV,MAAM,IAAIS,UAAWC,EAAQ,+GAAgHJ,IAI9I,IAAY,KADZC,EAAII,EAAgBV,EAAKK,EAAE,IAE1B,MAAM,IAAIM,WAAYF,EAAQ,6GAA8GJ,EAAGL,IAOhJ,OAJAI,EAAOQ,EAAQ,KAAMP,IACfC,GAAM,IAAIO,EAAOZ,EAAO,MAGvBa,EAAOf,EAAGgB,EAAiBX,GAAQF,EAAQC,EACnD"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index b3f97b2..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 shifted view of an input ndarray along a specified dimension. -* -* @module @stdlib/ndarray-base-slice-dimension-from -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var sliceDimensionFrom = require( '@stdlib/ndarray-base-slice-dimension-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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // 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 2b8e198..0000000 --- a/lib/main.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var Slice = require( '@stdlib/slice-ctor' ); -var ndims = require( '@stdlib/ndarray-base-ndims' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' ); -var filled = require( '@stdlib/array-base-filled' ); -var format = require( '@stdlib/string-format' ); - - -// MAIN // - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param {ndarray} x - input array -* @param {integer} dim - index of dimension to slice -* @param {integer} start - starting index (inclusive) -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @param {boolean} writable - boolean indicating whether a returned array should be writable -* @throws {TypeError} first argument must be an ndarray having one or more dimensions -* @throws {RangeError} dimension index exceeds the number of dimensions -* @throws {RangeError} slice 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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -function sliceDimensionFrom( x, dim, start, strict, writable ) { - var args; - var N; - var d; - - // Retrieve array meta data: - N = ndims( x ); - - // Check whether we were provided a zero-dimensional array... - if ( N === 0 ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.', N ) ); - } - // Normalize the dimension index: - d = normalizeIndex( dim, N-1 ); - if ( d === -1 ) { - throw new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', N, dim ) ); - } - // Define a list of slice arguments: - args = filled( null, N ); - args[ d ] = new Slice( start, null ); - - // Return a new array view: - return slice( x, args2multislice( args ), strict, writable ); -} - - -// EXPORTS // - -module.exports = sliceDimensionFrom; diff --git a/package.json b/package.json index 8c8fdb9..c42fa88 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Return a shifted view of an input ndarray along a specific dimension.", "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,49 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-filled": "^0.1.0", - "@stdlib/ndarray-base-ndims": "^0.1.0", - "@stdlib/ndarray-base-normalize-index": "^0.1.0", - "@stdlib/ndarray-base-slice": "^0.1.0", - "@stdlib/slice-base-args2multislice": "^0.1.0", - "@stdlib/slice-ctor": "^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/assert-is-ndarray-like": "^0.1.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-base-assert-is-read-only": "^0.1.1", - "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/ndarray-base-empty": "^0.1.1", - "@stdlib/ndarray-base-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..d221e27 --- /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 28703b5..0000000 --- a/test/test.js +++ /dev/null @@ -1,616 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 ndarray2array = require( '@stdlib/ndarray-to-array' ); -var baseCtor = require( '@stdlib/ndarray-base-ctor' ); -var ctor = require( '@stdlib/ndarray-ctor' ); -var sliceDimensionFrom = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sliceDimensionFrom, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a zero-dimensional array (strict=false)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error' ); - } - t.end(); - - function badValue( x ) { - return function badValue() { - sliceDimensionFrom( x, 0, 0, false, false ); - }; - } -}); - -tape( 'the function throws an error if provided a zero-dimensional array (strict=true)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error' ); - } - t.end(); - - function badValue( x ) { - return function badValue() { - sliceDimensionFrom( x, 0, 0, true, false ); - }; - } -}); - -tape( 'the function throws an error if the dimension index exceeds the number of dimensions (strict=false)', 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 ], 10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - t.throws( badValue( values[ i ], -10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - } - t.end(); - - function badValue( x, dim ) { - return function badValue() { - sliceDimensionFrom( x, dim, 0, false, false ); - }; - } -}); - -tape( 'the function throws an error if the dimension index exceeds the number of dimensions (strict=true)', 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 ], 10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - t.throws( badValue( values[ i ], -10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - } - t.end(); - - function badValue( x, dim ) { - return function badValue() { - sliceDimensionFrom( x, dim, 0, true, false ); - }; - } -}); - -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, - 20, - 20, - 20 - ]; - 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() { - sliceDimensionFrom( x, 0, s, true, false ); - }; - } -}); - -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, - 20, - 20, - 20, - 10 - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceDimensionFrom( values[ i ], 0, start[ i ], false, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), 0, 'returns expected value' ); - t.strictEqual( actual.dtype, values[ i ].dtype, 'returns expected value' ); - } - t.end(); -}); - -tape( 'in non-strict mode, the function returns an empty array when a starting index is the one more than the last index along a dimension', function test( t ) { - var actual; - var values; - var start; - var dim; - 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' } ) - ]; - - dim = [ - 0, - 1, - 0, - 1, - 4 - ]; - - start = [ - 1, - 1, - 1, - 1, - 1 - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceDimensionFrom( values[ i ], dim[ i ], start[ i ], false, false ); // eslint-disable-line max-len - 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 a shifted view of a provided input array (ndims=1)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 2, true, false ); - - 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 = sliceDimensionFrom( x, 0, -4, true, false ); - - 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)', 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 1, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 2, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, -2, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 1, 1, true, false ); - - 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 = sliceDimensionFrom( x, 1, -2, true, false ); - - 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' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=3)', 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 1, true, false ); - - 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 = sliceDimensionFrom( x, 1, 1, true, false ); - - 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 = sliceDimensionFrom( x, 2, 2, true, false ); - - 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 = sliceDimensionFrom( x, 2, -1, true, false ); - - 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' ); - t.end(); -}); - -tape( 'if a provided ndarray has a constructor supporting read-only instances, the function returns a read-only instance', function test( t ) { - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - x = new baseCtor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports returning writable views', function test( t ) { - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - x = new baseCtor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - t.end(); -}); From 3a9b1783e0f50b2d97d1f0528390a4035998905c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 08:34:54 +0000 Subject: [PATCH 20/92] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index fcc43fc..8c8fdb9 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/ndarray-base-slice": "^0.1.0", "@stdlib/slice-base-args2multislice": "^0.1.0", "@stdlib/slice-ctor": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.2.0" }, "devDependencies": { From fea7e6f5617ada1b696317fb6b934c5e513faebc Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 13:59:55 +0000 Subject: [PATCH 21/92] Remove files --- index.d.ts | 534 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6716 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 1248b30..0000000 --- a/index.d.ts +++ /dev/null @@ -1,534 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceDimensionFrom( x: float64ndarray, dim: number, start: number, strict: boolean, writable: boolean ): float64ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceDimensionFrom( x: float32ndarray, dim: number, start: number, strict: boolean, writable: boolean ): float32ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: int32ndarray, dim: number, start: number, strict: boolean, writable: boolean ): int32ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: int16ndarray, dim: number, start: number, strict: boolean, writable: boolean ): int16ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: int8ndarray, dim: number, start: number, strict: boolean, writable: boolean ): int8ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint32ndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint32ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint16ndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint16ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint8ndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint8ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint8cndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint8cndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceDimensionFrom( x: complex128ndarray, dim: number, start: number, strict: boolean, writable: boolean ): complex128ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceDimensionFrom( x: complex64ndarray, dim: number, start: number, strict: boolean, writable: boolean ): complex64ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: genericndarray, dim: number, start: number, strict: boolean, writable: boolean ): genericndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: typedndarray, dim: number, start: number, strict: boolean, writable: boolean ): typedndarray; - - -// EXPORTS // - -export = sliceDimensionFrom; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 04f9012..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-ctor@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndims@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-normalize-index@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-filled@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function m(m,o,a,l,j){var h,v,b;if(0===(v=i(m)))throw new TypeError(d("invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.",v));if(-1===(b=r(o,v-1)))throw new RangeError(d("invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.",v,o));return(h=t(null,v))[b]=new s(a,null),n(m,e(h),l,j)}export{m as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 8d8d253..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport Slice from '@stdlib/slice-ctor';\nimport ndims from '@stdlib/ndarray-base-ndims';\nimport slice from '@stdlib/ndarray-base-slice';\nimport normalizeIndex from '@stdlib/ndarray-base-normalize-index';\nimport filled from '@stdlib/array-base-filled';\nimport format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Returns a shifted view of an input ndarray along a specified dimension.\n*\n* @param {ndarray} x - input array\n* @param {integer} dim - index of dimension to slice\n* @param {integer} start - starting index (inclusive)\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {TypeError} first argument must be an ndarray having one or more dimensions\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\n*\n* @example\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceDimensionFrom( x, 0, 1, false, false );\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 sliceDimensionFrom( x, dim, start, strict, writable ) {\n\tvar args;\n\tvar N;\n\tvar d;\n\n\t// Retrieve array meta data:\n\tN = ndims( x );\n\n\t// Check whether we were provided a zero-dimensional array...\n\tif ( N === 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.', N ) );\n\t}\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, N-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', N, dim ) );\n\t}\n\t// Define a list of slice arguments:\n\targs = filled( null, N );\n\targs[ d ] = new Slice( start, null );\n\n\t// Return a new array view:\n\treturn slice( x, args2multislice( args ), strict, writable );\n}\n\n\n// EXPORTS //\n\nexport default sliceDimensionFrom;\n"],"names":["sliceDimensionFrom","x","dim","start","strict","writable","args","N","d","ndims","TypeError","format","normalizeIndex","RangeError","filled","Slice","slice","args2multislice"],"mappings":";;+oBAyEA,SAASA,EAAoBC,EAAGC,EAAKC,EAAOC,EAAQC,GACnD,IAAIC,EACAC,EACAC,EAMJ,GAAW,KAHXD,EAAIE,EAAOR,IAIV,MAAM,IAAIS,UAAWC,EAAQ,+GAAgHJ,IAI9I,IAAY,KADZC,EAAII,EAAgBV,EAAKK,EAAE,IAE1B,MAAM,IAAIM,WAAYF,EAAQ,6GAA8GJ,EAAGL,IAOhJ,OAJAI,EAAOQ,EAAQ,KAAMP,IACfC,GAAM,IAAIO,EAAOZ,EAAO,MAGvBa,EAAOf,EAAGgB,EAAiBX,GAAQF,EAAQC,EACnD"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index d221e27..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 7779368e9a0c4f63b1ce09d6916a90e61e53c472 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 14:00:32 +0000 Subject: [PATCH 22/92] 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 | 45 +- SECURITY.md | 5 - benchmark/benchmark.js | 681 --- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 49 - docs/types/test.ts | 164 - 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 | 102 - package.json | 70 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 616 -- 43 files changed, 6203 insertions(+), 5099 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index bf456e9..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-02-01T06:00:23.534Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 05d1840..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-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 ced95ae..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-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 e50b813..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: '38 14 * * 5' - - # 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 + + ```
@@ -202,7 +193,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]. diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 8a6b7a2..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,681 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 sliceDimensionFrom = require( './../lib' ); - - -// MAIN // - -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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2 ], { 'dtype': 'float64' } ), - empty( [ 2 ], { 'dtype': 'float32' } ), - empty( [ 2 ], { 'dtype': 'int32' } ), - empty( [ 2 ], { 'dtype': 'complex128' } ), - empty( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== '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 9543fcd..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-from" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-from -[production-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-slice-dimension-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 2ab577a..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import sliceDimensionFrom from '../docs/types/index'; -export = sliceDimensionFrom; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 0f7ac9a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var l=function(i,r){return function(){return r||i((r={exports:{}}).exports,r),r.exports}};var o=l(function(p,u){ -var v=require('@stdlib/slice-base-args2multislice/dist'),c=require('@stdlib/slice-ctor/dist'),f=require('@stdlib/ndarray-base-ndims/dist'),q=require('@stdlib/ndarray-base-slice/dist'),g=require('@stdlib/ndarray-base-normalize-index/dist'),w=require('@stdlib/array-base-filled/dist'),s=require('@stdlib/error-tools-fmtprodmsg/dist');function b(i,r,m,t,d){var n,e,a;if(e=f(i),e===0)throw new TypeError(s('1lDF7',e));if(a=g(r,e-1),a===-1)throw new RangeError(s('1lDF8',e,r));return n=w(null,e),n[a]=new c(m,null),q(i,v(n),t,d)}u.exports=b -});var h=o();module.exports=h; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index a75b3e0..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar args2multislice = require( '@stdlib/slice-base-args2multislice' );\nvar Slice = require( '@stdlib/slice-ctor' );\nvar ndims = require( '@stdlib/ndarray-base-ndims' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' );\nvar filled = require( '@stdlib/array-base-filled' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns a shifted view of an input ndarray along a specified dimension.\n*\n* @param {ndarray} x - input array\n* @param {integer} dim - index of dimension to slice\n* @param {integer} start - starting index (inclusive)\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {TypeError} first argument must be an ndarray having one or more dimensions\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceDimensionFrom( x, 0, 1, false, false );\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 sliceDimensionFrom( x, dim, start, strict, writable ) {\n\tvar args;\n\tvar N;\n\tvar d;\n\n\t// Retrieve array meta data:\n\tN = ndims( x );\n\n\t// Check whether we were provided a zero-dimensional array...\n\tif ( N === 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.', N ) );\n\t}\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, N-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', N, dim ) );\n\t}\n\t// Define a list of slice arguments:\n\targs = filled( null, N );\n\targs[ d ] = new Slice( start, null );\n\n\t// Return a new array view:\n\treturn slice( x, args2multislice( args ), strict, writable );\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceDimensionFrom;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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 shifted view of an input ndarray along a specified dimension.\n*\n* @module @stdlib/ndarray-base-slice-dimension-from\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var sliceDimensionFrom = require( '@stdlib/ndarray-base-slice-dimension-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 = sliceDimensionFrom( x, 0, 1, false, false );\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,EAAkB,QAAS,oCAAqC,EAChEC,EAAQ,QAAS,oBAAqB,EACtCC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAiB,QAAS,sCAAuC,EACjEC,EAAS,QAAS,2BAA4B,EAC9CC,EAAS,QAAS,uBAAwB,EA6C9C,SAASC,EAAoBC,EAAGC,EAAKC,EAAOC,EAAQC,EAAW,CAC9D,IAAIC,EACAC,EACAC,EAMJ,GAHAD,EAAIZ,EAAOM,CAAE,EAGRM,IAAM,EACV,MAAM,IAAI,UAAWR,EAAQ,+GAAgHQ,CAAE,CAAE,EAIlJ,GADAC,EAAIX,EAAgBK,EAAKK,EAAE,CAAE,EACxBC,IAAM,GACV,MAAM,IAAI,WAAYT,EAAQ,6GAA8GQ,EAAGL,CAAI,CAAE,EAGtJ,OAAAI,EAAOR,EAAQ,KAAMS,CAAE,EACvBD,EAAME,CAAE,EAAI,IAAId,EAAOS,EAAO,IAAK,EAG5BP,EAAOK,EAAGR,EAAiBa,CAAK,EAAGF,EAAQC,CAAS,CAC5D,CAKAb,EAAO,QAAUQ,IC7CjB,IAAIS,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "args2multislice", "Slice", "ndims", "slice", "normalizeIndex", "filled", "format", "sliceDimensionFrom", "x", "dim", "start", "strict", "writable", "args", "N", "d", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ffc1f03..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,49 +0,0 @@ - -{{alias}}( x, dim, start, strict, writable ) - Returns a shifted view of an input ndarray along a specified dimension. - - Parameters - ---------- - x: ndarray - Input array. - - dim: integer - Index of dimension to slice. If less than zero, the index is resolved - relative to the last dimension, with the last dimension corresponding to - the value `-1`. - - start: integer - Starting index (inclusive). If less than zero, the corresponding element - along the specified dimension is resolved relative to the last element - along that dimension. For negative integers, the last element - corresponds to the value `-1`. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - writable: boolean - Boolean indicating whether a returned ndarray should be writable. This - parameter only applies to ndarray constructors which support read-only - instances. - - Returns - ------- - out: ndarray - Output array view. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > x.shape - [ 2, 2 ] - > var y = {{alias}}( x, 1, 1, false, false ) - - > 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 9dfeaf3..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,164 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sliceDimensionFrom = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = 0; - - sliceDimensionFrom( empty( 'float64', sh, order ), 1, s, false, false ); // $ExpectType float64ndarray - sliceDimensionFrom( empty( 'float32', sh, order ), 1, s, false, false ); // $ExpectType float32ndarray - sliceDimensionFrom( empty( 'complex128', sh, order ), 1, s, false, false ); // $ExpectType complex128ndarray - sliceDimensionFrom( empty( 'complex64', sh, order ), 1, s, false, false ); // $ExpectType complex64ndarray - sliceDimensionFrom( empty( 'int32', sh, order ), 1, s, false, false ); // $ExpectType int32ndarray - sliceDimensionFrom( empty( 'int16', sh, order ), 1, s, false, false ); // $ExpectType int16ndarray - sliceDimensionFrom( empty( 'int8', sh, order ), 1, s, false, false ); // $ExpectType int8ndarray - sliceDimensionFrom( empty( 'uint32', sh, order ), 1, s, false, false ); // $ExpectType uint32ndarray - sliceDimensionFrom( empty( 'uint16', sh, order ), 1, s, false, false ); // $ExpectType uint16ndarray - sliceDimensionFrom( empty( 'uint8', sh, order ), 1, s, false, false ); // $ExpectType uint8ndarray - sliceDimensionFrom( empty( 'uint8c', sh, order ), 1, s, false, false ); // $ExpectType uint8cndarray - - sliceDimensionFrom( empty( 'float64', sh, order ), 1, s, true, true ); // $ExpectType float64ndarray - sliceDimensionFrom( empty( 'float32', sh, order ), 1, s, true, true ); // $ExpectType float32ndarray - sliceDimensionFrom( empty( 'complex128', sh, order ), 1, s, true, true ); // $ExpectType complex128ndarray - sliceDimensionFrom( empty( 'complex64', sh, order ), 1, s, true, true ); // $ExpectType complex64ndarray - sliceDimensionFrom( empty( 'int32', sh, order ), 1, s, true, true ); // $ExpectType int32ndarray - sliceDimensionFrom( empty( 'int16', sh, order ), 1, s, true, true ); // $ExpectType int16ndarray - sliceDimensionFrom( empty( 'int8', sh, order ), 1, s, true, true ); // $ExpectType int8ndarray - sliceDimensionFrom( empty( 'uint32', sh, order ), 1, s, true, true ); // $ExpectType uint32ndarray - sliceDimensionFrom( empty( 'uint16', sh, order ), 1, s, true, true ); // $ExpectType uint16ndarray - sliceDimensionFrom( empty( 'uint8', sh, order ), 1, s, true, true ); // $ExpectType uint8ndarray - sliceDimensionFrom( empty( 'uint8c', sh, order ), 1, s, true, true ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const s = 0; - - sliceDimensionFrom( '10', 1, s, false, false ); // $ExpectError - sliceDimensionFrom( 10, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( false, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( true, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( null, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( [], 1, s, false, false ); // $ExpectError - sliceDimensionFrom( {}, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( ( x: number ): number => x, 1, s, false, false ); // $ExpectError - - sliceDimensionFrom( '10', 1, s, true, true ); // $ExpectError - sliceDimensionFrom( 10, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( false, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( true, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( null, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( [], 1, s, true, true ); // $ExpectError - sliceDimensionFrom( {}, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( ( x: number ): number => x, 1, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a number... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 1; - - sliceDimensionFrom( x, '5', s, false, false ); // $ExpectError - sliceDimensionFrom( x, false, s, false, false ); // $ExpectError - sliceDimensionFrom( x, true, s, false, false ); // $ExpectError - sliceDimensionFrom( x, null, s, false, false ); // $ExpectError - sliceDimensionFrom( x, undefined, s, false, false ); // $ExpectError - sliceDimensionFrom( x, [ '5' ], s, false, false ); // $ExpectError - sliceDimensionFrom( x, {}, s, false, false ); // $ExpectError - sliceDimensionFrom( x, ( x: number ): number => x, s, false, false ); // $ExpectError - - sliceDimensionFrom( x, '5', s, true, true ); // $ExpectError - sliceDimensionFrom( x, false, s, true, true ); // $ExpectError - sliceDimensionFrom( x, true, s, true, true ); // $ExpectError - sliceDimensionFrom( x, null, s, true, true ); // $ExpectError - sliceDimensionFrom( x, undefined, s, true, true ); // $ExpectError - sliceDimensionFrom( x, [ '5' ], s, true, true ); // $ExpectError - sliceDimensionFrom( x, {}, s, true, true ); // $ExpectError - sliceDimensionFrom( x, ( x: number ): number => x, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceDimensionFrom( x, 1, '5', false, false ); // $ExpectError - sliceDimensionFrom( x, 1, false, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, true, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, null, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, undefined, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, [ '5' ], false, false ); // $ExpectError - sliceDimensionFrom( x, 1, {}, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, ( x: number ): number => x, 1, false, false ); // $ExpectError - - sliceDimensionFrom( x, 1, '5', true, true ); // $ExpectError - sliceDimensionFrom( x, 1, false, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, true, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, null, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, undefined, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, [ '5' ], true, true ); // $ExpectError - sliceDimensionFrom( x, 1, {}, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, ( x: number ): number => x, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x, 1, s, '5', false ); // $ExpectError - sliceDimensionFrom( x, 1, s, 5, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, null, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, undefined, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, [ '5' ], false ); // $ExpectError - sliceDimensionFrom( x, 1, s, {}, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x, 1, s, false, '5' ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, 5 ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, null ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, undefined ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, [ '5' ] ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, {} ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x ); // $ExpectError - sliceDimensionFrom( x, 1 ); // $ExpectError - sliceDimensionFrom( x, 1, s ); // $ExpectError - sliceDimensionFrom( x, 1, s, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index b17162a..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 sliceDimensionFrom = 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 = sliceDimensionFrom( x, 1, 1, false, false ); -// 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 columns of each matrix: -var y2 = sliceDimensionFrom( x, 2, 1, false, false ); -// returns - -var a2 = ndarray2array( y2 ); -console.log( a2 ); -// => [ [ [ 1, 2 ], [ 4, 5 ], [ 7, 8 ] ], [ [ 10, 11 ], [ 13, 14 ], [ 16, 17 ] ], [ [ 19, 20 ], [ 22, 23 ], [ 25, 26 ] ] ] - -// Get the last two matrices: -var y3 = sliceDimensionFrom( x, 0, 1, false, false ); -// returns - -var a3 = ndarray2array( y3 ); -console.log( a3 ); -// => [ [ [ 9, 10, 11 ], [ 12, 13, 14 ], [ 15, 16, 17 ] ], [ [ 18, 19, 20 ], [ 21, 22, 23 ], [ 24, 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 e398649..44225a7 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..04f9012 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-ctor@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndims@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-normalize-index@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-filled@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function m(m,o,a,l,j){var h,v,b;if(0===(v=i(m)))throw new TypeError(d("invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.",v));if(-1===(b=r(o,v-1)))throw new RangeError(d("invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.",v,o));return(h=t(null,v))[b]=new s(a,null),n(m,e(h),l,j)}export{m as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..8d8d253 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport Slice from '@stdlib/slice-ctor';\nimport ndims from '@stdlib/ndarray-base-ndims';\nimport slice from '@stdlib/ndarray-base-slice';\nimport normalizeIndex from '@stdlib/ndarray-base-normalize-index';\nimport filled from '@stdlib/array-base-filled';\nimport format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Returns a shifted view of an input ndarray along a specified dimension.\n*\n* @param {ndarray} x - input array\n* @param {integer} dim - index of dimension to slice\n* @param {integer} start - starting index (inclusive)\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {TypeError} first argument must be an ndarray having one or more dimensions\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\n*\n* @example\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceDimensionFrom( x, 0, 1, false, false );\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 sliceDimensionFrom( x, dim, start, strict, writable ) {\n\tvar args;\n\tvar N;\n\tvar d;\n\n\t// Retrieve array meta data:\n\tN = ndims( x );\n\n\t// Check whether we were provided a zero-dimensional array...\n\tif ( N === 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.', N ) );\n\t}\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, N-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', N, dim ) );\n\t}\n\t// Define a list of slice arguments:\n\targs = filled( null, N );\n\targs[ d ] = new Slice( start, null );\n\n\t// Return a new array view:\n\treturn slice( x, args2multislice( args ), strict, writable );\n}\n\n\n// EXPORTS //\n\nexport default sliceDimensionFrom;\n"],"names":["sliceDimensionFrom","x","dim","start","strict","writable","args","N","d","ndims","TypeError","format","normalizeIndex","RangeError","filled","Slice","slice","args2multislice"],"mappings":";;+oBAyEA,SAASA,EAAoBC,EAAGC,EAAKC,EAAOC,EAAQC,GACnD,IAAIC,EACAC,EACAC,EAMJ,GAAW,KAHXD,EAAIE,EAAOR,IAIV,MAAM,IAAIS,UAAWC,EAAQ,+GAAgHJ,IAI9I,IAAY,KADZC,EAAII,EAAgBV,EAAKK,EAAE,IAE1B,MAAM,IAAIM,WAAYF,EAAQ,6GAA8GJ,EAAGL,IAOhJ,OAJAI,EAAOQ,EAAQ,KAAMP,IACfC,GAAM,IAAIO,EAAOZ,EAAO,MAGvBa,EAAOf,EAAGgB,EAAiBX,GAAQF,EAAQC,EACnD"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index b3f97b2..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 shifted view of an input ndarray along a specified dimension. -* -* @module @stdlib/ndarray-base-slice-dimension-from -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var sliceDimensionFrom = require( '@stdlib/ndarray-base-slice-dimension-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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // 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 2b8e198..0000000 --- a/lib/main.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var Slice = require( '@stdlib/slice-ctor' ); -var ndims = require( '@stdlib/ndarray-base-ndims' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' ); -var filled = require( '@stdlib/array-base-filled' ); -var format = require( '@stdlib/string-format' ); - - -// MAIN // - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param {ndarray} x - input array -* @param {integer} dim - index of dimension to slice -* @param {integer} start - starting index (inclusive) -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @param {boolean} writable - boolean indicating whether a returned array should be writable -* @throws {TypeError} first argument must be an ndarray having one or more dimensions -* @throws {RangeError} dimension index exceeds the number of dimensions -* @throws {RangeError} slice 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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -function sliceDimensionFrom( x, dim, start, strict, writable ) { - var args; - var N; - var d; - - // Retrieve array meta data: - N = ndims( x ); - - // Check whether we were provided a zero-dimensional array... - if ( N === 0 ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.', N ) ); - } - // Normalize the dimension index: - d = normalizeIndex( dim, N-1 ); - if ( d === -1 ) { - throw new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', N, dim ) ); - } - // Define a list of slice arguments: - args = filled( null, N ); - args[ d ] = new Slice( start, null ); - - // Return a new array view: - return slice( x, args2multislice( args ), strict, writable ); -} - - -// EXPORTS // - -module.exports = sliceDimensionFrom; diff --git a/package.json b/package.json index 8c8fdb9..c42fa88 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Return a shifted view of an input ndarray along a specific dimension.", "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,49 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-filled": "^0.1.0", - "@stdlib/ndarray-base-ndims": "^0.1.0", - "@stdlib/ndarray-base-normalize-index": "^0.1.0", - "@stdlib/ndarray-base-slice": "^0.1.0", - "@stdlib/slice-base-args2multislice": "^0.1.0", - "@stdlib/slice-ctor": "^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/assert-is-ndarray-like": "^0.1.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-base-assert-is-read-only": "^0.1.1", - "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/ndarray-base-empty": "^0.1.1", - "@stdlib/ndarray-base-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..b7040c8 --- /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 28703b5..0000000 --- a/test/test.js +++ /dev/null @@ -1,616 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 ndarray2array = require( '@stdlib/ndarray-to-array' ); -var baseCtor = require( '@stdlib/ndarray-base-ctor' ); -var ctor = require( '@stdlib/ndarray-ctor' ); -var sliceDimensionFrom = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sliceDimensionFrom, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a zero-dimensional array (strict=false)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error' ); - } - t.end(); - - function badValue( x ) { - return function badValue() { - sliceDimensionFrom( x, 0, 0, false, false ); - }; - } -}); - -tape( 'the function throws an error if provided a zero-dimensional array (strict=true)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error' ); - } - t.end(); - - function badValue( x ) { - return function badValue() { - sliceDimensionFrom( x, 0, 0, true, false ); - }; - } -}); - -tape( 'the function throws an error if the dimension index exceeds the number of dimensions (strict=false)', 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 ], 10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - t.throws( badValue( values[ i ], -10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - } - t.end(); - - function badValue( x, dim ) { - return function badValue() { - sliceDimensionFrom( x, dim, 0, false, false ); - }; - } -}); - -tape( 'the function throws an error if the dimension index exceeds the number of dimensions (strict=true)', 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 ], 10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - t.throws( badValue( values[ i ], -10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - } - t.end(); - - function badValue( x, dim ) { - return function badValue() { - sliceDimensionFrom( x, dim, 0, true, false ); - }; - } -}); - -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, - 20, - 20, - 20 - ]; - 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() { - sliceDimensionFrom( x, 0, s, true, false ); - }; - } -}); - -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, - 20, - 20, - 20, - 10 - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceDimensionFrom( values[ i ], 0, start[ i ], false, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), 0, 'returns expected value' ); - t.strictEqual( actual.dtype, values[ i ].dtype, 'returns expected value' ); - } - t.end(); -}); - -tape( 'in non-strict mode, the function returns an empty array when a starting index is the one more than the last index along a dimension', function test( t ) { - var actual; - var values; - var start; - var dim; - 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' } ) - ]; - - dim = [ - 0, - 1, - 0, - 1, - 4 - ]; - - start = [ - 1, - 1, - 1, - 1, - 1 - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceDimensionFrom( values[ i ], dim[ i ], start[ i ], false, false ); // eslint-disable-line max-len - 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 a shifted view of a provided input array (ndims=1)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 2, true, false ); - - 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 = sliceDimensionFrom( x, 0, -4, true, false ); - - 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)', 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 1, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 2, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, -2, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 1, 1, true, false ); - - 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 = sliceDimensionFrom( x, 1, -2, true, false ); - - 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' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=3)', 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 1, true, false ); - - 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 = sliceDimensionFrom( x, 1, 1, true, false ); - - 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 = sliceDimensionFrom( x, 2, 2, true, false ); - - 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 = sliceDimensionFrom( x, 2, -1, true, false ); - - 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' ); - t.end(); -}); - -tape( 'if a provided ndarray has a constructor supporting read-only instances, the function returns a read-only instance', function test( t ) { - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - x = new baseCtor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports returning writable views', function test( t ) { - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - x = new baseCtor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - t.end(); -}); From 5bba445c0ada0bec756f6f92a492b88d98cfe332 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 00:16:30 +0000 Subject: [PATCH 23/92] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6354968..7f80f22 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/ndarray-base-slice": "^0.2.0", "@stdlib/slice-base-args2multislice": "^0.2.0", "@stdlib/slice-ctor": "^0.2.0", - "@stdlib/string-format": "^0.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.2.0", "@stdlib/types": "^0.3.1" }, "devDependencies": { From fe8bab1079eef1c50259b3b6da6011def8b1c216 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 03:04:54 +0000 Subject: [PATCH 24/92] Remove files --- index.d.ts | 534 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6716 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 44225a7..0000000 --- a/index.d.ts +++ /dev/null @@ -1,534 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceDimensionFrom( x: float64ndarray, dim: number, start: number, strict: boolean, writable: boolean ): float64ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceDimensionFrom( x: float32ndarray, dim: number, start: number, strict: boolean, writable: boolean ): float32ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: int32ndarray, dim: number, start: number, strict: boolean, writable: boolean ): int32ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: int16ndarray, dim: number, start: number, strict: boolean, writable: boolean ): int16ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: int8ndarray, dim: number, start: number, strict: boolean, writable: boolean ): int8ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint32ndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint32ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint16ndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint16ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint8ndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint8ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint8cndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint8cndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceDimensionFrom( x: complex128ndarray, dim: number, start: number, strict: boolean, writable: boolean ): complex128ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceDimensionFrom( x: complex64ndarray, dim: number, start: number, strict: boolean, writable: boolean ): complex64ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: genericndarray, dim: number, start: number, strict: boolean, writable: boolean ): genericndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: typedndarray, dim: number, start: number, strict: boolean, writable: boolean ): typedndarray; - - -// EXPORTS // - -export = sliceDimensionFrom; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 04f9012..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-ctor@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndims@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-normalize-index@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-filled@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function m(m,o,a,l,j){var h,v,b;if(0===(v=i(m)))throw new TypeError(d("invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.",v));if(-1===(b=r(o,v-1)))throw new RangeError(d("invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.",v,o));return(h=t(null,v))[b]=new s(a,null),n(m,e(h),l,j)}export{m as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 8d8d253..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport Slice from '@stdlib/slice-ctor';\nimport ndims from '@stdlib/ndarray-base-ndims';\nimport slice from '@stdlib/ndarray-base-slice';\nimport normalizeIndex from '@stdlib/ndarray-base-normalize-index';\nimport filled from '@stdlib/array-base-filled';\nimport format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Returns a shifted view of an input ndarray along a specified dimension.\n*\n* @param {ndarray} x - input array\n* @param {integer} dim - index of dimension to slice\n* @param {integer} start - starting index (inclusive)\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {TypeError} first argument must be an ndarray having one or more dimensions\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\n*\n* @example\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceDimensionFrom( x, 0, 1, false, false );\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 sliceDimensionFrom( x, dim, start, strict, writable ) {\n\tvar args;\n\tvar N;\n\tvar d;\n\n\t// Retrieve array meta data:\n\tN = ndims( x );\n\n\t// Check whether we were provided a zero-dimensional array...\n\tif ( N === 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.', N ) );\n\t}\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, N-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', N, dim ) );\n\t}\n\t// Define a list of slice arguments:\n\targs = filled( null, N );\n\targs[ d ] = new Slice( start, null );\n\n\t// Return a new array view:\n\treturn slice( x, args2multislice( args ), strict, writable );\n}\n\n\n// EXPORTS //\n\nexport default sliceDimensionFrom;\n"],"names":["sliceDimensionFrom","x","dim","start","strict","writable","args","N","d","ndims","TypeError","format","normalizeIndex","RangeError","filled","Slice","slice","args2multislice"],"mappings":";;+oBAyEA,SAASA,EAAoBC,EAAGC,EAAKC,EAAOC,EAAQC,GACnD,IAAIC,EACAC,EACAC,EAMJ,GAAW,KAHXD,EAAIE,EAAOR,IAIV,MAAM,IAAIS,UAAWC,EAAQ,+GAAgHJ,IAI9I,IAAY,KADZC,EAAII,EAAgBV,EAAKK,EAAE,IAE1B,MAAM,IAAIM,WAAYF,EAAQ,6GAA8GJ,EAAGL,IAOhJ,OAJAI,EAAOQ,EAAQ,KAAMP,IACfC,GAAM,IAAIO,EAAOZ,EAAO,MAGvBa,EAAOf,EAAGgB,EAAiBX,GAAQF,EAAQC,EACnD"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index b7040c8..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From d285e9c514f6094b297a3424fcba932a32dd68e4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 03:06:03 +0000 Subject: [PATCH 25/92] 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 | 45 +- SECURITY.md | 5 - benchmark/benchmark.js | 681 --- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 49 - docs/types/test.ts | 164 - 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 | 102 - package.json | 70 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 616 -- 42 files changed, 6203 insertions(+), 5102 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 05d1840..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-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 ced95ae..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-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 3486e8f..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: '38 14 * * 5' - - # 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 + + ```
@@ -202,7 +193,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]. diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 8a6b7a2..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,681 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 sliceDimensionFrom = require( './../lib' ); - - -// MAIN // - -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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2 ], { 'dtype': 'float64' } ), - empty( [ 2 ], { 'dtype': 'float32' } ), - empty( [ 2 ], { 'dtype': 'int32' } ), - empty( [ 2 ], { 'dtype': 'complex128' } ), - empty( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== '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 9543fcd..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-from" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-from -[production-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-slice-dimension-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 2ab577a..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import sliceDimensionFrom from '../docs/types/index'; -export = sliceDimensionFrom; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 0f7ac9a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var l=function(i,r){return function(){return r||i((r={exports:{}}).exports,r),r.exports}};var o=l(function(p,u){ -var v=require('@stdlib/slice-base-args2multislice/dist'),c=require('@stdlib/slice-ctor/dist'),f=require('@stdlib/ndarray-base-ndims/dist'),q=require('@stdlib/ndarray-base-slice/dist'),g=require('@stdlib/ndarray-base-normalize-index/dist'),w=require('@stdlib/array-base-filled/dist'),s=require('@stdlib/error-tools-fmtprodmsg/dist');function b(i,r,m,t,d){var n,e,a;if(e=f(i),e===0)throw new TypeError(s('1lDF7',e));if(a=g(r,e-1),a===-1)throw new RangeError(s('1lDF8',e,r));return n=w(null,e),n[a]=new c(m,null),q(i,v(n),t,d)}u.exports=b -});var h=o();module.exports=h; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index a75b3e0..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar args2multislice = require( '@stdlib/slice-base-args2multislice' );\nvar Slice = require( '@stdlib/slice-ctor' );\nvar ndims = require( '@stdlib/ndarray-base-ndims' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' );\nvar filled = require( '@stdlib/array-base-filled' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns a shifted view of an input ndarray along a specified dimension.\n*\n* @param {ndarray} x - input array\n* @param {integer} dim - index of dimension to slice\n* @param {integer} start - starting index (inclusive)\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {TypeError} first argument must be an ndarray having one or more dimensions\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceDimensionFrom( x, 0, 1, false, false );\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 sliceDimensionFrom( x, dim, start, strict, writable ) {\n\tvar args;\n\tvar N;\n\tvar d;\n\n\t// Retrieve array meta data:\n\tN = ndims( x );\n\n\t// Check whether we were provided a zero-dimensional array...\n\tif ( N === 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.', N ) );\n\t}\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, N-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', N, dim ) );\n\t}\n\t// Define a list of slice arguments:\n\targs = filled( null, N );\n\targs[ d ] = new Slice( start, null );\n\n\t// Return a new array view:\n\treturn slice( x, args2multislice( args ), strict, writable );\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceDimensionFrom;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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 shifted view of an input ndarray along a specified dimension.\n*\n* @module @stdlib/ndarray-base-slice-dimension-from\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var sliceDimensionFrom = require( '@stdlib/ndarray-base-slice-dimension-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 = sliceDimensionFrom( x, 0, 1, false, false );\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,EAAkB,QAAS,oCAAqC,EAChEC,EAAQ,QAAS,oBAAqB,EACtCC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAiB,QAAS,sCAAuC,EACjEC,EAAS,QAAS,2BAA4B,EAC9CC,EAAS,QAAS,uBAAwB,EA6C9C,SAASC,EAAoBC,EAAGC,EAAKC,EAAOC,EAAQC,EAAW,CAC9D,IAAIC,EACAC,EACAC,EAMJ,GAHAD,EAAIZ,EAAOM,CAAE,EAGRM,IAAM,EACV,MAAM,IAAI,UAAWR,EAAQ,+GAAgHQ,CAAE,CAAE,EAIlJ,GADAC,EAAIX,EAAgBK,EAAKK,EAAE,CAAE,EACxBC,IAAM,GACV,MAAM,IAAI,WAAYT,EAAQ,6GAA8GQ,EAAGL,CAAI,CAAE,EAGtJ,OAAAI,EAAOR,EAAQ,KAAMS,CAAE,EACvBD,EAAME,CAAE,EAAI,IAAId,EAAOS,EAAO,IAAK,EAG5BP,EAAOK,EAAGR,EAAiBa,CAAK,EAAGF,EAAQC,CAAS,CAC5D,CAKAb,EAAO,QAAUQ,IC7CjB,IAAIS,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "args2multislice", "Slice", "ndims", "slice", "normalizeIndex", "filled", "format", "sliceDimensionFrom", "x", "dim", "start", "strict", "writable", "args", "N", "d", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ffc1f03..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,49 +0,0 @@ - -{{alias}}( x, dim, start, strict, writable ) - Returns a shifted view of an input ndarray along a specified dimension. - - Parameters - ---------- - x: ndarray - Input array. - - dim: integer - Index of dimension to slice. If less than zero, the index is resolved - relative to the last dimension, with the last dimension corresponding to - the value `-1`. - - start: integer - Starting index (inclusive). If less than zero, the corresponding element - along the specified dimension is resolved relative to the last element - along that dimension. For negative integers, the last element - corresponds to the value `-1`. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - writable: boolean - Boolean indicating whether a returned ndarray should be writable. This - parameter only applies to ndarray constructors which support read-only - instances. - - Returns - ------- - out: ndarray - Output array view. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > x.shape - [ 2, 2 ] - > var y = {{alias}}( x, 1, 1, false, false ) - - > 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 9dfeaf3..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,164 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sliceDimensionFrom = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = 0; - - sliceDimensionFrom( empty( 'float64', sh, order ), 1, s, false, false ); // $ExpectType float64ndarray - sliceDimensionFrom( empty( 'float32', sh, order ), 1, s, false, false ); // $ExpectType float32ndarray - sliceDimensionFrom( empty( 'complex128', sh, order ), 1, s, false, false ); // $ExpectType complex128ndarray - sliceDimensionFrom( empty( 'complex64', sh, order ), 1, s, false, false ); // $ExpectType complex64ndarray - sliceDimensionFrom( empty( 'int32', sh, order ), 1, s, false, false ); // $ExpectType int32ndarray - sliceDimensionFrom( empty( 'int16', sh, order ), 1, s, false, false ); // $ExpectType int16ndarray - sliceDimensionFrom( empty( 'int8', sh, order ), 1, s, false, false ); // $ExpectType int8ndarray - sliceDimensionFrom( empty( 'uint32', sh, order ), 1, s, false, false ); // $ExpectType uint32ndarray - sliceDimensionFrom( empty( 'uint16', sh, order ), 1, s, false, false ); // $ExpectType uint16ndarray - sliceDimensionFrom( empty( 'uint8', sh, order ), 1, s, false, false ); // $ExpectType uint8ndarray - sliceDimensionFrom( empty( 'uint8c', sh, order ), 1, s, false, false ); // $ExpectType uint8cndarray - - sliceDimensionFrom( empty( 'float64', sh, order ), 1, s, true, true ); // $ExpectType float64ndarray - sliceDimensionFrom( empty( 'float32', sh, order ), 1, s, true, true ); // $ExpectType float32ndarray - sliceDimensionFrom( empty( 'complex128', sh, order ), 1, s, true, true ); // $ExpectType complex128ndarray - sliceDimensionFrom( empty( 'complex64', sh, order ), 1, s, true, true ); // $ExpectType complex64ndarray - sliceDimensionFrom( empty( 'int32', sh, order ), 1, s, true, true ); // $ExpectType int32ndarray - sliceDimensionFrom( empty( 'int16', sh, order ), 1, s, true, true ); // $ExpectType int16ndarray - sliceDimensionFrom( empty( 'int8', sh, order ), 1, s, true, true ); // $ExpectType int8ndarray - sliceDimensionFrom( empty( 'uint32', sh, order ), 1, s, true, true ); // $ExpectType uint32ndarray - sliceDimensionFrom( empty( 'uint16', sh, order ), 1, s, true, true ); // $ExpectType uint16ndarray - sliceDimensionFrom( empty( 'uint8', sh, order ), 1, s, true, true ); // $ExpectType uint8ndarray - sliceDimensionFrom( empty( 'uint8c', sh, order ), 1, s, true, true ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const s = 0; - - sliceDimensionFrom( '10', 1, s, false, false ); // $ExpectError - sliceDimensionFrom( 10, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( false, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( true, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( null, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( [], 1, s, false, false ); // $ExpectError - sliceDimensionFrom( {}, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( ( x: number ): number => x, 1, s, false, false ); // $ExpectError - - sliceDimensionFrom( '10', 1, s, true, true ); // $ExpectError - sliceDimensionFrom( 10, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( false, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( true, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( null, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( [], 1, s, true, true ); // $ExpectError - sliceDimensionFrom( {}, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( ( x: number ): number => x, 1, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a number... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 1; - - sliceDimensionFrom( x, '5', s, false, false ); // $ExpectError - sliceDimensionFrom( x, false, s, false, false ); // $ExpectError - sliceDimensionFrom( x, true, s, false, false ); // $ExpectError - sliceDimensionFrom( x, null, s, false, false ); // $ExpectError - sliceDimensionFrom( x, undefined, s, false, false ); // $ExpectError - sliceDimensionFrom( x, [ '5' ], s, false, false ); // $ExpectError - sliceDimensionFrom( x, {}, s, false, false ); // $ExpectError - sliceDimensionFrom( x, ( x: number ): number => x, s, false, false ); // $ExpectError - - sliceDimensionFrom( x, '5', s, true, true ); // $ExpectError - sliceDimensionFrom( x, false, s, true, true ); // $ExpectError - sliceDimensionFrom( x, true, s, true, true ); // $ExpectError - sliceDimensionFrom( x, null, s, true, true ); // $ExpectError - sliceDimensionFrom( x, undefined, s, true, true ); // $ExpectError - sliceDimensionFrom( x, [ '5' ], s, true, true ); // $ExpectError - sliceDimensionFrom( x, {}, s, true, true ); // $ExpectError - sliceDimensionFrom( x, ( x: number ): number => x, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceDimensionFrom( x, 1, '5', false, false ); // $ExpectError - sliceDimensionFrom( x, 1, false, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, true, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, null, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, undefined, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, [ '5' ], false, false ); // $ExpectError - sliceDimensionFrom( x, 1, {}, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, ( x: number ): number => x, 1, false, false ); // $ExpectError - - sliceDimensionFrom( x, 1, '5', true, true ); // $ExpectError - sliceDimensionFrom( x, 1, false, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, true, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, null, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, undefined, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, [ '5' ], true, true ); // $ExpectError - sliceDimensionFrom( x, 1, {}, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, ( x: number ): number => x, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x, 1, s, '5', false ); // $ExpectError - sliceDimensionFrom( x, 1, s, 5, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, null, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, undefined, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, [ '5' ], false ); // $ExpectError - sliceDimensionFrom( x, 1, s, {}, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x, 1, s, false, '5' ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, 5 ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, null ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, undefined ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, [ '5' ] ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, {} ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x ); // $ExpectError - sliceDimensionFrom( x, 1 ); // $ExpectError - sliceDimensionFrom( x, 1, s ); // $ExpectError - sliceDimensionFrom( x, 1, s, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index b17162a..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 sliceDimensionFrom = 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 = sliceDimensionFrom( x, 1, 1, false, false ); -// 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 columns of each matrix: -var y2 = sliceDimensionFrom( x, 2, 1, false, false ); -// returns - -var a2 = ndarray2array( y2 ); -console.log( a2 ); -// => [ [ [ 1, 2 ], [ 4, 5 ], [ 7, 8 ] ], [ [ 10, 11 ], [ 13, 14 ], [ 16, 17 ] ], [ [ 19, 20 ], [ 22, 23 ], [ 25, 26 ] ] ] - -// Get the last two matrices: -var y3 = sliceDimensionFrom( x, 0, 1, false, false ); -// returns - -var a3 = ndarray2array( y3 ); -console.log( a3 ); -// => [ [ [ 9, 10, 11 ], [ 12, 13, 14 ], [ 15, 16, 17 ] ], [ [ 18, 19, 20 ], [ 21, 22, 23 ], [ 24, 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 e398649..44225a7 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..c48d57d --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-ctor@v0.2.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndims@v0.2.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-normalize-index@v0.2.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-filled@v0.2.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function m(m,o,a,l,j){var h,v,b;if(0===(v=i(m)))throw new TypeError(d("invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.",v));if(-1===(b=r(o,v-1)))throw new RangeError(d("invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.",v,o));return(h=t(null,v))[b]=new s(a,null),n(m,e(h),l,j)}export{m as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..8d8d253 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport Slice from '@stdlib/slice-ctor';\nimport ndims from '@stdlib/ndarray-base-ndims';\nimport slice from '@stdlib/ndarray-base-slice';\nimport normalizeIndex from '@stdlib/ndarray-base-normalize-index';\nimport filled from '@stdlib/array-base-filled';\nimport format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Returns a shifted view of an input ndarray along a specified dimension.\n*\n* @param {ndarray} x - input array\n* @param {integer} dim - index of dimension to slice\n* @param {integer} start - starting index (inclusive)\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {TypeError} first argument must be an ndarray having one or more dimensions\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\n*\n* @example\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceDimensionFrom( x, 0, 1, false, false );\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 sliceDimensionFrom( x, dim, start, strict, writable ) {\n\tvar args;\n\tvar N;\n\tvar d;\n\n\t// Retrieve array meta data:\n\tN = ndims( x );\n\n\t// Check whether we were provided a zero-dimensional array...\n\tif ( N === 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.', N ) );\n\t}\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, N-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', N, dim ) );\n\t}\n\t// Define a list of slice arguments:\n\targs = filled( null, N );\n\targs[ d ] = new Slice( start, null );\n\n\t// Return a new array view:\n\treturn slice( x, args2multislice( args ), strict, writable );\n}\n\n\n// EXPORTS //\n\nexport default sliceDimensionFrom;\n"],"names":["sliceDimensionFrom","x","dim","start","strict","writable","args","N","d","ndims","TypeError","format","normalizeIndex","RangeError","filled","Slice","slice","args2multislice"],"mappings":";;+oBAyEA,SAASA,EAAoBC,EAAGC,EAAKC,EAAOC,EAAQC,GACnD,IAAIC,EACAC,EACAC,EAMJ,GAAW,KAHXD,EAAIE,EAAOR,IAIV,MAAM,IAAIS,UAAWC,EAAQ,+GAAgHJ,IAI9I,IAAY,KADZC,EAAII,EAAgBV,EAAKK,EAAE,IAE1B,MAAM,IAAIM,WAAYF,EAAQ,6GAA8GJ,EAAGL,IAOhJ,OAJAI,EAAOQ,EAAQ,KAAMP,IACfC,GAAM,IAAIO,EAAOZ,EAAO,MAGvBa,EAAOf,EAAGgB,EAAiBX,GAAQF,EAAQC,EACnD"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index b3f97b2..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 shifted view of an input ndarray along a specified dimension. -* -* @module @stdlib/ndarray-base-slice-dimension-from -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var sliceDimensionFrom = require( '@stdlib/ndarray-base-slice-dimension-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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // 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 2b8e198..0000000 --- a/lib/main.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var Slice = require( '@stdlib/slice-ctor' ); -var ndims = require( '@stdlib/ndarray-base-ndims' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' ); -var filled = require( '@stdlib/array-base-filled' ); -var format = require( '@stdlib/string-format' ); - - -// MAIN // - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param {ndarray} x - input array -* @param {integer} dim - index of dimension to slice -* @param {integer} start - starting index (inclusive) -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @param {boolean} writable - boolean indicating whether a returned array should be writable -* @throws {TypeError} first argument must be an ndarray having one or more dimensions -* @throws {RangeError} dimension index exceeds the number of dimensions -* @throws {RangeError} slice 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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -function sliceDimensionFrom( x, dim, start, strict, writable ) { - var args; - var N; - var d; - - // Retrieve array meta data: - N = ndims( x ); - - // Check whether we were provided a zero-dimensional array... - if ( N === 0 ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.', N ) ); - } - // Normalize the dimension index: - d = normalizeIndex( dim, N-1 ); - if ( d === -1 ) { - throw new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', N, dim ) ); - } - // Define a list of slice arguments: - args = filled( null, N ); - args[ d ] = new Slice( start, null ); - - // Return a new array view: - return slice( x, args2multislice( args ), strict, writable ); -} - - -// EXPORTS // - -module.exports = sliceDimensionFrom; diff --git a/package.json b/package.json index 7f80f22..b102c9b 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.0", "description": "Return a shifted view of an input ndarray along a specific dimension.", "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,49 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-filled": "^0.2.0", - "@stdlib/ndarray-base-ndims": "^0.2.0", - "@stdlib/ndarray-base-normalize-index": "^0.2.0", - "@stdlib/ndarray-base-slice": "^0.2.0", - "@stdlib/slice-base-args2multislice": "^0.2.0", - "@stdlib/slice-ctor": "^0.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.2.0", - "@stdlib/types": "^0.3.1" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/array-typed": "^0.1.0", - "@stdlib/assert-is-ndarray-like": "^0.2.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.0", - "@stdlib/ndarray-base-ctor": "^0.2.0", - "@stdlib/ndarray-base-empty": "^0.1.1", - "@stdlib/ndarray-base-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..c97e8dd --- /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 28703b5..0000000 --- a/test/test.js +++ /dev/null @@ -1,616 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 ndarray2array = require( '@stdlib/ndarray-to-array' ); -var baseCtor = require( '@stdlib/ndarray-base-ctor' ); -var ctor = require( '@stdlib/ndarray-ctor' ); -var sliceDimensionFrom = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sliceDimensionFrom, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a zero-dimensional array (strict=false)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error' ); - } - t.end(); - - function badValue( x ) { - return function badValue() { - sliceDimensionFrom( x, 0, 0, false, false ); - }; - } -}); - -tape( 'the function throws an error if provided a zero-dimensional array (strict=true)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error' ); - } - t.end(); - - function badValue( x ) { - return function badValue() { - sliceDimensionFrom( x, 0, 0, true, false ); - }; - } -}); - -tape( 'the function throws an error if the dimension index exceeds the number of dimensions (strict=false)', 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 ], 10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - t.throws( badValue( values[ i ], -10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - } - t.end(); - - function badValue( x, dim ) { - return function badValue() { - sliceDimensionFrom( x, dim, 0, false, false ); - }; - } -}); - -tape( 'the function throws an error if the dimension index exceeds the number of dimensions (strict=true)', 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 ], 10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - t.throws( badValue( values[ i ], -10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - } - t.end(); - - function badValue( x, dim ) { - return function badValue() { - sliceDimensionFrom( x, dim, 0, true, false ); - }; - } -}); - -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, - 20, - 20, - 20 - ]; - 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() { - sliceDimensionFrom( x, 0, s, true, false ); - }; - } -}); - -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, - 20, - 20, - 20, - 10 - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceDimensionFrom( values[ i ], 0, start[ i ], false, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), 0, 'returns expected value' ); - t.strictEqual( actual.dtype, values[ i ].dtype, 'returns expected value' ); - } - t.end(); -}); - -tape( 'in non-strict mode, the function returns an empty array when a starting index is the one more than the last index along a dimension', function test( t ) { - var actual; - var values; - var start; - var dim; - 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' } ) - ]; - - dim = [ - 0, - 1, - 0, - 1, - 4 - ]; - - start = [ - 1, - 1, - 1, - 1, - 1 - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceDimensionFrom( values[ i ], dim[ i ], start[ i ], false, false ); // eslint-disable-line max-len - 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 a shifted view of a provided input array (ndims=1)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 2, true, false ); - - 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 = sliceDimensionFrom( x, 0, -4, true, false ); - - 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)', 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 1, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 2, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, -2, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 1, 1, true, false ); - - 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 = sliceDimensionFrom( x, 1, -2, true, false ); - - 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' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=3)', 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 1, true, false ); - - 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 = sliceDimensionFrom( x, 1, 1, true, false ); - - 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 = sliceDimensionFrom( x, 2, 2, true, false ); - - 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 = sliceDimensionFrom( x, 2, -1, true, false ); - - 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' ); - t.end(); -}); - -tape( 'if a provided ndarray has a constructor supporting read-only instances, the function returns a read-only instance', function test( t ) { - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - x = new baseCtor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports returning writable views', function test( t ) { - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - x = new baseCtor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - t.end(); -}); From b1a028e1f685461621e8dfe33dc5e044aeda6725 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 04:49:26 +0000 Subject: [PATCH 26/92] 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 b08d0ee..8822422 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import sliceDimensionFrom from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-dimension-from@esm/index.mjs'; +import sliceDimensionFrom from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-dimension-from@v0.2.0-esm/index.mjs'; ``` #### sliceDimensionFrom( x, dim, start, strict, writable ) @@ -128,7 +128,7 @@ The function accepts the following arguments: 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 sliceDimensionFrom from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-dimension-from@esm/index.mjs'; +import sliceDimensionFrom from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-dimension-from@v0.2.0-esm/index.mjs'; // Create a linear ndarray buffer: var buf = zeroTo( 27 ); From 97b3418d432a5bee41b2c94d464a200f10043682 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 04:49:27 +0000 Subject: [PATCH 27/92] Auto-generated commit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8822422..122c90a 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,11 @@ limitations under the License. ## Usage +```javascript +import sliceDimensionFrom from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-dimension-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-base-slice-dimension-from/tags). For example, + ```javascript import sliceDimensionFrom from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-dimension-from@v0.2.0-esm/index.mjs'; ``` @@ -128,7 +133,7 @@ The function accepts the following arguments: 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 sliceDimensionFrom from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-dimension-from@v0.2.0-esm/index.mjs'; +import sliceDimensionFrom from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-dimension-from@esm/index.mjs'; // Create a linear ndarray buffer: var buf = zeroTo( 27 ); From fe38902732032ac1066cee14e4ec77d09f4f34cf Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 19:09:15 +0000 Subject: [PATCH 28/92] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 2b8e198..5dbaaef 100644 --- a/lib/main.js +++ b/lib/main.js @@ -26,7 +26,7 @@ var ndims = require( '@stdlib/ndarray-base-ndims' ); var slice = require( '@stdlib/ndarray-base-slice' ); var normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' ); var filled = require( '@stdlib/array-base-filled' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -81,12 +81,12 @@ function sliceDimensionFrom( x, dim, start, strict, writable ) { // Check whether we were provided a zero-dimensional array... if ( N === 0 ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.', N ) ); + throw new TypeError( format( '1lDF7', N ) ); } // Normalize the dimension index: d = normalizeIndex( dim, N-1 ); if ( d === -1 ) { - throw new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', N, dim ) ); + throw new RangeError( format( '1lDF8', N, dim ) ); } // Define a list of slice arguments: args = filled( null, N ); diff --git a/package.json b/package.json index 088ae05..b5b0bf9 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/ndarray-base-slice": "^0.2.1", "@stdlib/slice-base-args2multislice": "^0.2.1", "@stdlib/slice-ctor": "^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 59c9247a7bad21ddb5580133ec5ea6d5f9439aac Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 20:02:39 +0000 Subject: [PATCH 29/92] Remove files --- index.d.ts | 534 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6716 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 44225a7..0000000 --- a/index.d.ts +++ /dev/null @@ -1,534 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceDimensionFrom( x: float64ndarray, dim: number, start: number, strict: boolean, writable: boolean ): float64ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceDimensionFrom( x: float32ndarray, dim: number, start: number, strict: boolean, writable: boolean ): float32ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: int32ndarray, dim: number, start: number, strict: boolean, writable: boolean ): int32ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: int16ndarray, dim: number, start: number, strict: boolean, writable: boolean ): int16ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: int8ndarray, dim: number, start: number, strict: boolean, writable: boolean ): int8ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint32ndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint32ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint16ndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint16ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint8ndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint8ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint8cndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint8cndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceDimensionFrom( x: complex128ndarray, dim: number, start: number, strict: boolean, writable: boolean ): complex128ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceDimensionFrom( x: complex64ndarray, dim: number, start: number, strict: boolean, writable: boolean ): complex64ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: genericndarray, dim: number, start: number, strict: boolean, writable: boolean ): genericndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: typedndarray, dim: number, start: number, strict: boolean, writable: boolean ): typedndarray; - - -// EXPORTS // - -export = sliceDimensionFrom; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index c48d57d..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-ctor@v0.2.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndims@v0.2.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-normalize-index@v0.2.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-filled@v0.2.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function m(m,o,a,l,j){var h,v,b;if(0===(v=i(m)))throw new TypeError(d("invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.",v));if(-1===(b=r(o,v-1)))throw new RangeError(d("invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.",v,o));return(h=t(null,v))[b]=new s(a,null),n(m,e(h),l,j)}export{m as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 8d8d253..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport Slice from '@stdlib/slice-ctor';\nimport ndims from '@stdlib/ndarray-base-ndims';\nimport slice from '@stdlib/ndarray-base-slice';\nimport normalizeIndex from '@stdlib/ndarray-base-normalize-index';\nimport filled from '@stdlib/array-base-filled';\nimport format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Returns a shifted view of an input ndarray along a specified dimension.\n*\n* @param {ndarray} x - input array\n* @param {integer} dim - index of dimension to slice\n* @param {integer} start - starting index (inclusive)\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {TypeError} first argument must be an ndarray having one or more dimensions\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\n*\n* @example\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceDimensionFrom( x, 0, 1, false, false );\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 sliceDimensionFrom( x, dim, start, strict, writable ) {\n\tvar args;\n\tvar N;\n\tvar d;\n\n\t// Retrieve array meta data:\n\tN = ndims( x );\n\n\t// Check whether we were provided a zero-dimensional array...\n\tif ( N === 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.', N ) );\n\t}\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, N-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', N, dim ) );\n\t}\n\t// Define a list of slice arguments:\n\targs = filled( null, N );\n\targs[ d ] = new Slice( start, null );\n\n\t// Return a new array view:\n\treturn slice( x, args2multislice( args ), strict, writable );\n}\n\n\n// EXPORTS //\n\nexport default sliceDimensionFrom;\n"],"names":["sliceDimensionFrom","x","dim","start","strict","writable","args","N","d","ndims","TypeError","format","normalizeIndex","RangeError","filled","Slice","slice","args2multislice"],"mappings":";;+oBAyEA,SAASA,EAAoBC,EAAGC,EAAKC,EAAOC,EAAQC,GACnD,IAAIC,EACAC,EACAC,EAMJ,GAAW,KAHXD,EAAIE,EAAOR,IAIV,MAAM,IAAIS,UAAWC,EAAQ,+GAAgHJ,IAI9I,IAAY,KADZC,EAAII,EAAgBV,EAAKK,EAAE,IAE1B,MAAM,IAAIM,WAAYF,EAAQ,6GAA8GJ,EAAGL,IAOhJ,OAJAI,EAAOQ,EAAQ,KAAMP,IACfC,GAAM,IAAIO,EAAOZ,EAAO,MAGvBa,EAAOf,EAAGgB,EAAiBX,GAAQF,EAAQC,EACnD"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index c97e8dd..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From d849f5d6de4a4c77d18de76709a31bef51120447 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 20:03:00 +0000 Subject: [PATCH 30/92] 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 | 45 +- SECURITY.md | 5 - benchmark/benchmark.js | 681 --- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 49 - docs/types/test.ts | 164 - 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 | 102 - package.json | 71 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 616 --- 42 files changed, 4868 insertions(+), 5097 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 05d1840..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-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 ced95ae..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-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 60a2bb4..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: '38 14 * * 5' - - # 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 + + ```
@@ -202,7 +193,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]. diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 8a6b7a2..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,681 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 sliceDimensionFrom = require( './../lib' ); - - -// MAIN // - -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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2 ], { 'dtype': 'float64' } ), - empty( [ 2 ], { 'dtype': 'float32' } ), - empty( [ 2 ], { 'dtype': 'int32' } ), - empty( [ 2 ], { 'dtype': 'complex128' } ), - empty( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== '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 9543fcd..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-from" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-from -[production-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-slice-dimension-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 2ab577a..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import sliceDimensionFrom from '../docs/types/index'; -export = sliceDimensionFrom; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 0f7ac9a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var l=function(i,r){return function(){return r||i((r={exports:{}}).exports,r),r.exports}};var o=l(function(p,u){ -var v=require('@stdlib/slice-base-args2multislice/dist'),c=require('@stdlib/slice-ctor/dist'),f=require('@stdlib/ndarray-base-ndims/dist'),q=require('@stdlib/ndarray-base-slice/dist'),g=require('@stdlib/ndarray-base-normalize-index/dist'),w=require('@stdlib/array-base-filled/dist'),s=require('@stdlib/error-tools-fmtprodmsg/dist');function b(i,r,m,t,d){var n,e,a;if(e=f(i),e===0)throw new TypeError(s('1lDF7',e));if(a=g(r,e-1),a===-1)throw new RangeError(s('1lDF8',e,r));return n=w(null,e),n[a]=new c(m,null),q(i,v(n),t,d)}u.exports=b -});var h=o();module.exports=h; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index a75b3e0..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar args2multislice = require( '@stdlib/slice-base-args2multislice' );\nvar Slice = require( '@stdlib/slice-ctor' );\nvar ndims = require( '@stdlib/ndarray-base-ndims' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' );\nvar filled = require( '@stdlib/array-base-filled' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns a shifted view of an input ndarray along a specified dimension.\n*\n* @param {ndarray} x - input array\n* @param {integer} dim - index of dimension to slice\n* @param {integer} start - starting index (inclusive)\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {TypeError} first argument must be an ndarray having one or more dimensions\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceDimensionFrom( x, 0, 1, false, false );\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 sliceDimensionFrom( x, dim, start, strict, writable ) {\n\tvar args;\n\tvar N;\n\tvar d;\n\n\t// Retrieve array meta data:\n\tN = ndims( x );\n\n\t// Check whether we were provided a zero-dimensional array...\n\tif ( N === 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.', N ) );\n\t}\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, N-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', N, dim ) );\n\t}\n\t// Define a list of slice arguments:\n\targs = filled( null, N );\n\targs[ d ] = new Slice( start, null );\n\n\t// Return a new array view:\n\treturn slice( x, args2multislice( args ), strict, writable );\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceDimensionFrom;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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 shifted view of an input ndarray along a specified dimension.\n*\n* @module @stdlib/ndarray-base-slice-dimension-from\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var sliceDimensionFrom = require( '@stdlib/ndarray-base-slice-dimension-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 = sliceDimensionFrom( x, 0, 1, false, false );\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,EAAkB,QAAS,oCAAqC,EAChEC,EAAQ,QAAS,oBAAqB,EACtCC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAiB,QAAS,sCAAuC,EACjEC,EAAS,QAAS,2BAA4B,EAC9CC,EAAS,QAAS,uBAAwB,EA6C9C,SAASC,EAAoBC,EAAGC,EAAKC,EAAOC,EAAQC,EAAW,CAC9D,IAAIC,EACAC,EACAC,EAMJ,GAHAD,EAAIZ,EAAOM,CAAE,EAGRM,IAAM,EACV,MAAM,IAAI,UAAWR,EAAQ,+GAAgHQ,CAAE,CAAE,EAIlJ,GADAC,EAAIX,EAAgBK,EAAKK,EAAE,CAAE,EACxBC,IAAM,GACV,MAAM,IAAI,WAAYT,EAAQ,6GAA8GQ,EAAGL,CAAI,CAAE,EAGtJ,OAAAI,EAAOR,EAAQ,KAAMS,CAAE,EACvBD,EAAME,CAAE,EAAI,IAAId,EAAOS,EAAO,IAAK,EAG5BP,EAAOK,EAAGR,EAAiBa,CAAK,EAAGF,EAAQC,CAAS,CAC5D,CAKAb,EAAO,QAAUQ,IC7CjB,IAAIS,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "args2multislice", "Slice", "ndims", "slice", "normalizeIndex", "filled", "format", "sliceDimensionFrom", "x", "dim", "start", "strict", "writable", "args", "N", "d", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ffc1f03..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,49 +0,0 @@ - -{{alias}}( x, dim, start, strict, writable ) - Returns a shifted view of an input ndarray along a specified dimension. - - Parameters - ---------- - x: ndarray - Input array. - - dim: integer - Index of dimension to slice. If less than zero, the index is resolved - relative to the last dimension, with the last dimension corresponding to - the value `-1`. - - start: integer - Starting index (inclusive). If less than zero, the corresponding element - along the specified dimension is resolved relative to the last element - along that dimension. For negative integers, the last element - corresponds to the value `-1`. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - writable: boolean - Boolean indicating whether a returned ndarray should be writable. This - parameter only applies to ndarray constructors which support read-only - instances. - - Returns - ------- - out: ndarray - Output array view. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > x.shape - [ 2, 2 ] - > var y = {{alias}}( x, 1, 1, false, false ) - - > 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 9dfeaf3..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,164 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sliceDimensionFrom = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = 0; - - sliceDimensionFrom( empty( 'float64', sh, order ), 1, s, false, false ); // $ExpectType float64ndarray - sliceDimensionFrom( empty( 'float32', sh, order ), 1, s, false, false ); // $ExpectType float32ndarray - sliceDimensionFrom( empty( 'complex128', sh, order ), 1, s, false, false ); // $ExpectType complex128ndarray - sliceDimensionFrom( empty( 'complex64', sh, order ), 1, s, false, false ); // $ExpectType complex64ndarray - sliceDimensionFrom( empty( 'int32', sh, order ), 1, s, false, false ); // $ExpectType int32ndarray - sliceDimensionFrom( empty( 'int16', sh, order ), 1, s, false, false ); // $ExpectType int16ndarray - sliceDimensionFrom( empty( 'int8', sh, order ), 1, s, false, false ); // $ExpectType int8ndarray - sliceDimensionFrom( empty( 'uint32', sh, order ), 1, s, false, false ); // $ExpectType uint32ndarray - sliceDimensionFrom( empty( 'uint16', sh, order ), 1, s, false, false ); // $ExpectType uint16ndarray - sliceDimensionFrom( empty( 'uint8', sh, order ), 1, s, false, false ); // $ExpectType uint8ndarray - sliceDimensionFrom( empty( 'uint8c', sh, order ), 1, s, false, false ); // $ExpectType uint8cndarray - - sliceDimensionFrom( empty( 'float64', sh, order ), 1, s, true, true ); // $ExpectType float64ndarray - sliceDimensionFrom( empty( 'float32', sh, order ), 1, s, true, true ); // $ExpectType float32ndarray - sliceDimensionFrom( empty( 'complex128', sh, order ), 1, s, true, true ); // $ExpectType complex128ndarray - sliceDimensionFrom( empty( 'complex64', sh, order ), 1, s, true, true ); // $ExpectType complex64ndarray - sliceDimensionFrom( empty( 'int32', sh, order ), 1, s, true, true ); // $ExpectType int32ndarray - sliceDimensionFrom( empty( 'int16', sh, order ), 1, s, true, true ); // $ExpectType int16ndarray - sliceDimensionFrom( empty( 'int8', sh, order ), 1, s, true, true ); // $ExpectType int8ndarray - sliceDimensionFrom( empty( 'uint32', sh, order ), 1, s, true, true ); // $ExpectType uint32ndarray - sliceDimensionFrom( empty( 'uint16', sh, order ), 1, s, true, true ); // $ExpectType uint16ndarray - sliceDimensionFrom( empty( 'uint8', sh, order ), 1, s, true, true ); // $ExpectType uint8ndarray - sliceDimensionFrom( empty( 'uint8c', sh, order ), 1, s, true, true ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const s = 0; - - sliceDimensionFrom( '10', 1, s, false, false ); // $ExpectError - sliceDimensionFrom( 10, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( false, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( true, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( null, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( [], 1, s, false, false ); // $ExpectError - sliceDimensionFrom( {}, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( ( x: number ): number => x, 1, s, false, false ); // $ExpectError - - sliceDimensionFrom( '10', 1, s, true, true ); // $ExpectError - sliceDimensionFrom( 10, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( false, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( true, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( null, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( [], 1, s, true, true ); // $ExpectError - sliceDimensionFrom( {}, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( ( x: number ): number => x, 1, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a number... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 1; - - sliceDimensionFrom( x, '5', s, false, false ); // $ExpectError - sliceDimensionFrom( x, false, s, false, false ); // $ExpectError - sliceDimensionFrom( x, true, s, false, false ); // $ExpectError - sliceDimensionFrom( x, null, s, false, false ); // $ExpectError - sliceDimensionFrom( x, undefined, s, false, false ); // $ExpectError - sliceDimensionFrom( x, [ '5' ], s, false, false ); // $ExpectError - sliceDimensionFrom( x, {}, s, false, false ); // $ExpectError - sliceDimensionFrom( x, ( x: number ): number => x, s, false, false ); // $ExpectError - - sliceDimensionFrom( x, '5', s, true, true ); // $ExpectError - sliceDimensionFrom( x, false, s, true, true ); // $ExpectError - sliceDimensionFrom( x, true, s, true, true ); // $ExpectError - sliceDimensionFrom( x, null, s, true, true ); // $ExpectError - sliceDimensionFrom( x, undefined, s, true, true ); // $ExpectError - sliceDimensionFrom( x, [ '5' ], s, true, true ); // $ExpectError - sliceDimensionFrom( x, {}, s, true, true ); // $ExpectError - sliceDimensionFrom( x, ( x: number ): number => x, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceDimensionFrom( x, 1, '5', false, false ); // $ExpectError - sliceDimensionFrom( x, 1, false, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, true, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, null, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, undefined, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, [ '5' ], false, false ); // $ExpectError - sliceDimensionFrom( x, 1, {}, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, ( x: number ): number => x, 1, false, false ); // $ExpectError - - sliceDimensionFrom( x, 1, '5', true, true ); // $ExpectError - sliceDimensionFrom( x, 1, false, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, true, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, null, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, undefined, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, [ '5' ], true, true ); // $ExpectError - sliceDimensionFrom( x, 1, {}, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, ( x: number ): number => x, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x, 1, s, '5', false ); // $ExpectError - sliceDimensionFrom( x, 1, s, 5, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, null, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, undefined, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, [ '5' ], false ); // $ExpectError - sliceDimensionFrom( x, 1, s, {}, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x, 1, s, false, '5' ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, 5 ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, null ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, undefined ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, [ '5' ] ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, {} ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x ); // $ExpectError - sliceDimensionFrom( x, 1 ); // $ExpectError - sliceDimensionFrom( x, 1, s ); // $ExpectError - sliceDimensionFrom( x, 1, s, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index b17162a..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 sliceDimensionFrom = 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 = sliceDimensionFrom( x, 1, 1, false, false ); -// 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 columns of each matrix: -var y2 = sliceDimensionFrom( x, 2, 1, false, false ); -// returns - -var a2 = ndarray2array( y2 ); -console.log( a2 ); -// => [ [ [ 1, 2 ], [ 4, 5 ], [ 7, 8 ] ], [ [ 10, 11 ], [ 13, 14 ], [ 16, 17 ] ], [ [ 19, 20 ], [ 22, 23 ], [ 25, 26 ] ] ] - -// Get the last two matrices: -var y3 = sliceDimensionFrom( x, 0, 1, false, false ); -// returns - -var a3 = ndarray2array( y3 ); -console.log( a3 ); -// => [ [ [ 9, 10, 11 ], [ 12, 13, 14 ], [ 15, 16, 17 ] ], [ [ 18, 19, 20 ], [ 21, 22, 23 ], [ 24, 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 e398649..44225a7 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..3493ede --- /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/slice-base-args2multislice@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-ctor@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndims@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-normalize-index@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-filled@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function m(m,l,o,j,a){var p,h,v;if(0===(h=r(m)))throw new TypeError(n("1lDF7",h));if(-1===(v=i(l,h-1)))throw new RangeError(n("1lDF8",h,l));return(p=d(null,h))[v]=new e(o,null),t(m,s(p),j,a)}export{m as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..275a0ea --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport Slice from '@stdlib/slice-ctor';\nimport ndims from '@stdlib/ndarray-base-ndims';\nimport slice from '@stdlib/ndarray-base-slice';\nimport normalizeIndex from '@stdlib/ndarray-base-normalize-index';\nimport filled from '@stdlib/array-base-filled';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns a shifted view of an input ndarray along a specified dimension.\n*\n* @param {ndarray} x - input array\n* @param {integer} dim - index of dimension to slice\n* @param {integer} start - starting index (inclusive)\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {TypeError} first argument must be an ndarray having one or more dimensions\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\n*\n* @example\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceDimensionFrom( x, 0, 1, false, false );\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 sliceDimensionFrom( x, dim, start, strict, writable ) {\n\tvar args;\n\tvar N;\n\tvar d;\n\n\t// Retrieve array meta data:\n\tN = ndims( x );\n\n\t// Check whether we were provided a zero-dimensional array...\n\tif ( N === 0 ) {\n\t\tthrow new TypeError( format( '1lDF7', N ) );\n\t}\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, N-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( '1lDF8', N, dim ) );\n\t}\n\t// Define a list of slice arguments:\n\targs = filled( null, N );\n\targs[ d ] = new Slice( start, null );\n\n\t// Return a new array view:\n\treturn slice( x, args2multislice( args ), strict, writable );\n}\n\n\n// EXPORTS //\n\nexport default sliceDimensionFrom;\n"],"names":["sliceDimensionFrom","x","dim","start","strict","writable","args","N","d","ndims","TypeError","format","normalizeIndex","RangeError","filled","Slice","slice","args2multislice"],"mappings":";;wpBAyEA,SAASA,EAAoBC,EAAGC,EAAKC,EAAOC,EAAQC,GACnD,IAAIC,EACAC,EACAC,EAMJ,GAAW,KAHXD,EAAIE,EAAOR,IAIV,MAAM,IAAIS,UAAWC,EAAQ,QAASJ,IAIvC,IAAY,KADZC,EAAII,EAAgBV,EAAKK,EAAE,IAE1B,MAAM,IAAIM,WAAYF,EAAQ,QAASJ,EAAGL,IAO3C,OAJAI,EAAOQ,EAAQ,KAAMP,IACfC,GAAM,IAAIO,EAAOZ,EAAO,MAGvBa,EAAOf,EAAGgB,EAAiBX,GAAQF,EAAQC,EACnD"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index b3f97b2..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 shifted view of an input ndarray along a specified dimension. -* -* @module @stdlib/ndarray-base-slice-dimension-from -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var sliceDimensionFrom = require( '@stdlib/ndarray-base-slice-dimension-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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // 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 5dbaaef..0000000 --- a/lib/main.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var Slice = require( '@stdlib/slice-ctor' ); -var ndims = require( '@stdlib/ndarray-base-ndims' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' ); -var filled = require( '@stdlib/array-base-filled' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param {ndarray} x - input array -* @param {integer} dim - index of dimension to slice -* @param {integer} start - starting index (inclusive) -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @param {boolean} writable - boolean indicating whether a returned array should be writable -* @throws {TypeError} first argument must be an ndarray having one or more dimensions -* @throws {RangeError} dimension index exceeds the number of dimensions -* @throws {RangeError} slice 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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -function sliceDimensionFrom( x, dim, start, strict, writable ) { - var args; - var N; - var d; - - // Retrieve array meta data: - N = ndims( x ); - - // Check whether we were provided a zero-dimensional array... - if ( N === 0 ) { - throw new TypeError( format( '1lDF7', N ) ); - } - // Normalize the dimension index: - d = normalizeIndex( dim, N-1 ); - if ( d === -1 ) { - throw new RangeError( format( '1lDF8', N, dim ) ); - } - // Define a list of slice arguments: - args = filled( null, N ); - args[ d ] = new Slice( start, null ); - - // Return a new array view: - return slice( x, args2multislice( args ), strict, writable ); -} - - -// EXPORTS // - -module.exports = sliceDimensionFrom; diff --git a/package.json b/package.json index b5b0bf9..7879a68 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Return a shifted view of an input ndarray along a specific dimension.", "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,50 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-filled": "^0.2.1", - "@stdlib/ndarray-base-ndims": "^0.2.1", - "@stdlib/ndarray-base-normalize-index": "^0.2.1", - "@stdlib/ndarray-base-slice": "^0.2.1", - "@stdlib/slice-base-args2multislice": "^0.2.1", - "@stdlib/slice-ctor": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.0", - "@stdlib/array-typed": "^0.2.0", - "@stdlib/assert-is-ndarray-like": "^0.2.1", - "@stdlib/ndarray-array": "^0.2.0", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.1", - "@stdlib/ndarray-base-ctor": "^0.2.1", - "@stdlib/ndarray-base-empty": "^0.2.0", - "@stdlib/ndarray-base-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..160aa8f --- /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 28703b5..0000000 --- a/test/test.js +++ /dev/null @@ -1,616 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 ndarray2array = require( '@stdlib/ndarray-to-array' ); -var baseCtor = require( '@stdlib/ndarray-base-ctor' ); -var ctor = require( '@stdlib/ndarray-ctor' ); -var sliceDimensionFrom = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sliceDimensionFrom, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a zero-dimensional array (strict=false)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error' ); - } - t.end(); - - function badValue( x ) { - return function badValue() { - sliceDimensionFrom( x, 0, 0, false, false ); - }; - } -}); - -tape( 'the function throws an error if provided a zero-dimensional array (strict=true)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error' ); - } - t.end(); - - function badValue( x ) { - return function badValue() { - sliceDimensionFrom( x, 0, 0, true, false ); - }; - } -}); - -tape( 'the function throws an error if the dimension index exceeds the number of dimensions (strict=false)', 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 ], 10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - t.throws( badValue( values[ i ], -10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - } - t.end(); - - function badValue( x, dim ) { - return function badValue() { - sliceDimensionFrom( x, dim, 0, false, false ); - }; - } -}); - -tape( 'the function throws an error if the dimension index exceeds the number of dimensions (strict=true)', 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 ], 10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - t.throws( badValue( values[ i ], -10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - } - t.end(); - - function badValue( x, dim ) { - return function badValue() { - sliceDimensionFrom( x, dim, 0, true, false ); - }; - } -}); - -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, - 20, - 20, - 20 - ]; - 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() { - sliceDimensionFrom( x, 0, s, true, false ); - }; - } -}); - -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, - 20, - 20, - 20, - 10 - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceDimensionFrom( values[ i ], 0, start[ i ], false, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), 0, 'returns expected value' ); - t.strictEqual( actual.dtype, values[ i ].dtype, 'returns expected value' ); - } - t.end(); -}); - -tape( 'in non-strict mode, the function returns an empty array when a starting index is the one more than the last index along a dimension', function test( t ) { - var actual; - var values; - var start; - var dim; - 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' } ) - ]; - - dim = [ - 0, - 1, - 0, - 1, - 4 - ]; - - start = [ - 1, - 1, - 1, - 1, - 1 - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceDimensionFrom( values[ i ], dim[ i ], start[ i ], false, false ); // eslint-disable-line max-len - 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 a shifted view of a provided input array (ndims=1)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 2, true, false ); - - 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 = sliceDimensionFrom( x, 0, -4, true, false ); - - 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)', 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 1, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 2, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, -2, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 1, 1, true, false ); - - 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 = sliceDimensionFrom( x, 1, -2, true, false ); - - 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' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=3)', 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 1, true, false ); - - 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 = sliceDimensionFrom( x, 1, 1, true, false ); - - 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 = sliceDimensionFrom( x, 2, 2, true, false ); - - 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 = sliceDimensionFrom( x, 2, -1, true, false ); - - 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' ); - t.end(); -}); - -tape( 'if a provided ndarray has a constructor supporting read-only instances, the function returns a read-only instance', function test( t ) { - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - x = new baseCtor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports returning writable views', function test( t ) { - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - x = new baseCtor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - t.end(); -}); From 5bdd9037bca959d55c4bb8abb848828c6f5d7cc9 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 20:38:58 +0000 Subject: [PATCH 31/92] 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 0890b7c..229217b 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import sliceDimensionFrom from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-dimension-from@esm/index.mjs'; +import sliceDimensionFrom from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-dimension-from@v0.2.1-esm/index.mjs'; ``` #### sliceDimensionFrom( x, dim, start, strict, writable ) @@ -128,7 +128,7 @@ The function accepts the following arguments: 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 sliceDimensionFrom from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-dimension-from@esm/index.mjs'; +import sliceDimensionFrom from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-dimension-from@v0.2.1-esm/index.mjs'; // Create a linear ndarray buffer: var buf = zeroTo( 27 ); From eb3f86e7b51398179f36d59203fadc7f2df0fb42 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 20:38:58 +0000 Subject: [PATCH 32/92] Auto-generated commit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 229217b..ce91875 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,11 @@ limitations under the License. ## Usage +```javascript +import sliceDimensionFrom from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-dimension-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-base-slice-dimension-from/tags). For example, + ```javascript import sliceDimensionFrom from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-dimension-from@v0.2.1-esm/index.mjs'; ``` @@ -128,7 +133,7 @@ The function accepts the following arguments: 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 sliceDimensionFrom from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-dimension-from@v0.2.1-esm/index.mjs'; +import sliceDimensionFrom from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-dimension-from@esm/index.mjs'; // Create a linear ndarray buffer: var buf = zeroTo( 27 ); From 96362ffefe7f64b0fe68027bfeb396399a08e8e6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Mar 2024 07:55:04 +0000 Subject: [PATCH 33/92] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 2b8e198..5dbaaef 100644 --- a/lib/main.js +++ b/lib/main.js @@ -26,7 +26,7 @@ var ndims = require( '@stdlib/ndarray-base-ndims' ); var slice = require( '@stdlib/ndarray-base-slice' ); var normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' ); var filled = require( '@stdlib/array-base-filled' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -81,12 +81,12 @@ function sliceDimensionFrom( x, dim, start, strict, writable ) { // Check whether we were provided a zero-dimensional array... if ( N === 0 ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.', N ) ); + throw new TypeError( format( '1lDF7', N ) ); } // Normalize the dimension index: d = normalizeIndex( dim, N-1 ); if ( d === -1 ) { - throw new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', N, dim ) ); + throw new RangeError( format( '1lDF8', N, dim ) ); } // Define a list of slice arguments: args = filled( null, N ); diff --git a/package.json b/package.json index 4895887..f7083d8 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/ndarray-base-slice": "^0.2.1", "@stdlib/slice-base-args2multislice": "^0.2.1", "@stdlib/slice-ctor": "^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 098a4aa072f9acc7194319512a73d8b4fccf3fbf Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Mar 2024 13:34:31 +0000 Subject: [PATCH 34/92] Remove files --- index.d.ts | 534 ------ index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5381 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 44225a7..0000000 --- a/index.d.ts +++ /dev/null @@ -1,534 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceDimensionFrom( x: float64ndarray, dim: number, start: number, strict: boolean, writable: boolean ): float64ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceDimensionFrom( x: float32ndarray, dim: number, start: number, strict: boolean, writable: boolean ): float32ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: int32ndarray, dim: number, start: number, strict: boolean, writable: boolean ): int32ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: int16ndarray, dim: number, start: number, strict: boolean, writable: boolean ): int16ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: int8ndarray, dim: number, start: number, strict: boolean, writable: boolean ): int8ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint32ndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint32ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint16ndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint16ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint8ndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint8ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint8cndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint8cndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceDimensionFrom( x: complex128ndarray, dim: number, start: number, strict: boolean, writable: boolean ): complex128ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceDimensionFrom( x: complex64ndarray, dim: number, start: number, strict: boolean, writable: boolean ): complex64ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: genericndarray, dim: number, start: number, strict: boolean, writable: boolean ): genericndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: typedndarray, dim: number, start: number, strict: boolean, writable: boolean ): typedndarray; - - -// EXPORTS // - -export = sliceDimensionFrom; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 3493ede..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/slice-base-args2multislice@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-ctor@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndims@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-normalize-index@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-filled@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function m(m,l,o,j,a){var p,h,v;if(0===(h=r(m)))throw new TypeError(n("1lDF7",h));if(-1===(v=i(l,h-1)))throw new RangeError(n("1lDF8",h,l));return(p=d(null,h))[v]=new e(o,null),t(m,s(p),j,a)}export{m as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 275a0ea..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport Slice from '@stdlib/slice-ctor';\nimport ndims from '@stdlib/ndarray-base-ndims';\nimport slice from '@stdlib/ndarray-base-slice';\nimport normalizeIndex from '@stdlib/ndarray-base-normalize-index';\nimport filled from '@stdlib/array-base-filled';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns a shifted view of an input ndarray along a specified dimension.\n*\n* @param {ndarray} x - input array\n* @param {integer} dim - index of dimension to slice\n* @param {integer} start - starting index (inclusive)\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {TypeError} first argument must be an ndarray having one or more dimensions\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\n*\n* @example\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceDimensionFrom( x, 0, 1, false, false );\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 sliceDimensionFrom( x, dim, start, strict, writable ) {\n\tvar args;\n\tvar N;\n\tvar d;\n\n\t// Retrieve array meta data:\n\tN = ndims( x );\n\n\t// Check whether we were provided a zero-dimensional array...\n\tif ( N === 0 ) {\n\t\tthrow new TypeError( format( '1lDF7', N ) );\n\t}\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, N-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( '1lDF8', N, dim ) );\n\t}\n\t// Define a list of slice arguments:\n\targs = filled( null, N );\n\targs[ d ] = new Slice( start, null );\n\n\t// Return a new array view:\n\treturn slice( x, args2multislice( args ), strict, writable );\n}\n\n\n// EXPORTS //\n\nexport default sliceDimensionFrom;\n"],"names":["sliceDimensionFrom","x","dim","start","strict","writable","args","N","d","ndims","TypeError","format","normalizeIndex","RangeError","filled","Slice","slice","args2multislice"],"mappings":";;wpBAyEA,SAASA,EAAoBC,EAAGC,EAAKC,EAAOC,EAAQC,GACnD,IAAIC,EACAC,EACAC,EAMJ,GAAW,KAHXD,EAAIE,EAAOR,IAIV,MAAM,IAAIS,UAAWC,EAAQ,QAASJ,IAIvC,IAAY,KADZC,EAAII,EAAgBV,EAAKK,EAAE,IAE1B,MAAM,IAAIM,WAAYF,EAAQ,QAASJ,EAAGL,IAO3C,OAJAI,EAAOQ,EAAQ,KAAMP,IACfC,GAAM,IAAIO,EAAOZ,EAAO,MAGvBa,EAAOf,EAAGgB,EAAiBX,GAAQF,EAAQC,EACnD"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 160aa8f..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From b6946f9f4c3f8865e4bd8f390477de9f2e75cba6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Mar 2024 13:34:53 +0000 Subject: [PATCH 35/92] 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 | 45 +- SECURITY.md | 5 - benchmark/benchmark.js | 681 --- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 49 - docs/types/test.ts | 164 - 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 | 102 - package.json | 71 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 616 --- 43 files changed, 4868 insertions(+), 5099 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 7ebd054..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-03-01T05:42:23.737Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 05d1840..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-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 ced95ae..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-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 60a2bb4..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: '38 14 * * 5' - - # 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 + + ```
@@ -202,7 +193,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]. diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 8a6b7a2..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,681 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 sliceDimensionFrom = require( './../lib' ); - - -// MAIN // - -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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2 ], { 'dtype': 'float64' } ), - empty( [ 2 ], { 'dtype': 'float32' } ), - empty( [ 2 ], { 'dtype': 'int32' } ), - empty( [ 2 ], { 'dtype': 'complex128' } ), - empty( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== '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 9543fcd..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-from" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-from -[production-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-slice-dimension-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 2ab577a..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import sliceDimensionFrom from '../docs/types/index'; -export = sliceDimensionFrom; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 0f7ac9a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var l=function(i,r){return function(){return r||i((r={exports:{}}).exports,r),r.exports}};var o=l(function(p,u){ -var v=require('@stdlib/slice-base-args2multislice/dist'),c=require('@stdlib/slice-ctor/dist'),f=require('@stdlib/ndarray-base-ndims/dist'),q=require('@stdlib/ndarray-base-slice/dist'),g=require('@stdlib/ndarray-base-normalize-index/dist'),w=require('@stdlib/array-base-filled/dist'),s=require('@stdlib/error-tools-fmtprodmsg/dist');function b(i,r,m,t,d){var n,e,a;if(e=f(i),e===0)throw new TypeError(s('1lDF7',e));if(a=g(r,e-1),a===-1)throw new RangeError(s('1lDF8',e,r));return n=w(null,e),n[a]=new c(m,null),q(i,v(n),t,d)}u.exports=b -});var h=o();module.exports=h; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index a75b3e0..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar args2multislice = require( '@stdlib/slice-base-args2multislice' );\nvar Slice = require( '@stdlib/slice-ctor' );\nvar ndims = require( '@stdlib/ndarray-base-ndims' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' );\nvar filled = require( '@stdlib/array-base-filled' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns a shifted view of an input ndarray along a specified dimension.\n*\n* @param {ndarray} x - input array\n* @param {integer} dim - index of dimension to slice\n* @param {integer} start - starting index (inclusive)\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {TypeError} first argument must be an ndarray having one or more dimensions\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceDimensionFrom( x, 0, 1, false, false );\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 sliceDimensionFrom( x, dim, start, strict, writable ) {\n\tvar args;\n\tvar N;\n\tvar d;\n\n\t// Retrieve array meta data:\n\tN = ndims( x );\n\n\t// Check whether we were provided a zero-dimensional array...\n\tif ( N === 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.', N ) );\n\t}\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, N-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', N, dim ) );\n\t}\n\t// Define a list of slice arguments:\n\targs = filled( null, N );\n\targs[ d ] = new Slice( start, null );\n\n\t// Return a new array view:\n\treturn slice( x, args2multislice( args ), strict, writable );\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceDimensionFrom;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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 shifted view of an input ndarray along a specified dimension.\n*\n* @module @stdlib/ndarray-base-slice-dimension-from\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var sliceDimensionFrom = require( '@stdlib/ndarray-base-slice-dimension-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 = sliceDimensionFrom( x, 0, 1, false, false );\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,EAAkB,QAAS,oCAAqC,EAChEC,EAAQ,QAAS,oBAAqB,EACtCC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAiB,QAAS,sCAAuC,EACjEC,EAAS,QAAS,2BAA4B,EAC9CC,EAAS,QAAS,uBAAwB,EA6C9C,SAASC,EAAoBC,EAAGC,EAAKC,EAAOC,EAAQC,EAAW,CAC9D,IAAIC,EACAC,EACAC,EAMJ,GAHAD,EAAIZ,EAAOM,CAAE,EAGRM,IAAM,EACV,MAAM,IAAI,UAAWR,EAAQ,+GAAgHQ,CAAE,CAAE,EAIlJ,GADAC,EAAIX,EAAgBK,EAAKK,EAAE,CAAE,EACxBC,IAAM,GACV,MAAM,IAAI,WAAYT,EAAQ,6GAA8GQ,EAAGL,CAAI,CAAE,EAGtJ,OAAAI,EAAOR,EAAQ,KAAMS,CAAE,EACvBD,EAAME,CAAE,EAAI,IAAId,EAAOS,EAAO,IAAK,EAG5BP,EAAOK,EAAGR,EAAiBa,CAAK,EAAGF,EAAQC,CAAS,CAC5D,CAKAb,EAAO,QAAUQ,IC7CjB,IAAIS,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "args2multislice", "Slice", "ndims", "slice", "normalizeIndex", "filled", "format", "sliceDimensionFrom", "x", "dim", "start", "strict", "writable", "args", "N", "d", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ffc1f03..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,49 +0,0 @@ - -{{alias}}( x, dim, start, strict, writable ) - Returns a shifted view of an input ndarray along a specified dimension. - - Parameters - ---------- - x: ndarray - Input array. - - dim: integer - Index of dimension to slice. If less than zero, the index is resolved - relative to the last dimension, with the last dimension corresponding to - the value `-1`. - - start: integer - Starting index (inclusive). If less than zero, the corresponding element - along the specified dimension is resolved relative to the last element - along that dimension. For negative integers, the last element - corresponds to the value `-1`. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - writable: boolean - Boolean indicating whether a returned ndarray should be writable. This - parameter only applies to ndarray constructors which support read-only - instances. - - Returns - ------- - out: ndarray - Output array view. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > x.shape - [ 2, 2 ] - > var y = {{alias}}( x, 1, 1, false, false ) - - > 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 9dfeaf3..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,164 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sliceDimensionFrom = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = 0; - - sliceDimensionFrom( empty( 'float64', sh, order ), 1, s, false, false ); // $ExpectType float64ndarray - sliceDimensionFrom( empty( 'float32', sh, order ), 1, s, false, false ); // $ExpectType float32ndarray - sliceDimensionFrom( empty( 'complex128', sh, order ), 1, s, false, false ); // $ExpectType complex128ndarray - sliceDimensionFrom( empty( 'complex64', sh, order ), 1, s, false, false ); // $ExpectType complex64ndarray - sliceDimensionFrom( empty( 'int32', sh, order ), 1, s, false, false ); // $ExpectType int32ndarray - sliceDimensionFrom( empty( 'int16', sh, order ), 1, s, false, false ); // $ExpectType int16ndarray - sliceDimensionFrom( empty( 'int8', sh, order ), 1, s, false, false ); // $ExpectType int8ndarray - sliceDimensionFrom( empty( 'uint32', sh, order ), 1, s, false, false ); // $ExpectType uint32ndarray - sliceDimensionFrom( empty( 'uint16', sh, order ), 1, s, false, false ); // $ExpectType uint16ndarray - sliceDimensionFrom( empty( 'uint8', sh, order ), 1, s, false, false ); // $ExpectType uint8ndarray - sliceDimensionFrom( empty( 'uint8c', sh, order ), 1, s, false, false ); // $ExpectType uint8cndarray - - sliceDimensionFrom( empty( 'float64', sh, order ), 1, s, true, true ); // $ExpectType float64ndarray - sliceDimensionFrom( empty( 'float32', sh, order ), 1, s, true, true ); // $ExpectType float32ndarray - sliceDimensionFrom( empty( 'complex128', sh, order ), 1, s, true, true ); // $ExpectType complex128ndarray - sliceDimensionFrom( empty( 'complex64', sh, order ), 1, s, true, true ); // $ExpectType complex64ndarray - sliceDimensionFrom( empty( 'int32', sh, order ), 1, s, true, true ); // $ExpectType int32ndarray - sliceDimensionFrom( empty( 'int16', sh, order ), 1, s, true, true ); // $ExpectType int16ndarray - sliceDimensionFrom( empty( 'int8', sh, order ), 1, s, true, true ); // $ExpectType int8ndarray - sliceDimensionFrom( empty( 'uint32', sh, order ), 1, s, true, true ); // $ExpectType uint32ndarray - sliceDimensionFrom( empty( 'uint16', sh, order ), 1, s, true, true ); // $ExpectType uint16ndarray - sliceDimensionFrom( empty( 'uint8', sh, order ), 1, s, true, true ); // $ExpectType uint8ndarray - sliceDimensionFrom( empty( 'uint8c', sh, order ), 1, s, true, true ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const s = 0; - - sliceDimensionFrom( '10', 1, s, false, false ); // $ExpectError - sliceDimensionFrom( 10, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( false, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( true, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( null, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( [], 1, s, false, false ); // $ExpectError - sliceDimensionFrom( {}, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( ( x: number ): number => x, 1, s, false, false ); // $ExpectError - - sliceDimensionFrom( '10', 1, s, true, true ); // $ExpectError - sliceDimensionFrom( 10, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( false, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( true, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( null, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( [], 1, s, true, true ); // $ExpectError - sliceDimensionFrom( {}, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( ( x: number ): number => x, 1, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a number... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 1; - - sliceDimensionFrom( x, '5', s, false, false ); // $ExpectError - sliceDimensionFrom( x, false, s, false, false ); // $ExpectError - sliceDimensionFrom( x, true, s, false, false ); // $ExpectError - sliceDimensionFrom( x, null, s, false, false ); // $ExpectError - sliceDimensionFrom( x, undefined, s, false, false ); // $ExpectError - sliceDimensionFrom( x, [ '5' ], s, false, false ); // $ExpectError - sliceDimensionFrom( x, {}, s, false, false ); // $ExpectError - sliceDimensionFrom( x, ( x: number ): number => x, s, false, false ); // $ExpectError - - sliceDimensionFrom( x, '5', s, true, true ); // $ExpectError - sliceDimensionFrom( x, false, s, true, true ); // $ExpectError - sliceDimensionFrom( x, true, s, true, true ); // $ExpectError - sliceDimensionFrom( x, null, s, true, true ); // $ExpectError - sliceDimensionFrom( x, undefined, s, true, true ); // $ExpectError - sliceDimensionFrom( x, [ '5' ], s, true, true ); // $ExpectError - sliceDimensionFrom( x, {}, s, true, true ); // $ExpectError - sliceDimensionFrom( x, ( x: number ): number => x, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceDimensionFrom( x, 1, '5', false, false ); // $ExpectError - sliceDimensionFrom( x, 1, false, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, true, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, null, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, undefined, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, [ '5' ], false, false ); // $ExpectError - sliceDimensionFrom( x, 1, {}, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, ( x: number ): number => x, 1, false, false ); // $ExpectError - - sliceDimensionFrom( x, 1, '5', true, true ); // $ExpectError - sliceDimensionFrom( x, 1, false, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, true, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, null, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, undefined, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, [ '5' ], true, true ); // $ExpectError - sliceDimensionFrom( x, 1, {}, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, ( x: number ): number => x, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x, 1, s, '5', false ); // $ExpectError - sliceDimensionFrom( x, 1, s, 5, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, null, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, undefined, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, [ '5' ], false ); // $ExpectError - sliceDimensionFrom( x, 1, s, {}, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x, 1, s, false, '5' ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, 5 ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, null ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, undefined ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, [ '5' ] ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, {} ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x ); // $ExpectError - sliceDimensionFrom( x, 1 ); // $ExpectError - sliceDimensionFrom( x, 1, s ); // $ExpectError - sliceDimensionFrom( x, 1, s, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index b17162a..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 sliceDimensionFrom = 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 = sliceDimensionFrom( x, 1, 1, false, false ); -// 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 columns of each matrix: -var y2 = sliceDimensionFrom( x, 2, 1, false, false ); -// returns - -var a2 = ndarray2array( y2 ); -console.log( a2 ); -// => [ [ [ 1, 2 ], [ 4, 5 ], [ 7, 8 ] ], [ [ 10, 11 ], [ 13, 14 ], [ 16, 17 ] ], [ [ 19, 20 ], [ 22, 23 ], [ 25, 26 ] ] ] - -// Get the last two matrices: -var y3 = sliceDimensionFrom( x, 0, 1, false, false ); -// returns - -var a3 = ndarray2array( y3 ); -console.log( a3 ); -// => [ [ [ 9, 10, 11 ], [ 12, 13, 14 ], [ 15, 16, 17 ] ], [ [ 18, 19, 20 ], [ 21, 22, 23 ], [ 24, 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 e398649..44225a7 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..1a8cb86 --- /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/slice-base-args2multislice@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-ctor@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndims@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-normalize-index@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-filled@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function m(m,l,o,j,a){var p,h,v;if(0===(h=r(m)))throw new TypeError(n("1lDF7",h));if(-1===(v=i(l,h-1)))throw new RangeError(n("1lDF8",h,l));return(p=d(null,h))[v]=new e(o,null),t(m,s(p),j,a)}export{m as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..275a0ea --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport Slice from '@stdlib/slice-ctor';\nimport ndims from '@stdlib/ndarray-base-ndims';\nimport slice from '@stdlib/ndarray-base-slice';\nimport normalizeIndex from '@stdlib/ndarray-base-normalize-index';\nimport filled from '@stdlib/array-base-filled';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns a shifted view of an input ndarray along a specified dimension.\n*\n* @param {ndarray} x - input array\n* @param {integer} dim - index of dimension to slice\n* @param {integer} start - starting index (inclusive)\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {TypeError} first argument must be an ndarray having one or more dimensions\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\n*\n* @example\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceDimensionFrom( x, 0, 1, false, false );\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 sliceDimensionFrom( x, dim, start, strict, writable ) {\n\tvar args;\n\tvar N;\n\tvar d;\n\n\t// Retrieve array meta data:\n\tN = ndims( x );\n\n\t// Check whether we were provided a zero-dimensional array...\n\tif ( N === 0 ) {\n\t\tthrow new TypeError( format( '1lDF7', N ) );\n\t}\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, N-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( '1lDF8', N, dim ) );\n\t}\n\t// Define a list of slice arguments:\n\targs = filled( null, N );\n\targs[ d ] = new Slice( start, null );\n\n\t// Return a new array view:\n\treturn slice( x, args2multislice( args ), strict, writable );\n}\n\n\n// EXPORTS //\n\nexport default sliceDimensionFrom;\n"],"names":["sliceDimensionFrom","x","dim","start","strict","writable","args","N","d","ndims","TypeError","format","normalizeIndex","RangeError","filled","Slice","slice","args2multislice"],"mappings":";;wpBAyEA,SAASA,EAAoBC,EAAGC,EAAKC,EAAOC,EAAQC,GACnD,IAAIC,EACAC,EACAC,EAMJ,GAAW,KAHXD,EAAIE,EAAOR,IAIV,MAAM,IAAIS,UAAWC,EAAQ,QAASJ,IAIvC,IAAY,KADZC,EAAII,EAAgBV,EAAKK,EAAE,IAE1B,MAAM,IAAIM,WAAYF,EAAQ,QAASJ,EAAGL,IAO3C,OAJAI,EAAOQ,EAAQ,KAAMP,IACfC,GAAM,IAAIO,EAAOZ,EAAO,MAGvBa,EAAOf,EAAGgB,EAAiBX,GAAQF,EAAQC,EACnD"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index b3f97b2..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 shifted view of an input ndarray along a specified dimension. -* -* @module @stdlib/ndarray-base-slice-dimension-from -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var sliceDimensionFrom = require( '@stdlib/ndarray-base-slice-dimension-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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // 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 5dbaaef..0000000 --- a/lib/main.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var Slice = require( '@stdlib/slice-ctor' ); -var ndims = require( '@stdlib/ndarray-base-ndims' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' ); -var filled = require( '@stdlib/array-base-filled' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param {ndarray} x - input array -* @param {integer} dim - index of dimension to slice -* @param {integer} start - starting index (inclusive) -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @param {boolean} writable - boolean indicating whether a returned array should be writable -* @throws {TypeError} first argument must be an ndarray having one or more dimensions -* @throws {RangeError} dimension index exceeds the number of dimensions -* @throws {RangeError} slice 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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -function sliceDimensionFrom( x, dim, start, strict, writable ) { - var args; - var N; - var d; - - // Retrieve array meta data: - N = ndims( x ); - - // Check whether we were provided a zero-dimensional array... - if ( N === 0 ) { - throw new TypeError( format( '1lDF7', N ) ); - } - // Normalize the dimension index: - d = normalizeIndex( dim, N-1 ); - if ( d === -1 ) { - throw new RangeError( format( '1lDF8', N, dim ) ); - } - // Define a list of slice arguments: - args = filled( null, N ); - args[ d ] = new Slice( start, null ); - - // Return a new array view: - return slice( x, args2multislice( args ), strict, writable ); -} - - -// EXPORTS // - -module.exports = sliceDimensionFrom; diff --git a/package.json b/package.json index f7083d8..7879a68 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Return a shifted view of an input ndarray along a specific dimension.", "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,50 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-filled": "^0.2.1", - "@stdlib/ndarray-base-ndims": "^0.2.1", - "@stdlib/ndarray-base-normalize-index": "^0.2.1", - "@stdlib/ndarray-base-slice": "^0.2.1", - "@stdlib/slice-base-args2multislice": "^0.2.1", - "@stdlib/slice-ctor": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/array-typed": "^0.2.1", - "@stdlib/assert-is-ndarray-like": "^0.2.1", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.1", - "@stdlib/ndarray-base-ctor": "^0.2.1", - "@stdlib/ndarray-base-empty": "^0.2.1", - "@stdlib/ndarray-base-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..71c4425 --- /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 28703b5..0000000 --- a/test/test.js +++ /dev/null @@ -1,616 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 ndarray2array = require( '@stdlib/ndarray-to-array' ); -var baseCtor = require( '@stdlib/ndarray-base-ctor' ); -var ctor = require( '@stdlib/ndarray-ctor' ); -var sliceDimensionFrom = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sliceDimensionFrom, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a zero-dimensional array (strict=false)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error' ); - } - t.end(); - - function badValue( x ) { - return function badValue() { - sliceDimensionFrom( x, 0, 0, false, false ); - }; - } -}); - -tape( 'the function throws an error if provided a zero-dimensional array (strict=true)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error' ); - } - t.end(); - - function badValue( x ) { - return function badValue() { - sliceDimensionFrom( x, 0, 0, true, false ); - }; - } -}); - -tape( 'the function throws an error if the dimension index exceeds the number of dimensions (strict=false)', 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 ], 10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - t.throws( badValue( values[ i ], -10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - } - t.end(); - - function badValue( x, dim ) { - return function badValue() { - sliceDimensionFrom( x, dim, 0, false, false ); - }; - } -}); - -tape( 'the function throws an error if the dimension index exceeds the number of dimensions (strict=true)', 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 ], 10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - t.throws( badValue( values[ i ], -10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - } - t.end(); - - function badValue( x, dim ) { - return function badValue() { - sliceDimensionFrom( x, dim, 0, true, false ); - }; - } -}); - -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, - 20, - 20, - 20 - ]; - 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() { - sliceDimensionFrom( x, 0, s, true, false ); - }; - } -}); - -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, - 20, - 20, - 20, - 10 - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceDimensionFrom( values[ i ], 0, start[ i ], false, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), 0, 'returns expected value' ); - t.strictEqual( actual.dtype, values[ i ].dtype, 'returns expected value' ); - } - t.end(); -}); - -tape( 'in non-strict mode, the function returns an empty array when a starting index is the one more than the last index along a dimension', function test( t ) { - var actual; - var values; - var start; - var dim; - 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' } ) - ]; - - dim = [ - 0, - 1, - 0, - 1, - 4 - ]; - - start = [ - 1, - 1, - 1, - 1, - 1 - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceDimensionFrom( values[ i ], dim[ i ], start[ i ], false, false ); // eslint-disable-line max-len - 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 a shifted view of a provided input array (ndims=1)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 2, true, false ); - - 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 = sliceDimensionFrom( x, 0, -4, true, false ); - - 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)', 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 1, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 2, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, -2, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 1, 1, true, false ); - - 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 = sliceDimensionFrom( x, 1, -2, true, false ); - - 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' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=3)', 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 1, true, false ); - - 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 = sliceDimensionFrom( x, 1, 1, true, false ); - - 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 = sliceDimensionFrom( x, 2, 2, true, false ); - - 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 = sliceDimensionFrom( x, 2, -1, true, false ); - - 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' ); - t.end(); -}); - -tape( 'if a provided ndarray has a constructor supporting read-only instances, the function returns a read-only instance', function test( t ) { - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - x = new baseCtor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports returning writable views', function test( t ) { - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - x = new baseCtor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - t.end(); -}); From ee4ecb0e926048ededa61a958f0c2459d4852662 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 07:12:19 +0000 Subject: [PATCH 36/92] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 2b8e198..5dbaaef 100644 --- a/lib/main.js +++ b/lib/main.js @@ -26,7 +26,7 @@ var ndims = require( '@stdlib/ndarray-base-ndims' ); var slice = require( '@stdlib/ndarray-base-slice' ); var normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' ); var filled = require( '@stdlib/array-base-filled' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -81,12 +81,12 @@ function sliceDimensionFrom( x, dim, start, strict, writable ) { // Check whether we were provided a zero-dimensional array... if ( N === 0 ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.', N ) ); + throw new TypeError( format( '1lDF7', N ) ); } // Normalize the dimension index: d = normalizeIndex( dim, N-1 ); if ( d === -1 ) { - throw new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', N, dim ) ); + throw new RangeError( format( '1lDF8', N, dim ) ); } // Define a list of slice arguments: args = filled( null, N ); diff --git a/package.json b/package.json index 4895887..f7083d8 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/ndarray-base-slice": "^0.2.1", "@stdlib/slice-base-args2multislice": "^0.2.1", "@stdlib/slice-ctor": "^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 4e1127218d97c5ef84a48c5621f321993a3a4516 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 12:33:19 +0000 Subject: [PATCH 37/92] Remove files --- index.d.ts | 534 ------ index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5381 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 44225a7..0000000 --- a/index.d.ts +++ /dev/null @@ -1,534 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceDimensionFrom( x: float64ndarray, dim: number, start: number, strict: boolean, writable: boolean ): float64ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceDimensionFrom( x: float32ndarray, dim: number, start: number, strict: boolean, writable: boolean ): float32ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: int32ndarray, dim: number, start: number, strict: boolean, writable: boolean ): int32ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: int16ndarray, dim: number, start: number, strict: boolean, writable: boolean ): int16ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: int8ndarray, dim: number, start: number, strict: boolean, writable: boolean ): int8ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint32ndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint32ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint16ndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint16ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint8ndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint8ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint8cndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint8cndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceDimensionFrom( x: complex128ndarray, dim: number, start: number, strict: boolean, writable: boolean ): complex128ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceDimensionFrom( x: complex64ndarray, dim: number, start: number, strict: boolean, writable: boolean ): complex64ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: genericndarray, dim: number, start: number, strict: boolean, writable: boolean ): genericndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: typedndarray, dim: number, start: number, strict: boolean, writable: boolean ): typedndarray; - - -// EXPORTS // - -export = sliceDimensionFrom; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 1a8cb86..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/slice-base-args2multislice@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-ctor@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndims@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-normalize-index@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-filled@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function m(m,l,o,j,a){var p,h,v;if(0===(h=r(m)))throw new TypeError(n("1lDF7",h));if(-1===(v=i(l,h-1)))throw new RangeError(n("1lDF8",h,l));return(p=d(null,h))[v]=new e(o,null),t(m,s(p),j,a)}export{m as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 275a0ea..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport Slice from '@stdlib/slice-ctor';\nimport ndims from '@stdlib/ndarray-base-ndims';\nimport slice from '@stdlib/ndarray-base-slice';\nimport normalizeIndex from '@stdlib/ndarray-base-normalize-index';\nimport filled from '@stdlib/array-base-filled';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns a shifted view of an input ndarray along a specified dimension.\n*\n* @param {ndarray} x - input array\n* @param {integer} dim - index of dimension to slice\n* @param {integer} start - starting index (inclusive)\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {TypeError} first argument must be an ndarray having one or more dimensions\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\n*\n* @example\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceDimensionFrom( x, 0, 1, false, false );\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 sliceDimensionFrom( x, dim, start, strict, writable ) {\n\tvar args;\n\tvar N;\n\tvar d;\n\n\t// Retrieve array meta data:\n\tN = ndims( x );\n\n\t// Check whether we were provided a zero-dimensional array...\n\tif ( N === 0 ) {\n\t\tthrow new TypeError( format( '1lDF7', N ) );\n\t}\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, N-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( '1lDF8', N, dim ) );\n\t}\n\t// Define a list of slice arguments:\n\targs = filled( null, N );\n\targs[ d ] = new Slice( start, null );\n\n\t// Return a new array view:\n\treturn slice( x, args2multislice( args ), strict, writable );\n}\n\n\n// EXPORTS //\n\nexport default sliceDimensionFrom;\n"],"names":["sliceDimensionFrom","x","dim","start","strict","writable","args","N","d","ndims","TypeError","format","normalizeIndex","RangeError","filled","Slice","slice","args2multislice"],"mappings":";;wpBAyEA,SAASA,EAAoBC,EAAGC,EAAKC,EAAOC,EAAQC,GACnD,IAAIC,EACAC,EACAC,EAMJ,GAAW,KAHXD,EAAIE,EAAOR,IAIV,MAAM,IAAIS,UAAWC,EAAQ,QAASJ,IAIvC,IAAY,KADZC,EAAII,EAAgBV,EAAKK,EAAE,IAE1B,MAAM,IAAIM,WAAYF,EAAQ,QAASJ,EAAGL,IAO3C,OAJAI,EAAOQ,EAAQ,KAAMP,IACfC,GAAM,IAAIO,EAAOZ,EAAO,MAGvBa,EAAOf,EAAGgB,EAAiBX,GAAQF,EAAQC,EACnD"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 71c4425..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From ccac0408c6d8dc41dfd681561a25b6978841162d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 12:33:38 +0000 Subject: [PATCH 38/92] 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 | 45 +- SECURITY.md | 5 - benchmark/benchmark.js | 681 --- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 49 - docs/types/test.ts | 164 - 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 | 102 - package.json | 71 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 616 --- 43 files changed, 4868 insertions(+), 5102 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 6c97217..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-04-01T05:00:29.530Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 05d1840..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-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 ced95ae..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-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 60a2bb4..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: '38 14 * * 5' - - # 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 + + ```
@@ -202,7 +193,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]. diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 8a6b7a2..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,681 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 sliceDimensionFrom = require( './../lib' ); - - -// MAIN // - -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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2 ], { 'dtype': 'float64' } ), - empty( [ 2 ], { 'dtype': 'float32' } ), - empty( [ 2 ], { 'dtype': 'int32' } ), - empty( [ 2 ], { 'dtype': 'complex128' } ), - empty( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== '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 9543fcd..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-from" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-from -[production-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-slice-dimension-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 2ab577a..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import sliceDimensionFrom from '../docs/types/index'; -export = sliceDimensionFrom; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 0f7ac9a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var l=function(i,r){return function(){return r||i((r={exports:{}}).exports,r),r.exports}};var o=l(function(p,u){ -var v=require('@stdlib/slice-base-args2multislice/dist'),c=require('@stdlib/slice-ctor/dist'),f=require('@stdlib/ndarray-base-ndims/dist'),q=require('@stdlib/ndarray-base-slice/dist'),g=require('@stdlib/ndarray-base-normalize-index/dist'),w=require('@stdlib/array-base-filled/dist'),s=require('@stdlib/error-tools-fmtprodmsg/dist');function b(i,r,m,t,d){var n,e,a;if(e=f(i),e===0)throw new TypeError(s('1lDF7',e));if(a=g(r,e-1),a===-1)throw new RangeError(s('1lDF8',e,r));return n=w(null,e),n[a]=new c(m,null),q(i,v(n),t,d)}u.exports=b -});var h=o();module.exports=h; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index a75b3e0..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar args2multislice = require( '@stdlib/slice-base-args2multislice' );\nvar Slice = require( '@stdlib/slice-ctor' );\nvar ndims = require( '@stdlib/ndarray-base-ndims' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' );\nvar filled = require( '@stdlib/array-base-filled' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns a shifted view of an input ndarray along a specified dimension.\n*\n* @param {ndarray} x - input array\n* @param {integer} dim - index of dimension to slice\n* @param {integer} start - starting index (inclusive)\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {TypeError} first argument must be an ndarray having one or more dimensions\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceDimensionFrom( x, 0, 1, false, false );\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 sliceDimensionFrom( x, dim, start, strict, writable ) {\n\tvar args;\n\tvar N;\n\tvar d;\n\n\t// Retrieve array meta data:\n\tN = ndims( x );\n\n\t// Check whether we were provided a zero-dimensional array...\n\tif ( N === 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.', N ) );\n\t}\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, N-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', N, dim ) );\n\t}\n\t// Define a list of slice arguments:\n\targs = filled( null, N );\n\targs[ d ] = new Slice( start, null );\n\n\t// Return a new array view:\n\treturn slice( x, args2multislice( args ), strict, writable );\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceDimensionFrom;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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 shifted view of an input ndarray along a specified dimension.\n*\n* @module @stdlib/ndarray-base-slice-dimension-from\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var sliceDimensionFrom = require( '@stdlib/ndarray-base-slice-dimension-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 = sliceDimensionFrom( x, 0, 1, false, false );\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,EAAkB,QAAS,oCAAqC,EAChEC,EAAQ,QAAS,oBAAqB,EACtCC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAiB,QAAS,sCAAuC,EACjEC,EAAS,QAAS,2BAA4B,EAC9CC,EAAS,QAAS,uBAAwB,EA6C9C,SAASC,EAAoBC,EAAGC,EAAKC,EAAOC,EAAQC,EAAW,CAC9D,IAAIC,EACAC,EACAC,EAMJ,GAHAD,EAAIZ,EAAOM,CAAE,EAGRM,IAAM,EACV,MAAM,IAAI,UAAWR,EAAQ,+GAAgHQ,CAAE,CAAE,EAIlJ,GADAC,EAAIX,EAAgBK,EAAKK,EAAE,CAAE,EACxBC,IAAM,GACV,MAAM,IAAI,WAAYT,EAAQ,6GAA8GQ,EAAGL,CAAI,CAAE,EAGtJ,OAAAI,EAAOR,EAAQ,KAAMS,CAAE,EACvBD,EAAME,CAAE,EAAI,IAAId,EAAOS,EAAO,IAAK,EAG5BP,EAAOK,EAAGR,EAAiBa,CAAK,EAAGF,EAAQC,CAAS,CAC5D,CAKAb,EAAO,QAAUQ,IC7CjB,IAAIS,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "args2multislice", "Slice", "ndims", "slice", "normalizeIndex", "filled", "format", "sliceDimensionFrom", "x", "dim", "start", "strict", "writable", "args", "N", "d", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ffc1f03..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,49 +0,0 @@ - -{{alias}}( x, dim, start, strict, writable ) - Returns a shifted view of an input ndarray along a specified dimension. - - Parameters - ---------- - x: ndarray - Input array. - - dim: integer - Index of dimension to slice. If less than zero, the index is resolved - relative to the last dimension, with the last dimension corresponding to - the value `-1`. - - start: integer - Starting index (inclusive). If less than zero, the corresponding element - along the specified dimension is resolved relative to the last element - along that dimension. For negative integers, the last element - corresponds to the value `-1`. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - writable: boolean - Boolean indicating whether a returned ndarray should be writable. This - parameter only applies to ndarray constructors which support read-only - instances. - - Returns - ------- - out: ndarray - Output array view. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > x.shape - [ 2, 2 ] - > var y = {{alias}}( x, 1, 1, false, false ) - - > 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 9dfeaf3..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,164 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sliceDimensionFrom = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = 0; - - sliceDimensionFrom( empty( 'float64', sh, order ), 1, s, false, false ); // $ExpectType float64ndarray - sliceDimensionFrom( empty( 'float32', sh, order ), 1, s, false, false ); // $ExpectType float32ndarray - sliceDimensionFrom( empty( 'complex128', sh, order ), 1, s, false, false ); // $ExpectType complex128ndarray - sliceDimensionFrom( empty( 'complex64', sh, order ), 1, s, false, false ); // $ExpectType complex64ndarray - sliceDimensionFrom( empty( 'int32', sh, order ), 1, s, false, false ); // $ExpectType int32ndarray - sliceDimensionFrom( empty( 'int16', sh, order ), 1, s, false, false ); // $ExpectType int16ndarray - sliceDimensionFrom( empty( 'int8', sh, order ), 1, s, false, false ); // $ExpectType int8ndarray - sliceDimensionFrom( empty( 'uint32', sh, order ), 1, s, false, false ); // $ExpectType uint32ndarray - sliceDimensionFrom( empty( 'uint16', sh, order ), 1, s, false, false ); // $ExpectType uint16ndarray - sliceDimensionFrom( empty( 'uint8', sh, order ), 1, s, false, false ); // $ExpectType uint8ndarray - sliceDimensionFrom( empty( 'uint8c', sh, order ), 1, s, false, false ); // $ExpectType uint8cndarray - - sliceDimensionFrom( empty( 'float64', sh, order ), 1, s, true, true ); // $ExpectType float64ndarray - sliceDimensionFrom( empty( 'float32', sh, order ), 1, s, true, true ); // $ExpectType float32ndarray - sliceDimensionFrom( empty( 'complex128', sh, order ), 1, s, true, true ); // $ExpectType complex128ndarray - sliceDimensionFrom( empty( 'complex64', sh, order ), 1, s, true, true ); // $ExpectType complex64ndarray - sliceDimensionFrom( empty( 'int32', sh, order ), 1, s, true, true ); // $ExpectType int32ndarray - sliceDimensionFrom( empty( 'int16', sh, order ), 1, s, true, true ); // $ExpectType int16ndarray - sliceDimensionFrom( empty( 'int8', sh, order ), 1, s, true, true ); // $ExpectType int8ndarray - sliceDimensionFrom( empty( 'uint32', sh, order ), 1, s, true, true ); // $ExpectType uint32ndarray - sliceDimensionFrom( empty( 'uint16', sh, order ), 1, s, true, true ); // $ExpectType uint16ndarray - sliceDimensionFrom( empty( 'uint8', sh, order ), 1, s, true, true ); // $ExpectType uint8ndarray - sliceDimensionFrom( empty( 'uint8c', sh, order ), 1, s, true, true ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const s = 0; - - sliceDimensionFrom( '10', 1, s, false, false ); // $ExpectError - sliceDimensionFrom( 10, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( false, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( true, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( null, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( [], 1, s, false, false ); // $ExpectError - sliceDimensionFrom( {}, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( ( x: number ): number => x, 1, s, false, false ); // $ExpectError - - sliceDimensionFrom( '10', 1, s, true, true ); // $ExpectError - sliceDimensionFrom( 10, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( false, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( true, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( null, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( [], 1, s, true, true ); // $ExpectError - sliceDimensionFrom( {}, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( ( x: number ): number => x, 1, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a number... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 1; - - sliceDimensionFrom( x, '5', s, false, false ); // $ExpectError - sliceDimensionFrom( x, false, s, false, false ); // $ExpectError - sliceDimensionFrom( x, true, s, false, false ); // $ExpectError - sliceDimensionFrom( x, null, s, false, false ); // $ExpectError - sliceDimensionFrom( x, undefined, s, false, false ); // $ExpectError - sliceDimensionFrom( x, [ '5' ], s, false, false ); // $ExpectError - sliceDimensionFrom( x, {}, s, false, false ); // $ExpectError - sliceDimensionFrom( x, ( x: number ): number => x, s, false, false ); // $ExpectError - - sliceDimensionFrom( x, '5', s, true, true ); // $ExpectError - sliceDimensionFrom( x, false, s, true, true ); // $ExpectError - sliceDimensionFrom( x, true, s, true, true ); // $ExpectError - sliceDimensionFrom( x, null, s, true, true ); // $ExpectError - sliceDimensionFrom( x, undefined, s, true, true ); // $ExpectError - sliceDimensionFrom( x, [ '5' ], s, true, true ); // $ExpectError - sliceDimensionFrom( x, {}, s, true, true ); // $ExpectError - sliceDimensionFrom( x, ( x: number ): number => x, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceDimensionFrom( x, 1, '5', false, false ); // $ExpectError - sliceDimensionFrom( x, 1, false, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, true, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, null, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, undefined, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, [ '5' ], false, false ); // $ExpectError - sliceDimensionFrom( x, 1, {}, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, ( x: number ): number => x, 1, false, false ); // $ExpectError - - sliceDimensionFrom( x, 1, '5', true, true ); // $ExpectError - sliceDimensionFrom( x, 1, false, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, true, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, null, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, undefined, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, [ '5' ], true, true ); // $ExpectError - sliceDimensionFrom( x, 1, {}, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, ( x: number ): number => x, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x, 1, s, '5', false ); // $ExpectError - sliceDimensionFrom( x, 1, s, 5, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, null, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, undefined, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, [ '5' ], false ); // $ExpectError - sliceDimensionFrom( x, 1, s, {}, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x, 1, s, false, '5' ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, 5 ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, null ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, undefined ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, [ '5' ] ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, {} ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x ); // $ExpectError - sliceDimensionFrom( x, 1 ); // $ExpectError - sliceDimensionFrom( x, 1, s ); // $ExpectError - sliceDimensionFrom( x, 1, s, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index b17162a..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 sliceDimensionFrom = 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 = sliceDimensionFrom( x, 1, 1, false, false ); -// 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 columns of each matrix: -var y2 = sliceDimensionFrom( x, 2, 1, false, false ); -// returns - -var a2 = ndarray2array( y2 ); -console.log( a2 ); -// => [ [ [ 1, 2 ], [ 4, 5 ], [ 7, 8 ] ], [ [ 10, 11 ], [ 13, 14 ], [ 16, 17 ] ], [ [ 19, 20 ], [ 22, 23 ], [ 25, 26 ] ] ] - -// Get the last two matrices: -var y3 = sliceDimensionFrom( x, 0, 1, false, false ); -// returns - -var a3 = ndarray2array( y3 ); -console.log( a3 ); -// => [ [ [ 9, 10, 11 ], [ 12, 13, 14 ], [ 15, 16, 17 ] ], [ [ 18, 19, 20 ], [ 21, 22, 23 ], [ 24, 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 e398649..44225a7 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..1a8cb86 --- /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/slice-base-args2multislice@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-ctor@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndims@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-normalize-index@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-filled@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function m(m,l,o,j,a){var p,h,v;if(0===(h=r(m)))throw new TypeError(n("1lDF7",h));if(-1===(v=i(l,h-1)))throw new RangeError(n("1lDF8",h,l));return(p=d(null,h))[v]=new e(o,null),t(m,s(p),j,a)}export{m as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..275a0ea --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport Slice from '@stdlib/slice-ctor';\nimport ndims from '@stdlib/ndarray-base-ndims';\nimport slice from '@stdlib/ndarray-base-slice';\nimport normalizeIndex from '@stdlib/ndarray-base-normalize-index';\nimport filled from '@stdlib/array-base-filled';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns a shifted view of an input ndarray along a specified dimension.\n*\n* @param {ndarray} x - input array\n* @param {integer} dim - index of dimension to slice\n* @param {integer} start - starting index (inclusive)\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {TypeError} first argument must be an ndarray having one or more dimensions\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\n*\n* @example\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceDimensionFrom( x, 0, 1, false, false );\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 sliceDimensionFrom( x, dim, start, strict, writable ) {\n\tvar args;\n\tvar N;\n\tvar d;\n\n\t// Retrieve array meta data:\n\tN = ndims( x );\n\n\t// Check whether we were provided a zero-dimensional array...\n\tif ( N === 0 ) {\n\t\tthrow new TypeError( format( '1lDF7', N ) );\n\t}\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, N-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( '1lDF8', N, dim ) );\n\t}\n\t// Define a list of slice arguments:\n\targs = filled( null, N );\n\targs[ d ] = new Slice( start, null );\n\n\t// Return a new array view:\n\treturn slice( x, args2multislice( args ), strict, writable );\n}\n\n\n// EXPORTS //\n\nexport default sliceDimensionFrom;\n"],"names":["sliceDimensionFrom","x","dim","start","strict","writable","args","N","d","ndims","TypeError","format","normalizeIndex","RangeError","filled","Slice","slice","args2multislice"],"mappings":";;wpBAyEA,SAASA,EAAoBC,EAAGC,EAAKC,EAAOC,EAAQC,GACnD,IAAIC,EACAC,EACAC,EAMJ,GAAW,KAHXD,EAAIE,EAAOR,IAIV,MAAM,IAAIS,UAAWC,EAAQ,QAASJ,IAIvC,IAAY,KADZC,EAAII,EAAgBV,EAAKK,EAAE,IAE1B,MAAM,IAAIM,WAAYF,EAAQ,QAASJ,EAAGL,IAO3C,OAJAI,EAAOQ,EAAQ,KAAMP,IACfC,GAAM,IAAIO,EAAOZ,EAAO,MAGvBa,EAAOf,EAAGgB,EAAiBX,GAAQF,EAAQC,EACnD"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index b3f97b2..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 shifted view of an input ndarray along a specified dimension. -* -* @module @stdlib/ndarray-base-slice-dimension-from -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var sliceDimensionFrom = require( '@stdlib/ndarray-base-slice-dimension-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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // 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 5dbaaef..0000000 --- a/lib/main.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var Slice = require( '@stdlib/slice-ctor' ); -var ndims = require( '@stdlib/ndarray-base-ndims' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' ); -var filled = require( '@stdlib/array-base-filled' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param {ndarray} x - input array -* @param {integer} dim - index of dimension to slice -* @param {integer} start - starting index (inclusive) -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @param {boolean} writable - boolean indicating whether a returned array should be writable -* @throws {TypeError} first argument must be an ndarray having one or more dimensions -* @throws {RangeError} dimension index exceeds the number of dimensions -* @throws {RangeError} slice 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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -function sliceDimensionFrom( x, dim, start, strict, writable ) { - var args; - var N; - var d; - - // Retrieve array meta data: - N = ndims( x ); - - // Check whether we were provided a zero-dimensional array... - if ( N === 0 ) { - throw new TypeError( format( '1lDF7', N ) ); - } - // Normalize the dimension index: - d = normalizeIndex( dim, N-1 ); - if ( d === -1 ) { - throw new RangeError( format( '1lDF8', N, dim ) ); - } - // Define a list of slice arguments: - args = filled( null, N ); - args[ d ] = new Slice( start, null ); - - // Return a new array view: - return slice( x, args2multislice( args ), strict, writable ); -} - - -// EXPORTS // - -module.exports = sliceDimensionFrom; diff --git a/package.json b/package.json index f7083d8..7879a68 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Return a shifted view of an input ndarray along a specific dimension.", "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,50 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-filled": "^0.2.1", - "@stdlib/ndarray-base-ndims": "^0.2.1", - "@stdlib/ndarray-base-normalize-index": "^0.2.1", - "@stdlib/ndarray-base-slice": "^0.2.1", - "@stdlib/slice-base-args2multislice": "^0.2.1", - "@stdlib/slice-ctor": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/array-typed": "^0.2.1", - "@stdlib/assert-is-ndarray-like": "^0.2.1", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.1", - "@stdlib/ndarray-base-ctor": "^0.2.1", - "@stdlib/ndarray-base-empty": "^0.2.1", - "@stdlib/ndarray-base-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..71c4425 --- /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 28703b5..0000000 --- a/test/test.js +++ /dev/null @@ -1,616 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 ndarray2array = require( '@stdlib/ndarray-to-array' ); -var baseCtor = require( '@stdlib/ndarray-base-ctor' ); -var ctor = require( '@stdlib/ndarray-ctor' ); -var sliceDimensionFrom = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sliceDimensionFrom, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a zero-dimensional array (strict=false)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error' ); - } - t.end(); - - function badValue( x ) { - return function badValue() { - sliceDimensionFrom( x, 0, 0, false, false ); - }; - } -}); - -tape( 'the function throws an error if provided a zero-dimensional array (strict=true)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error' ); - } - t.end(); - - function badValue( x ) { - return function badValue() { - sliceDimensionFrom( x, 0, 0, true, false ); - }; - } -}); - -tape( 'the function throws an error if the dimension index exceeds the number of dimensions (strict=false)', 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 ], 10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - t.throws( badValue( values[ i ], -10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - } - t.end(); - - function badValue( x, dim ) { - return function badValue() { - sliceDimensionFrom( x, dim, 0, false, false ); - }; - } -}); - -tape( 'the function throws an error if the dimension index exceeds the number of dimensions (strict=true)', 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 ], 10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - t.throws( badValue( values[ i ], -10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - } - t.end(); - - function badValue( x, dim ) { - return function badValue() { - sliceDimensionFrom( x, dim, 0, true, false ); - }; - } -}); - -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, - 20, - 20, - 20 - ]; - 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() { - sliceDimensionFrom( x, 0, s, true, false ); - }; - } -}); - -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, - 20, - 20, - 20, - 10 - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceDimensionFrom( values[ i ], 0, start[ i ], false, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), 0, 'returns expected value' ); - t.strictEqual( actual.dtype, values[ i ].dtype, 'returns expected value' ); - } - t.end(); -}); - -tape( 'in non-strict mode, the function returns an empty array when a starting index is the one more than the last index along a dimension', function test( t ) { - var actual; - var values; - var start; - var dim; - 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' } ) - ]; - - dim = [ - 0, - 1, - 0, - 1, - 4 - ]; - - start = [ - 1, - 1, - 1, - 1, - 1 - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceDimensionFrom( values[ i ], dim[ i ], start[ i ], false, false ); // eslint-disable-line max-len - 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 a shifted view of a provided input array (ndims=1)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 2, true, false ); - - 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 = sliceDimensionFrom( x, 0, -4, true, false ); - - 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)', 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 1, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 2, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, -2, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 1, 1, true, false ); - - 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 = sliceDimensionFrom( x, 1, -2, true, false ); - - 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' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=3)', 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 1, true, false ); - - 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 = sliceDimensionFrom( x, 1, 1, true, false ); - - 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 = sliceDimensionFrom( x, 2, 2, true, false ); - - 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 = sliceDimensionFrom( x, 2, -1, true, false ); - - 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' ); - t.end(); -}); - -tape( 'if a provided ndarray has a constructor supporting read-only instances, the function returns a read-only instance', function test( t ) { - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - x = new baseCtor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports returning writable views', function test( t ) { - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - x = new baseCtor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - t.end(); -}); From 1aa99ad718d91e6254dc6a9840e89e61506f24ef Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 03:29:36 +0000 Subject: [PATCH 39/92] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 2b8e198..5dbaaef 100644 --- a/lib/main.js +++ b/lib/main.js @@ -26,7 +26,7 @@ var ndims = require( '@stdlib/ndarray-base-ndims' ); var slice = require( '@stdlib/ndarray-base-slice' ); var normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' ); var filled = require( '@stdlib/array-base-filled' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -81,12 +81,12 @@ function sliceDimensionFrom( x, dim, start, strict, writable ) { // Check whether we were provided a zero-dimensional array... if ( N === 0 ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.', N ) ); + throw new TypeError( format( '1lDF7', N ) ); } // Normalize the dimension index: d = normalizeIndex( dim, N-1 ); if ( d === -1 ) { - throw new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', N, dim ) ); + throw new RangeError( format( '1lDF8', N, dim ) ); } // Define a list of slice arguments: args = filled( null, N ); diff --git a/package.json b/package.json index 4895887..f7083d8 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/ndarray-base-slice": "^0.2.1", "@stdlib/slice-base-args2multislice": "^0.2.1", "@stdlib/slice-ctor": "^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 dff5516703214437ff94f7fe920e9728350bacfd Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 08:54:03 +0000 Subject: [PATCH 40/92] Remove files --- index.d.ts | 534 ------ index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5381 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 44225a7..0000000 --- a/index.d.ts +++ /dev/null @@ -1,534 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceDimensionFrom( x: float64ndarray, dim: number, start: number, strict: boolean, writable: boolean ): float64ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceDimensionFrom( x: float32ndarray, dim: number, start: number, strict: boolean, writable: boolean ): float32ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: int32ndarray, dim: number, start: number, strict: boolean, writable: boolean ): int32ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: int16ndarray, dim: number, start: number, strict: boolean, writable: boolean ): int16ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: int8ndarray, dim: number, start: number, strict: boolean, writable: boolean ): int8ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint32ndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint32ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint16ndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint16ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint8ndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint8ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint8cndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint8cndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceDimensionFrom( x: complex128ndarray, dim: number, start: number, strict: boolean, writable: boolean ): complex128ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceDimensionFrom( x: complex64ndarray, dim: number, start: number, strict: boolean, writable: boolean ): complex64ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: genericndarray, dim: number, start: number, strict: boolean, writable: boolean ): genericndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: typedndarray, dim: number, start: number, strict: boolean, writable: boolean ): typedndarray; - - -// EXPORTS // - -export = sliceDimensionFrom; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 1a8cb86..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/slice-base-args2multislice@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-ctor@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndims@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-normalize-index@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-filled@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function m(m,l,o,j,a){var p,h,v;if(0===(h=r(m)))throw new TypeError(n("1lDF7",h));if(-1===(v=i(l,h-1)))throw new RangeError(n("1lDF8",h,l));return(p=d(null,h))[v]=new e(o,null),t(m,s(p),j,a)}export{m as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 275a0ea..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport Slice from '@stdlib/slice-ctor';\nimport ndims from '@stdlib/ndarray-base-ndims';\nimport slice from '@stdlib/ndarray-base-slice';\nimport normalizeIndex from '@stdlib/ndarray-base-normalize-index';\nimport filled from '@stdlib/array-base-filled';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns a shifted view of an input ndarray along a specified dimension.\n*\n* @param {ndarray} x - input array\n* @param {integer} dim - index of dimension to slice\n* @param {integer} start - starting index (inclusive)\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {TypeError} first argument must be an ndarray having one or more dimensions\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\n*\n* @example\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceDimensionFrom( x, 0, 1, false, false );\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 sliceDimensionFrom( x, dim, start, strict, writable ) {\n\tvar args;\n\tvar N;\n\tvar d;\n\n\t// Retrieve array meta data:\n\tN = ndims( x );\n\n\t// Check whether we were provided a zero-dimensional array...\n\tif ( N === 0 ) {\n\t\tthrow new TypeError( format( '1lDF7', N ) );\n\t}\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, N-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( '1lDF8', N, dim ) );\n\t}\n\t// Define a list of slice arguments:\n\targs = filled( null, N );\n\targs[ d ] = new Slice( start, null );\n\n\t// Return a new array view:\n\treturn slice( x, args2multislice( args ), strict, writable );\n}\n\n\n// EXPORTS //\n\nexport default sliceDimensionFrom;\n"],"names":["sliceDimensionFrom","x","dim","start","strict","writable","args","N","d","ndims","TypeError","format","normalizeIndex","RangeError","filled","Slice","slice","args2multislice"],"mappings":";;wpBAyEA,SAASA,EAAoBC,EAAGC,EAAKC,EAAOC,EAAQC,GACnD,IAAIC,EACAC,EACAC,EAMJ,GAAW,KAHXD,EAAIE,EAAOR,IAIV,MAAM,IAAIS,UAAWC,EAAQ,QAASJ,IAIvC,IAAY,KADZC,EAAII,EAAgBV,EAAKK,EAAE,IAE1B,MAAM,IAAIM,WAAYF,EAAQ,QAASJ,EAAGL,IAO3C,OAJAI,EAAOQ,EAAQ,KAAMP,IACfC,GAAM,IAAIO,EAAOZ,EAAO,MAGvBa,EAAOf,EAAGgB,EAAiBX,GAAQF,EAAQC,EACnD"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 71c4425..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From d54787aa8247692ed8e70f4a2a40626198b4b857 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 08:54:28 +0000 Subject: [PATCH 41/92] 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 | 45 +- SECURITY.md | 5 - benchmark/benchmark.js | 681 --- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 49 - docs/types/test.ts | 164 - 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 | 102 - package.json | 71 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 616 --- 42 files changed, 4868 insertions(+), 5103 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 05d1840..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-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 ced95ae..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-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 60a2bb4..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: '38 14 * * 5' - - # 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 + + ```
@@ -202,7 +193,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]. diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 8a6b7a2..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,681 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 sliceDimensionFrom = require( './../lib' ); - - -// MAIN // - -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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2 ], { 'dtype': 'float64' } ), - empty( [ 2 ], { 'dtype': 'float32' } ), - empty( [ 2 ], { 'dtype': 'int32' } ), - empty( [ 2 ], { 'dtype': 'complex128' } ), - empty( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== '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 9543fcd..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-from" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-from -[production-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-slice-dimension-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 2ab577a..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import sliceDimensionFrom from '../docs/types/index'; -export = sliceDimensionFrom; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 0f7ac9a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var l=function(i,r){return function(){return r||i((r={exports:{}}).exports,r),r.exports}};var o=l(function(p,u){ -var v=require('@stdlib/slice-base-args2multislice/dist'),c=require('@stdlib/slice-ctor/dist'),f=require('@stdlib/ndarray-base-ndims/dist'),q=require('@stdlib/ndarray-base-slice/dist'),g=require('@stdlib/ndarray-base-normalize-index/dist'),w=require('@stdlib/array-base-filled/dist'),s=require('@stdlib/error-tools-fmtprodmsg/dist');function b(i,r,m,t,d){var n,e,a;if(e=f(i),e===0)throw new TypeError(s('1lDF7',e));if(a=g(r,e-1),a===-1)throw new RangeError(s('1lDF8',e,r));return n=w(null,e),n[a]=new c(m,null),q(i,v(n),t,d)}u.exports=b -});var h=o();module.exports=h; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index a75b3e0..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar args2multislice = require( '@stdlib/slice-base-args2multislice' );\nvar Slice = require( '@stdlib/slice-ctor' );\nvar ndims = require( '@stdlib/ndarray-base-ndims' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' );\nvar filled = require( '@stdlib/array-base-filled' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns a shifted view of an input ndarray along a specified dimension.\n*\n* @param {ndarray} x - input array\n* @param {integer} dim - index of dimension to slice\n* @param {integer} start - starting index (inclusive)\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {TypeError} first argument must be an ndarray having one or more dimensions\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceDimensionFrom( x, 0, 1, false, false );\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 sliceDimensionFrom( x, dim, start, strict, writable ) {\n\tvar args;\n\tvar N;\n\tvar d;\n\n\t// Retrieve array meta data:\n\tN = ndims( x );\n\n\t// Check whether we were provided a zero-dimensional array...\n\tif ( N === 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.', N ) );\n\t}\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, N-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', N, dim ) );\n\t}\n\t// Define a list of slice arguments:\n\targs = filled( null, N );\n\targs[ d ] = new Slice( start, null );\n\n\t// Return a new array view:\n\treturn slice( x, args2multislice( args ), strict, writable );\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceDimensionFrom;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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 shifted view of an input ndarray along a specified dimension.\n*\n* @module @stdlib/ndarray-base-slice-dimension-from\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var sliceDimensionFrom = require( '@stdlib/ndarray-base-slice-dimension-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 = sliceDimensionFrom( x, 0, 1, false, false );\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,EAAkB,QAAS,oCAAqC,EAChEC,EAAQ,QAAS,oBAAqB,EACtCC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAiB,QAAS,sCAAuC,EACjEC,EAAS,QAAS,2BAA4B,EAC9CC,EAAS,QAAS,uBAAwB,EA6C9C,SAASC,EAAoBC,EAAGC,EAAKC,EAAOC,EAAQC,EAAW,CAC9D,IAAIC,EACAC,EACAC,EAMJ,GAHAD,EAAIZ,EAAOM,CAAE,EAGRM,IAAM,EACV,MAAM,IAAI,UAAWR,EAAQ,+GAAgHQ,CAAE,CAAE,EAIlJ,GADAC,EAAIX,EAAgBK,EAAKK,EAAE,CAAE,EACxBC,IAAM,GACV,MAAM,IAAI,WAAYT,EAAQ,6GAA8GQ,EAAGL,CAAI,CAAE,EAGtJ,OAAAI,EAAOR,EAAQ,KAAMS,CAAE,EACvBD,EAAME,CAAE,EAAI,IAAId,EAAOS,EAAO,IAAK,EAG5BP,EAAOK,EAAGR,EAAiBa,CAAK,EAAGF,EAAQC,CAAS,CAC5D,CAKAb,EAAO,QAAUQ,IC7CjB,IAAIS,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "args2multislice", "Slice", "ndims", "slice", "normalizeIndex", "filled", "format", "sliceDimensionFrom", "x", "dim", "start", "strict", "writable", "args", "N", "d", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ffc1f03..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,49 +0,0 @@ - -{{alias}}( x, dim, start, strict, writable ) - Returns a shifted view of an input ndarray along a specified dimension. - - Parameters - ---------- - x: ndarray - Input array. - - dim: integer - Index of dimension to slice. If less than zero, the index is resolved - relative to the last dimension, with the last dimension corresponding to - the value `-1`. - - start: integer - Starting index (inclusive). If less than zero, the corresponding element - along the specified dimension is resolved relative to the last element - along that dimension. For negative integers, the last element - corresponds to the value `-1`. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - writable: boolean - Boolean indicating whether a returned ndarray should be writable. This - parameter only applies to ndarray constructors which support read-only - instances. - - Returns - ------- - out: ndarray - Output array view. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > x.shape - [ 2, 2 ] - > var y = {{alias}}( x, 1, 1, false, false ) - - > 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 9dfeaf3..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,164 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sliceDimensionFrom = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = 0; - - sliceDimensionFrom( empty( 'float64', sh, order ), 1, s, false, false ); // $ExpectType float64ndarray - sliceDimensionFrom( empty( 'float32', sh, order ), 1, s, false, false ); // $ExpectType float32ndarray - sliceDimensionFrom( empty( 'complex128', sh, order ), 1, s, false, false ); // $ExpectType complex128ndarray - sliceDimensionFrom( empty( 'complex64', sh, order ), 1, s, false, false ); // $ExpectType complex64ndarray - sliceDimensionFrom( empty( 'int32', sh, order ), 1, s, false, false ); // $ExpectType int32ndarray - sliceDimensionFrom( empty( 'int16', sh, order ), 1, s, false, false ); // $ExpectType int16ndarray - sliceDimensionFrom( empty( 'int8', sh, order ), 1, s, false, false ); // $ExpectType int8ndarray - sliceDimensionFrom( empty( 'uint32', sh, order ), 1, s, false, false ); // $ExpectType uint32ndarray - sliceDimensionFrom( empty( 'uint16', sh, order ), 1, s, false, false ); // $ExpectType uint16ndarray - sliceDimensionFrom( empty( 'uint8', sh, order ), 1, s, false, false ); // $ExpectType uint8ndarray - sliceDimensionFrom( empty( 'uint8c', sh, order ), 1, s, false, false ); // $ExpectType uint8cndarray - - sliceDimensionFrom( empty( 'float64', sh, order ), 1, s, true, true ); // $ExpectType float64ndarray - sliceDimensionFrom( empty( 'float32', sh, order ), 1, s, true, true ); // $ExpectType float32ndarray - sliceDimensionFrom( empty( 'complex128', sh, order ), 1, s, true, true ); // $ExpectType complex128ndarray - sliceDimensionFrom( empty( 'complex64', sh, order ), 1, s, true, true ); // $ExpectType complex64ndarray - sliceDimensionFrom( empty( 'int32', sh, order ), 1, s, true, true ); // $ExpectType int32ndarray - sliceDimensionFrom( empty( 'int16', sh, order ), 1, s, true, true ); // $ExpectType int16ndarray - sliceDimensionFrom( empty( 'int8', sh, order ), 1, s, true, true ); // $ExpectType int8ndarray - sliceDimensionFrom( empty( 'uint32', sh, order ), 1, s, true, true ); // $ExpectType uint32ndarray - sliceDimensionFrom( empty( 'uint16', sh, order ), 1, s, true, true ); // $ExpectType uint16ndarray - sliceDimensionFrom( empty( 'uint8', sh, order ), 1, s, true, true ); // $ExpectType uint8ndarray - sliceDimensionFrom( empty( 'uint8c', sh, order ), 1, s, true, true ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const s = 0; - - sliceDimensionFrom( '10', 1, s, false, false ); // $ExpectError - sliceDimensionFrom( 10, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( false, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( true, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( null, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( [], 1, s, false, false ); // $ExpectError - sliceDimensionFrom( {}, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( ( x: number ): number => x, 1, s, false, false ); // $ExpectError - - sliceDimensionFrom( '10', 1, s, true, true ); // $ExpectError - sliceDimensionFrom( 10, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( false, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( true, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( null, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( [], 1, s, true, true ); // $ExpectError - sliceDimensionFrom( {}, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( ( x: number ): number => x, 1, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a number... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 1; - - sliceDimensionFrom( x, '5', s, false, false ); // $ExpectError - sliceDimensionFrom( x, false, s, false, false ); // $ExpectError - sliceDimensionFrom( x, true, s, false, false ); // $ExpectError - sliceDimensionFrom( x, null, s, false, false ); // $ExpectError - sliceDimensionFrom( x, undefined, s, false, false ); // $ExpectError - sliceDimensionFrom( x, [ '5' ], s, false, false ); // $ExpectError - sliceDimensionFrom( x, {}, s, false, false ); // $ExpectError - sliceDimensionFrom( x, ( x: number ): number => x, s, false, false ); // $ExpectError - - sliceDimensionFrom( x, '5', s, true, true ); // $ExpectError - sliceDimensionFrom( x, false, s, true, true ); // $ExpectError - sliceDimensionFrom( x, true, s, true, true ); // $ExpectError - sliceDimensionFrom( x, null, s, true, true ); // $ExpectError - sliceDimensionFrom( x, undefined, s, true, true ); // $ExpectError - sliceDimensionFrom( x, [ '5' ], s, true, true ); // $ExpectError - sliceDimensionFrom( x, {}, s, true, true ); // $ExpectError - sliceDimensionFrom( x, ( x: number ): number => x, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceDimensionFrom( x, 1, '5', false, false ); // $ExpectError - sliceDimensionFrom( x, 1, false, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, true, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, null, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, undefined, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, [ '5' ], false, false ); // $ExpectError - sliceDimensionFrom( x, 1, {}, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, ( x: number ): number => x, 1, false, false ); // $ExpectError - - sliceDimensionFrom( x, 1, '5', true, true ); // $ExpectError - sliceDimensionFrom( x, 1, false, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, true, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, null, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, undefined, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, [ '5' ], true, true ); // $ExpectError - sliceDimensionFrom( x, 1, {}, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, ( x: number ): number => x, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x, 1, s, '5', false ); // $ExpectError - sliceDimensionFrom( x, 1, s, 5, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, null, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, undefined, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, [ '5' ], false ); // $ExpectError - sliceDimensionFrom( x, 1, s, {}, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x, 1, s, false, '5' ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, 5 ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, null ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, undefined ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, [ '5' ] ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, {} ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x ); // $ExpectError - sliceDimensionFrom( x, 1 ); // $ExpectError - sliceDimensionFrom( x, 1, s ); // $ExpectError - sliceDimensionFrom( x, 1, s, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index b17162a..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 sliceDimensionFrom = 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 = sliceDimensionFrom( x, 1, 1, false, false ); -// 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 columns of each matrix: -var y2 = sliceDimensionFrom( x, 2, 1, false, false ); -// returns - -var a2 = ndarray2array( y2 ); -console.log( a2 ); -// => [ [ [ 1, 2 ], [ 4, 5 ], [ 7, 8 ] ], [ [ 10, 11 ], [ 13, 14 ], [ 16, 17 ] ], [ [ 19, 20 ], [ 22, 23 ], [ 25, 26 ] ] ] - -// Get the last two matrices: -var y3 = sliceDimensionFrom( x, 0, 1, false, false ); -// returns - -var a3 = ndarray2array( y3 ); -console.log( a3 ); -// => [ [ [ 9, 10, 11 ], [ 12, 13, 14 ], [ 15, 16, 17 ] ], [ [ 18, 19, 20 ], [ 21, 22, 23 ], [ 24, 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 e398649..44225a7 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..1a8cb86 --- /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/slice-base-args2multislice@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-ctor@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndims@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-normalize-index@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-filled@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function m(m,l,o,j,a){var p,h,v;if(0===(h=r(m)))throw new TypeError(n("1lDF7",h));if(-1===(v=i(l,h-1)))throw new RangeError(n("1lDF8",h,l));return(p=d(null,h))[v]=new e(o,null),t(m,s(p),j,a)}export{m as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..275a0ea --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport Slice from '@stdlib/slice-ctor';\nimport ndims from '@stdlib/ndarray-base-ndims';\nimport slice from '@stdlib/ndarray-base-slice';\nimport normalizeIndex from '@stdlib/ndarray-base-normalize-index';\nimport filled from '@stdlib/array-base-filled';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns a shifted view of an input ndarray along a specified dimension.\n*\n* @param {ndarray} x - input array\n* @param {integer} dim - index of dimension to slice\n* @param {integer} start - starting index (inclusive)\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {TypeError} first argument must be an ndarray having one or more dimensions\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\n*\n* @example\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceDimensionFrom( x, 0, 1, false, false );\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 sliceDimensionFrom( x, dim, start, strict, writable ) {\n\tvar args;\n\tvar N;\n\tvar d;\n\n\t// Retrieve array meta data:\n\tN = ndims( x );\n\n\t// Check whether we were provided a zero-dimensional array...\n\tif ( N === 0 ) {\n\t\tthrow new TypeError( format( '1lDF7', N ) );\n\t}\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, N-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( '1lDF8', N, dim ) );\n\t}\n\t// Define a list of slice arguments:\n\targs = filled( null, N );\n\targs[ d ] = new Slice( start, null );\n\n\t// Return a new array view:\n\treturn slice( x, args2multislice( args ), strict, writable );\n}\n\n\n// EXPORTS //\n\nexport default sliceDimensionFrom;\n"],"names":["sliceDimensionFrom","x","dim","start","strict","writable","args","N","d","ndims","TypeError","format","normalizeIndex","RangeError","filled","Slice","slice","args2multislice"],"mappings":";;wpBAyEA,SAASA,EAAoBC,EAAGC,EAAKC,EAAOC,EAAQC,GACnD,IAAIC,EACAC,EACAC,EAMJ,GAAW,KAHXD,EAAIE,EAAOR,IAIV,MAAM,IAAIS,UAAWC,EAAQ,QAASJ,IAIvC,IAAY,KADZC,EAAII,EAAgBV,EAAKK,EAAE,IAE1B,MAAM,IAAIM,WAAYF,EAAQ,QAASJ,EAAGL,IAO3C,OAJAI,EAAOQ,EAAQ,KAAMP,IACfC,GAAM,IAAIO,EAAOZ,EAAO,MAGvBa,EAAOf,EAAGgB,EAAiBX,GAAQF,EAAQC,EACnD"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index b3f97b2..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 shifted view of an input ndarray along a specified dimension. -* -* @module @stdlib/ndarray-base-slice-dimension-from -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var sliceDimensionFrom = require( '@stdlib/ndarray-base-slice-dimension-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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // 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 5dbaaef..0000000 --- a/lib/main.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var Slice = require( '@stdlib/slice-ctor' ); -var ndims = require( '@stdlib/ndarray-base-ndims' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' ); -var filled = require( '@stdlib/array-base-filled' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param {ndarray} x - input array -* @param {integer} dim - index of dimension to slice -* @param {integer} start - starting index (inclusive) -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @param {boolean} writable - boolean indicating whether a returned array should be writable -* @throws {TypeError} first argument must be an ndarray having one or more dimensions -* @throws {RangeError} dimension index exceeds the number of dimensions -* @throws {RangeError} slice 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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -function sliceDimensionFrom( x, dim, start, strict, writable ) { - var args; - var N; - var d; - - // Retrieve array meta data: - N = ndims( x ); - - // Check whether we were provided a zero-dimensional array... - if ( N === 0 ) { - throw new TypeError( format( '1lDF7', N ) ); - } - // Normalize the dimension index: - d = normalizeIndex( dim, N-1 ); - if ( d === -1 ) { - throw new RangeError( format( '1lDF8', N, dim ) ); - } - // Define a list of slice arguments: - args = filled( null, N ); - args[ d ] = new Slice( start, null ); - - // Return a new array view: - return slice( x, args2multislice( args ), strict, writable ); -} - - -// EXPORTS // - -module.exports = sliceDimensionFrom; diff --git a/package.json b/package.json index f7083d8..7879a68 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Return a shifted view of an input ndarray along a specific dimension.", "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,50 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-filled": "^0.2.1", - "@stdlib/ndarray-base-ndims": "^0.2.1", - "@stdlib/ndarray-base-normalize-index": "^0.2.1", - "@stdlib/ndarray-base-slice": "^0.2.1", - "@stdlib/slice-base-args2multislice": "^0.2.1", - "@stdlib/slice-ctor": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/array-typed": "^0.2.1", - "@stdlib/assert-is-ndarray-like": "^0.2.1", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.1", - "@stdlib/ndarray-base-ctor": "^0.2.1", - "@stdlib/ndarray-base-empty": "^0.2.1", - "@stdlib/ndarray-base-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..71c4425 --- /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 28703b5..0000000 --- a/test/test.js +++ /dev/null @@ -1,616 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 ndarray2array = require( '@stdlib/ndarray-to-array' ); -var baseCtor = require( '@stdlib/ndarray-base-ctor' ); -var ctor = require( '@stdlib/ndarray-ctor' ); -var sliceDimensionFrom = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sliceDimensionFrom, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a zero-dimensional array (strict=false)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error' ); - } - t.end(); - - function badValue( x ) { - return function badValue() { - sliceDimensionFrom( x, 0, 0, false, false ); - }; - } -}); - -tape( 'the function throws an error if provided a zero-dimensional array (strict=true)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error' ); - } - t.end(); - - function badValue( x ) { - return function badValue() { - sliceDimensionFrom( x, 0, 0, true, false ); - }; - } -}); - -tape( 'the function throws an error if the dimension index exceeds the number of dimensions (strict=false)', 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 ], 10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - t.throws( badValue( values[ i ], -10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - } - t.end(); - - function badValue( x, dim ) { - return function badValue() { - sliceDimensionFrom( x, dim, 0, false, false ); - }; - } -}); - -tape( 'the function throws an error if the dimension index exceeds the number of dimensions (strict=true)', 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 ], 10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - t.throws( badValue( values[ i ], -10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - } - t.end(); - - function badValue( x, dim ) { - return function badValue() { - sliceDimensionFrom( x, dim, 0, true, false ); - }; - } -}); - -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, - 20, - 20, - 20 - ]; - 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() { - sliceDimensionFrom( x, 0, s, true, false ); - }; - } -}); - -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, - 20, - 20, - 20, - 10 - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceDimensionFrom( values[ i ], 0, start[ i ], false, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), 0, 'returns expected value' ); - t.strictEqual( actual.dtype, values[ i ].dtype, 'returns expected value' ); - } - t.end(); -}); - -tape( 'in non-strict mode, the function returns an empty array when a starting index is the one more than the last index along a dimension', function test( t ) { - var actual; - var values; - var start; - var dim; - 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' } ) - ]; - - dim = [ - 0, - 1, - 0, - 1, - 4 - ]; - - start = [ - 1, - 1, - 1, - 1, - 1 - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceDimensionFrom( values[ i ], dim[ i ], start[ i ], false, false ); // eslint-disable-line max-len - 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 a shifted view of a provided input array (ndims=1)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 2, true, false ); - - 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 = sliceDimensionFrom( x, 0, -4, true, false ); - - 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)', 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 1, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 2, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, -2, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 1, 1, true, false ); - - 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 = sliceDimensionFrom( x, 1, -2, true, false ); - - 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' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=3)', 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 1, true, false ); - - 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 = sliceDimensionFrom( x, 1, 1, true, false ); - - 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 = sliceDimensionFrom( x, 2, 2, true, false ); - - 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 = sliceDimensionFrom( x, 2, -1, true, false ); - - 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' ); - t.end(); -}); - -tape( 'if a provided ndarray has a constructor supporting read-only instances, the function returns a read-only instance', function test( t ) { - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - x = new baseCtor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports returning writable views', function test( t ) { - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - x = new baseCtor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - t.end(); -}); From 0d16db4c1e816ab559c5e4dab62adbd6dc9e67f9 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 02:47:49 +0000 Subject: [PATCH 42/92] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 2b8e198..5dbaaef 100644 --- a/lib/main.js +++ b/lib/main.js @@ -26,7 +26,7 @@ var ndims = require( '@stdlib/ndarray-base-ndims' ); var slice = require( '@stdlib/ndarray-base-slice' ); var normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' ); var filled = require( '@stdlib/array-base-filled' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -81,12 +81,12 @@ function sliceDimensionFrom( x, dim, start, strict, writable ) { // Check whether we were provided a zero-dimensional array... if ( N === 0 ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.', N ) ); + throw new TypeError( format( '1lDF7', N ) ); } // Normalize the dimension index: d = normalizeIndex( dim, N-1 ); if ( d === -1 ) { - throw new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', N, dim ) ); + throw new RangeError( format( '1lDF8', N, dim ) ); } // Define a list of slice arguments: args = filled( null, N ); diff --git a/package.json b/package.json index a1ad273..15b87aa 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/ndarray-base-slice": "^0.2.1", "@stdlib/slice-base-args2multislice": "^0.2.2", "@stdlib/slice-ctor": "^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 673b932cde67824ee0a7400bf9b20accfdab53df Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 03:04:12 +0000 Subject: [PATCH 43/92] Remove files --- index.d.ts | 534 ------ index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5381 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 44225a7..0000000 --- a/index.d.ts +++ /dev/null @@ -1,534 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceDimensionFrom( x: float64ndarray, dim: number, start: number, strict: boolean, writable: boolean ): float64ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceDimensionFrom( x: float32ndarray, dim: number, start: number, strict: boolean, writable: boolean ): float32ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: int32ndarray, dim: number, start: number, strict: boolean, writable: boolean ): int32ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: int16ndarray, dim: number, start: number, strict: boolean, writable: boolean ): int16ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: int8ndarray, dim: number, start: number, strict: boolean, writable: boolean ): int8ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint32ndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint32ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint16ndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint16ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint8ndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint8ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint8cndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint8cndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceDimensionFrom( x: complex128ndarray, dim: number, start: number, strict: boolean, writable: boolean ): complex128ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceDimensionFrom( x: complex64ndarray, dim: number, start: number, strict: boolean, writable: boolean ): complex64ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: genericndarray, dim: number, start: number, strict: boolean, writable: boolean ): genericndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: typedndarray, dim: number, start: number, strict: boolean, writable: boolean ): typedndarray; - - -// EXPORTS // - -export = sliceDimensionFrom; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 1a8cb86..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/slice-base-args2multislice@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-ctor@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndims@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-normalize-index@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-filled@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function m(m,l,o,j,a){var p,h,v;if(0===(h=r(m)))throw new TypeError(n("1lDF7",h));if(-1===(v=i(l,h-1)))throw new RangeError(n("1lDF8",h,l));return(p=d(null,h))[v]=new e(o,null),t(m,s(p),j,a)}export{m as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 275a0ea..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport Slice from '@stdlib/slice-ctor';\nimport ndims from '@stdlib/ndarray-base-ndims';\nimport slice from '@stdlib/ndarray-base-slice';\nimport normalizeIndex from '@stdlib/ndarray-base-normalize-index';\nimport filled from '@stdlib/array-base-filled';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns a shifted view of an input ndarray along a specified dimension.\n*\n* @param {ndarray} x - input array\n* @param {integer} dim - index of dimension to slice\n* @param {integer} start - starting index (inclusive)\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {TypeError} first argument must be an ndarray having one or more dimensions\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\n*\n* @example\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceDimensionFrom( x, 0, 1, false, false );\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 sliceDimensionFrom( x, dim, start, strict, writable ) {\n\tvar args;\n\tvar N;\n\tvar d;\n\n\t// Retrieve array meta data:\n\tN = ndims( x );\n\n\t// Check whether we were provided a zero-dimensional array...\n\tif ( N === 0 ) {\n\t\tthrow new TypeError( format( '1lDF7', N ) );\n\t}\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, N-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( '1lDF8', N, dim ) );\n\t}\n\t// Define a list of slice arguments:\n\targs = filled( null, N );\n\targs[ d ] = new Slice( start, null );\n\n\t// Return a new array view:\n\treturn slice( x, args2multislice( args ), strict, writable );\n}\n\n\n// EXPORTS //\n\nexport default sliceDimensionFrom;\n"],"names":["sliceDimensionFrom","x","dim","start","strict","writable","args","N","d","ndims","TypeError","format","normalizeIndex","RangeError","filled","Slice","slice","args2multislice"],"mappings":";;wpBAyEA,SAASA,EAAoBC,EAAGC,EAAKC,EAAOC,EAAQC,GACnD,IAAIC,EACAC,EACAC,EAMJ,GAAW,KAHXD,EAAIE,EAAOR,IAIV,MAAM,IAAIS,UAAWC,EAAQ,QAASJ,IAIvC,IAAY,KADZC,EAAII,EAAgBV,EAAKK,EAAE,IAE1B,MAAM,IAAIM,WAAYF,EAAQ,QAASJ,EAAGL,IAO3C,OAJAI,EAAOQ,EAAQ,KAAMP,IACfC,GAAM,IAAIO,EAAOZ,EAAO,MAGvBa,EAAOf,EAAGgB,EAAiBX,GAAQF,EAAQC,EACnD"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 71c4425..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 1c870d1230335c4be3dfef04d0a18da38c496557 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 03:04:46 +0000 Subject: [PATCH 44/92] 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 | 104 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 45 +- SECURITY.md | 5 - benchmark/benchmark.js | 681 --- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 49 - docs/types/test.ts | 164 - 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 | 102 - package.json | 71 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 616 --- 42 files changed, 4868 insertions(+), 5229 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 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 05d1840..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-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 ced95ae..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-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 60a2bb4..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: '38 14 * * 5' - - # 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 + + ```
@@ -202,7 +193,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]. diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 8a6b7a2..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,681 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 sliceDimensionFrom = require( './../lib' ); - - -// MAIN // - -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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2 ], { 'dtype': 'float64' } ), - empty( [ 2 ], { 'dtype': 'float32' } ), - empty( [ 2 ], { 'dtype': 'int32' } ), - empty( [ 2 ], { 'dtype': 'complex128' } ), - empty( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== '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 9543fcd..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-from" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-from -[production-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-slice-dimension-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 2ab577a..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import sliceDimensionFrom from '../docs/types/index'; -export = sliceDimensionFrom; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 2e11f06..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var l=function(i,r){return function(){return r||i((r={exports:{}}).exports,r),r.exports}};var o=l(function(p,u){"use strict";var v=require("@stdlib/slice-base-args2multislice"),c=require("@stdlib/slice-ctor"),f=require("@stdlib/ndarray-base-ndims"),q=require("@stdlib/ndarray-base-slice"),g=require("@stdlib/ndarray-base-normalize-index"),w=require("@stdlib/array-base-filled"),s=require("@stdlib/string-format");function b(i,r,m,t,d){var n,e,a;if(e=f(i),e===0)throw new TypeError(s("invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.",e));if(a=g(r,e-1),a===-1)throw new RangeError(s("invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.",e,r));return n=w(null,e),n[a]=new c(m,null),q(i,v(n),t,d)}u.exports=b});var h=o();module.exports=h; -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index a75b3e0..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar args2multislice = require( '@stdlib/slice-base-args2multislice' );\nvar Slice = require( '@stdlib/slice-ctor' );\nvar ndims = require( '@stdlib/ndarray-base-ndims' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' );\nvar filled = require( '@stdlib/array-base-filled' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns a shifted view of an input ndarray along a specified dimension.\n*\n* @param {ndarray} x - input array\n* @param {integer} dim - index of dimension to slice\n* @param {integer} start - starting index (inclusive)\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {TypeError} first argument must be an ndarray having one or more dimensions\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceDimensionFrom( x, 0, 1, false, false );\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 sliceDimensionFrom( x, dim, start, strict, writable ) {\n\tvar args;\n\tvar N;\n\tvar d;\n\n\t// Retrieve array meta data:\n\tN = ndims( x );\n\n\t// Check whether we were provided a zero-dimensional array...\n\tif ( N === 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.', N ) );\n\t}\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, N-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', N, dim ) );\n\t}\n\t// Define a list of slice arguments:\n\targs = filled( null, N );\n\targs[ d ] = new Slice( start, null );\n\n\t// Return a new array view:\n\treturn slice( x, args2multislice( args ), strict, writable );\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceDimensionFrom;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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 shifted view of an input ndarray along a specified dimension.\n*\n* @module @stdlib/ndarray-base-slice-dimension-from\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var sliceDimensionFrom = require( '@stdlib/ndarray-base-slice-dimension-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 = sliceDimensionFrom( x, 0, 1, false, false );\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,EAAkB,QAAS,oCAAqC,EAChEC,EAAQ,QAAS,oBAAqB,EACtCC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAiB,QAAS,sCAAuC,EACjEC,EAAS,QAAS,2BAA4B,EAC9CC,EAAS,QAAS,uBAAwB,EA6C9C,SAASC,EAAoBC,EAAGC,EAAKC,EAAOC,EAAQC,EAAW,CAC9D,IAAIC,EACAC,EACAC,EAMJ,GAHAD,EAAIZ,EAAOM,CAAE,EAGRM,IAAM,EACV,MAAM,IAAI,UAAWR,EAAQ,+GAAgHQ,CAAE,CAAE,EAIlJ,GADAC,EAAIX,EAAgBK,EAAKK,EAAE,CAAE,EACxBC,IAAM,GACV,MAAM,IAAI,WAAYT,EAAQ,6GAA8GQ,EAAGL,CAAI,CAAE,EAGtJ,OAAAI,EAAOR,EAAQ,KAAMS,CAAE,EACvBD,EAAME,CAAE,EAAI,IAAId,EAAOS,EAAO,IAAK,EAG5BP,EAAOK,EAAGR,EAAiBa,CAAK,EAAGF,EAAQC,CAAS,CAC5D,CAKAb,EAAO,QAAUQ,IC7CjB,IAAIS,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "args2multislice", "Slice", "ndims", "slice", "normalizeIndex", "filled", "format", "sliceDimensionFrom", "x", "dim", "start", "strict", "writable", "args", "N", "d", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ffc1f03..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,49 +0,0 @@ - -{{alias}}( x, dim, start, strict, writable ) - Returns a shifted view of an input ndarray along a specified dimension. - - Parameters - ---------- - x: ndarray - Input array. - - dim: integer - Index of dimension to slice. If less than zero, the index is resolved - relative to the last dimension, with the last dimension corresponding to - the value `-1`. - - start: integer - Starting index (inclusive). If less than zero, the corresponding element - along the specified dimension is resolved relative to the last element - along that dimension. For negative integers, the last element - corresponds to the value `-1`. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - writable: boolean - Boolean indicating whether a returned ndarray should be writable. This - parameter only applies to ndarray constructors which support read-only - instances. - - Returns - ------- - out: ndarray - Output array view. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > x.shape - [ 2, 2 ] - > var y = {{alias}}( x, 1, 1, false, false ) - - > 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 9dfeaf3..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,164 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sliceDimensionFrom = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = 0; - - sliceDimensionFrom( empty( 'float64', sh, order ), 1, s, false, false ); // $ExpectType float64ndarray - sliceDimensionFrom( empty( 'float32', sh, order ), 1, s, false, false ); // $ExpectType float32ndarray - sliceDimensionFrom( empty( 'complex128', sh, order ), 1, s, false, false ); // $ExpectType complex128ndarray - sliceDimensionFrom( empty( 'complex64', sh, order ), 1, s, false, false ); // $ExpectType complex64ndarray - sliceDimensionFrom( empty( 'int32', sh, order ), 1, s, false, false ); // $ExpectType int32ndarray - sliceDimensionFrom( empty( 'int16', sh, order ), 1, s, false, false ); // $ExpectType int16ndarray - sliceDimensionFrom( empty( 'int8', sh, order ), 1, s, false, false ); // $ExpectType int8ndarray - sliceDimensionFrom( empty( 'uint32', sh, order ), 1, s, false, false ); // $ExpectType uint32ndarray - sliceDimensionFrom( empty( 'uint16', sh, order ), 1, s, false, false ); // $ExpectType uint16ndarray - sliceDimensionFrom( empty( 'uint8', sh, order ), 1, s, false, false ); // $ExpectType uint8ndarray - sliceDimensionFrom( empty( 'uint8c', sh, order ), 1, s, false, false ); // $ExpectType uint8cndarray - - sliceDimensionFrom( empty( 'float64', sh, order ), 1, s, true, true ); // $ExpectType float64ndarray - sliceDimensionFrom( empty( 'float32', sh, order ), 1, s, true, true ); // $ExpectType float32ndarray - sliceDimensionFrom( empty( 'complex128', sh, order ), 1, s, true, true ); // $ExpectType complex128ndarray - sliceDimensionFrom( empty( 'complex64', sh, order ), 1, s, true, true ); // $ExpectType complex64ndarray - sliceDimensionFrom( empty( 'int32', sh, order ), 1, s, true, true ); // $ExpectType int32ndarray - sliceDimensionFrom( empty( 'int16', sh, order ), 1, s, true, true ); // $ExpectType int16ndarray - sliceDimensionFrom( empty( 'int8', sh, order ), 1, s, true, true ); // $ExpectType int8ndarray - sliceDimensionFrom( empty( 'uint32', sh, order ), 1, s, true, true ); // $ExpectType uint32ndarray - sliceDimensionFrom( empty( 'uint16', sh, order ), 1, s, true, true ); // $ExpectType uint16ndarray - sliceDimensionFrom( empty( 'uint8', sh, order ), 1, s, true, true ); // $ExpectType uint8ndarray - sliceDimensionFrom( empty( 'uint8c', sh, order ), 1, s, true, true ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const s = 0; - - sliceDimensionFrom( '10', 1, s, false, false ); // $ExpectError - sliceDimensionFrom( 10, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( false, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( true, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( null, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( [], 1, s, false, false ); // $ExpectError - sliceDimensionFrom( {}, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( ( x: number ): number => x, 1, s, false, false ); // $ExpectError - - sliceDimensionFrom( '10', 1, s, true, true ); // $ExpectError - sliceDimensionFrom( 10, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( false, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( true, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( null, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( [], 1, s, true, true ); // $ExpectError - sliceDimensionFrom( {}, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( ( x: number ): number => x, 1, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a number... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 1; - - sliceDimensionFrom( x, '5', s, false, false ); // $ExpectError - sliceDimensionFrom( x, false, s, false, false ); // $ExpectError - sliceDimensionFrom( x, true, s, false, false ); // $ExpectError - sliceDimensionFrom( x, null, s, false, false ); // $ExpectError - sliceDimensionFrom( x, undefined, s, false, false ); // $ExpectError - sliceDimensionFrom( x, [ '5' ], s, false, false ); // $ExpectError - sliceDimensionFrom( x, {}, s, false, false ); // $ExpectError - sliceDimensionFrom( x, ( x: number ): number => x, s, false, false ); // $ExpectError - - sliceDimensionFrom( x, '5', s, true, true ); // $ExpectError - sliceDimensionFrom( x, false, s, true, true ); // $ExpectError - sliceDimensionFrom( x, true, s, true, true ); // $ExpectError - sliceDimensionFrom( x, null, s, true, true ); // $ExpectError - sliceDimensionFrom( x, undefined, s, true, true ); // $ExpectError - sliceDimensionFrom( x, [ '5' ], s, true, true ); // $ExpectError - sliceDimensionFrom( x, {}, s, true, true ); // $ExpectError - sliceDimensionFrom( x, ( x: number ): number => x, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceDimensionFrom( x, 1, '5', false, false ); // $ExpectError - sliceDimensionFrom( x, 1, false, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, true, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, null, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, undefined, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, [ '5' ], false, false ); // $ExpectError - sliceDimensionFrom( x, 1, {}, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, ( x: number ): number => x, 1, false, false ); // $ExpectError - - sliceDimensionFrom( x, 1, '5', true, true ); // $ExpectError - sliceDimensionFrom( x, 1, false, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, true, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, null, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, undefined, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, [ '5' ], true, true ); // $ExpectError - sliceDimensionFrom( x, 1, {}, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, ( x: number ): number => x, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x, 1, s, '5', false ); // $ExpectError - sliceDimensionFrom( x, 1, s, 5, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, null, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, undefined, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, [ '5' ], false ); // $ExpectError - sliceDimensionFrom( x, 1, s, {}, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x, 1, s, false, '5' ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, 5 ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, null ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, undefined ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, [ '5' ] ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, {} ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x ); // $ExpectError - sliceDimensionFrom( x, 1 ); // $ExpectError - sliceDimensionFrom( x, 1, s ); // $ExpectError - sliceDimensionFrom( x, 1, s, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index b17162a..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 sliceDimensionFrom = 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 = sliceDimensionFrom( x, 1, 1, false, false ); -// 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 columns of each matrix: -var y2 = sliceDimensionFrom( x, 2, 1, false, false ); -// returns - -var a2 = ndarray2array( y2 ); -console.log( a2 ); -// => [ [ [ 1, 2 ], [ 4, 5 ], [ 7, 8 ] ], [ [ 10, 11 ], [ 13, 14 ], [ 16, 17 ] ], [ [ 19, 20 ], [ 22, 23 ], [ 25, 26 ] ] ] - -// Get the last two matrices: -var y3 = sliceDimensionFrom( x, 0, 1, false, false ); -// returns - -var a3 = ndarray2array( y3 ); -console.log( a3 ); -// => [ [ [ 9, 10, 11 ], [ 12, 13, 14 ], [ 15, 16, 17 ] ], [ [ 18, 19, 20 ], [ 21, 22, 23 ], [ 24, 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 e398649..44225a7 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..6355f15 --- /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/slice-base-args2multislice@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-ctor@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndims@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-normalize-index@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-filled@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function m(m,l,o,j,a){var p,h,v;if(0===(h=r(m)))throw new TypeError(n("1lDF7",h));if(-1===(v=i(l,h-1)))throw new RangeError(n("1lDF8",h,l));return(p=d(null,h))[v]=new e(o,null),t(m,s(p),j,a)}export{m as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..275a0ea --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport Slice from '@stdlib/slice-ctor';\nimport ndims from '@stdlib/ndarray-base-ndims';\nimport slice from '@stdlib/ndarray-base-slice';\nimport normalizeIndex from '@stdlib/ndarray-base-normalize-index';\nimport filled from '@stdlib/array-base-filled';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns a shifted view of an input ndarray along a specified dimension.\n*\n* @param {ndarray} x - input array\n* @param {integer} dim - index of dimension to slice\n* @param {integer} start - starting index (inclusive)\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {TypeError} first argument must be an ndarray having one or more dimensions\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\n*\n* @example\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceDimensionFrom( x, 0, 1, false, false );\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 sliceDimensionFrom( x, dim, start, strict, writable ) {\n\tvar args;\n\tvar N;\n\tvar d;\n\n\t// Retrieve array meta data:\n\tN = ndims( x );\n\n\t// Check whether we were provided a zero-dimensional array...\n\tif ( N === 0 ) {\n\t\tthrow new TypeError( format( '1lDF7', N ) );\n\t}\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, N-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( '1lDF8', N, dim ) );\n\t}\n\t// Define a list of slice arguments:\n\targs = filled( null, N );\n\targs[ d ] = new Slice( start, null );\n\n\t// Return a new array view:\n\treturn slice( x, args2multislice( args ), strict, writable );\n}\n\n\n// EXPORTS //\n\nexport default sliceDimensionFrom;\n"],"names":["sliceDimensionFrom","x","dim","start","strict","writable","args","N","d","ndims","TypeError","format","normalizeIndex","RangeError","filled","Slice","slice","args2multislice"],"mappings":";;wpBAyEA,SAASA,EAAoBC,EAAGC,EAAKC,EAAOC,EAAQC,GACnD,IAAIC,EACAC,EACAC,EAMJ,GAAW,KAHXD,EAAIE,EAAOR,IAIV,MAAM,IAAIS,UAAWC,EAAQ,QAASJ,IAIvC,IAAY,KADZC,EAAII,EAAgBV,EAAKK,EAAE,IAE1B,MAAM,IAAIM,WAAYF,EAAQ,QAASJ,EAAGL,IAO3C,OAJAI,EAAOQ,EAAQ,KAAMP,IACfC,GAAM,IAAIO,EAAOZ,EAAO,MAGvBa,EAAOf,EAAGgB,EAAiBX,GAAQF,EAAQC,EACnD"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index b3f97b2..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 shifted view of an input ndarray along a specified dimension. -* -* @module @stdlib/ndarray-base-slice-dimension-from -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var sliceDimensionFrom = require( '@stdlib/ndarray-base-slice-dimension-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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // 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 5dbaaef..0000000 --- a/lib/main.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var Slice = require( '@stdlib/slice-ctor' ); -var ndims = require( '@stdlib/ndarray-base-ndims' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' ); -var filled = require( '@stdlib/array-base-filled' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param {ndarray} x - input array -* @param {integer} dim - index of dimension to slice -* @param {integer} start - starting index (inclusive) -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @param {boolean} writable - boolean indicating whether a returned array should be writable -* @throws {TypeError} first argument must be an ndarray having one or more dimensions -* @throws {RangeError} dimension index exceeds the number of dimensions -* @throws {RangeError} slice 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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -function sliceDimensionFrom( x, dim, start, strict, writable ) { - var args; - var N; - var d; - - // Retrieve array meta data: - N = ndims( x ); - - // Check whether we were provided a zero-dimensional array... - if ( N === 0 ) { - throw new TypeError( format( '1lDF7', N ) ); - } - // Normalize the dimension index: - d = normalizeIndex( dim, N-1 ); - if ( d === -1 ) { - throw new RangeError( format( '1lDF8', N, dim ) ); - } - // Define a list of slice arguments: - args = filled( null, N ); - args[ d ] = new Slice( start, null ); - - // Return a new array view: - return slice( x, args2multislice( args ), strict, writable ); -} - - -// EXPORTS // - -module.exports = sliceDimensionFrom; diff --git a/package.json b/package.json index 15b87aa..eb2ee55 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Return a shifted view of an input ndarray along a specific dimension.", "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,50 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-filled": "^0.2.2", - "@stdlib/ndarray-base-ndims": "^0.2.2", - "@stdlib/ndarray-base-normalize-index": "^0.2.2", - "@stdlib/ndarray-base-slice": "^0.2.1", - "@stdlib/slice-base-args2multislice": "^0.2.2", - "@stdlib/slice-ctor": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/array-typed": "^0.2.1", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-base-empty": "^0.2.1", - "@stdlib/ndarray-base-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..5bdd403 --- /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 28703b5..0000000 --- a/test/test.js +++ /dev/null @@ -1,616 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 ndarray2array = require( '@stdlib/ndarray-to-array' ); -var baseCtor = require( '@stdlib/ndarray-base-ctor' ); -var ctor = require( '@stdlib/ndarray-ctor' ); -var sliceDimensionFrom = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sliceDimensionFrom, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a zero-dimensional array (strict=false)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error' ); - } - t.end(); - - function badValue( x ) { - return function badValue() { - sliceDimensionFrom( x, 0, 0, false, false ); - }; - } -}); - -tape( 'the function throws an error if provided a zero-dimensional array (strict=true)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error' ); - } - t.end(); - - function badValue( x ) { - return function badValue() { - sliceDimensionFrom( x, 0, 0, true, false ); - }; - } -}); - -tape( 'the function throws an error if the dimension index exceeds the number of dimensions (strict=false)', 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 ], 10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - t.throws( badValue( values[ i ], -10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - } - t.end(); - - function badValue( x, dim ) { - return function badValue() { - sliceDimensionFrom( x, dim, 0, false, false ); - }; - } -}); - -tape( 'the function throws an error if the dimension index exceeds the number of dimensions (strict=true)', 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 ], 10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - t.throws( badValue( values[ i ], -10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - } - t.end(); - - function badValue( x, dim ) { - return function badValue() { - sliceDimensionFrom( x, dim, 0, true, false ); - }; - } -}); - -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, - 20, - 20, - 20 - ]; - 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() { - sliceDimensionFrom( x, 0, s, true, false ); - }; - } -}); - -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, - 20, - 20, - 20, - 10 - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceDimensionFrom( values[ i ], 0, start[ i ], false, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), 0, 'returns expected value' ); - t.strictEqual( actual.dtype, values[ i ].dtype, 'returns expected value' ); - } - t.end(); -}); - -tape( 'in non-strict mode, the function returns an empty array when a starting index is the one more than the last index along a dimension', function test( t ) { - var actual; - var values; - var start; - var dim; - 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' } ) - ]; - - dim = [ - 0, - 1, - 0, - 1, - 4 - ]; - - start = [ - 1, - 1, - 1, - 1, - 1 - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceDimensionFrom( values[ i ], dim[ i ], start[ i ], false, false ); // eslint-disable-line max-len - 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 a shifted view of a provided input array (ndims=1)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 2, true, false ); - - 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 = sliceDimensionFrom( x, 0, -4, true, false ); - - 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)', 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 1, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 2, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, -2, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 1, 1, true, false ); - - 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 = sliceDimensionFrom( x, 1, -2, true, false ); - - 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' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=3)', 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 1, true, false ); - - 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 = sliceDimensionFrom( x, 1, 1, true, false ); - - 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 = sliceDimensionFrom( x, 2, 2, true, false ); - - 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 = sliceDimensionFrom( x, 2, -1, true, false ); - - 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' ); - t.end(); -}); - -tape( 'if a provided ndarray has a constructor supporting read-only instances, the function returns a read-only instance', function test( t ) { - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - x = new baseCtor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports returning writable views', function test( t ) { - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - x = new baseCtor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - t.end(); -}); From eb55ebea1eda0d18279431cfb6befba2f631d587 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 03:14:25 +0000 Subject: [PATCH 45/92] 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 66fb213..7fcdd42 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import sliceDimensionFrom from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-dimension-from@esm/index.mjs'; +import sliceDimensionFrom from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-dimension-from@v0.2.2-esm/index.mjs'; ``` #### sliceDimensionFrom( x, dim, start, strict, writable ) @@ -128,7 +128,7 @@ The function accepts the following arguments: 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 sliceDimensionFrom from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-dimension-from@esm/index.mjs'; +import sliceDimensionFrom from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-dimension-from@v0.2.2-esm/index.mjs'; // Create a linear ndarray buffer: var buf = zeroTo( 27 ); From 2ec672a3222cf36bdfd04d0eea188eef5154ca0e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 03:14:26 +0000 Subject: [PATCH 46/92] Auto-generated commit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7fcdd42..1b5d999 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,11 @@ limitations under the License. ## Usage +```javascript +import sliceDimensionFrom from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-dimension-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-base-slice-dimension-from/tags). For example, + ```javascript import sliceDimensionFrom from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-dimension-from@v0.2.2-esm/index.mjs'; ``` @@ -128,7 +133,7 @@ The function accepts the following arguments: 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 sliceDimensionFrom from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-dimension-from@v0.2.2-esm/index.mjs'; +import sliceDimensionFrom from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-dimension-from@esm/index.mjs'; // Create a linear ndarray buffer: var buf = zeroTo( 27 ); From 234a66f9aebc5c167e68b5086b6b059d7e0050c6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Aug 2024 08:00:57 +0000 Subject: [PATCH 47/92] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 2b8e198..5dbaaef 100644 --- a/lib/main.js +++ b/lib/main.js @@ -26,7 +26,7 @@ var ndims = require( '@stdlib/ndarray-base-ndims' ); var slice = require( '@stdlib/ndarray-base-slice' ); var normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' ); var filled = require( '@stdlib/array-base-filled' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -81,12 +81,12 @@ function sliceDimensionFrom( x, dim, start, strict, writable ) { // Check whether we were provided a zero-dimensional array... if ( N === 0 ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.', N ) ); + throw new TypeError( format( '1lDF7', N ) ); } // Normalize the dimension index: d = normalizeIndex( dim, N-1 ); if ( d === -1 ) { - throw new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', N, dim ) ); + throw new RangeError( format( '1lDF8', N, dim ) ); } // Define a list of slice arguments: args = filled( null, N ); diff --git a/package.json b/package.json index bc88c73..cbdca07 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/ndarray-base-slice": "^0.2.2", "@stdlib/slice-base-args2multislice": "^0.2.2", "@stdlib/slice-ctor": "^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 4984a08259449a53fbf60f4f05999a11826f8f01 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Aug 2024 12:56:41 +0000 Subject: [PATCH 48/92] Remove files --- index.d.ts | 534 ------ index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5381 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 44225a7..0000000 --- a/index.d.ts +++ /dev/null @@ -1,534 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceDimensionFrom( x: float64ndarray, dim: number, start: number, strict: boolean, writable: boolean ): float64ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceDimensionFrom( x: float32ndarray, dim: number, start: number, strict: boolean, writable: boolean ): float32ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: int32ndarray, dim: number, start: number, strict: boolean, writable: boolean ): int32ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: int16ndarray, dim: number, start: number, strict: boolean, writable: boolean ): int16ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: int8ndarray, dim: number, start: number, strict: boolean, writable: boolean ): int8ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint32ndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint32ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint16ndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint16ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint8ndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint8ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint8cndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint8cndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceDimensionFrom( x: complex128ndarray, dim: number, start: number, strict: boolean, writable: boolean ): complex128ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceDimensionFrom( x: complex64ndarray, dim: number, start: number, strict: boolean, writable: boolean ): complex64ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: genericndarray, dim: number, start: number, strict: boolean, writable: boolean ): genericndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: typedndarray, dim: number, start: number, strict: boolean, writable: boolean ): typedndarray; - - -// EXPORTS // - -export = sliceDimensionFrom; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 6355f15..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/slice-base-args2multislice@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-ctor@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndims@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-normalize-index@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-filled@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function m(m,l,o,j,a){var p,h,v;if(0===(h=r(m)))throw new TypeError(n("1lDF7",h));if(-1===(v=i(l,h-1)))throw new RangeError(n("1lDF8",h,l));return(p=d(null,h))[v]=new e(o,null),t(m,s(p),j,a)}export{m as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 275a0ea..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport Slice from '@stdlib/slice-ctor';\nimport ndims from '@stdlib/ndarray-base-ndims';\nimport slice from '@stdlib/ndarray-base-slice';\nimport normalizeIndex from '@stdlib/ndarray-base-normalize-index';\nimport filled from '@stdlib/array-base-filled';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns a shifted view of an input ndarray along a specified dimension.\n*\n* @param {ndarray} x - input array\n* @param {integer} dim - index of dimension to slice\n* @param {integer} start - starting index (inclusive)\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {TypeError} first argument must be an ndarray having one or more dimensions\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\n*\n* @example\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceDimensionFrom( x, 0, 1, false, false );\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 sliceDimensionFrom( x, dim, start, strict, writable ) {\n\tvar args;\n\tvar N;\n\tvar d;\n\n\t// Retrieve array meta data:\n\tN = ndims( x );\n\n\t// Check whether we were provided a zero-dimensional array...\n\tif ( N === 0 ) {\n\t\tthrow new TypeError( format( '1lDF7', N ) );\n\t}\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, N-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( '1lDF8', N, dim ) );\n\t}\n\t// Define a list of slice arguments:\n\targs = filled( null, N );\n\targs[ d ] = new Slice( start, null );\n\n\t// Return a new array view:\n\treturn slice( x, args2multislice( args ), strict, writable );\n}\n\n\n// EXPORTS //\n\nexport default sliceDimensionFrom;\n"],"names":["sliceDimensionFrom","x","dim","start","strict","writable","args","N","d","ndims","TypeError","format","normalizeIndex","RangeError","filled","Slice","slice","args2multislice"],"mappings":";;wpBAyEA,SAASA,EAAoBC,EAAGC,EAAKC,EAAOC,EAAQC,GACnD,IAAIC,EACAC,EACAC,EAMJ,GAAW,KAHXD,EAAIE,EAAOR,IAIV,MAAM,IAAIS,UAAWC,EAAQ,QAASJ,IAIvC,IAAY,KADZC,EAAII,EAAgBV,EAAKK,EAAE,IAE1B,MAAM,IAAIM,WAAYF,EAAQ,QAASJ,EAAGL,IAO3C,OAJAI,EAAOQ,EAAQ,KAAMP,IACfC,GAAM,IAAIO,EAAOZ,EAAO,MAGvBa,EAAOf,EAAGgB,EAAiBX,GAAQF,EAAQC,EACnD"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 5bdd403..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From e8427d5049d4691d8dac402db3bbbb1b63274896 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Aug 2024 12:57:07 +0000 Subject: [PATCH 49/92] 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 | 45 +- SECURITY.md | 5 - benchmark/benchmark.js | 681 --- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 49 - docs/types/test.ts | 164 - 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 | 102 - package.json | 71 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 616 --- 43 files changed, 4868 insertions(+), 5204 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 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 b2c6fd9..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-08-01T05:53:04.877Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 05d1840..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-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 ced95ae..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-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 60a2bb4..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: '38 14 * * 5' - - # 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 + + ```
@@ -202,7 +193,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]. diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 8a6b7a2..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,681 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 sliceDimensionFrom = require( './../lib' ); - - -// MAIN // - -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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2 ], { 'dtype': 'float64' } ), - empty( [ 2 ], { 'dtype': 'float32' } ), - empty( [ 2 ], { 'dtype': 'int32' } ), - empty( [ 2 ], { 'dtype': 'complex128' } ), - empty( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== '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 9543fcd..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-from" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-from -[production-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-slice-dimension-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 2ab577a..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import sliceDimensionFrom from '../docs/types/index'; -export = sliceDimensionFrom; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 2e11f06..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var l=function(i,r){return function(){return r||i((r={exports:{}}).exports,r),r.exports}};var o=l(function(p,u){"use strict";var v=require("@stdlib/slice-base-args2multislice"),c=require("@stdlib/slice-ctor"),f=require("@stdlib/ndarray-base-ndims"),q=require("@stdlib/ndarray-base-slice"),g=require("@stdlib/ndarray-base-normalize-index"),w=require("@stdlib/array-base-filled"),s=require("@stdlib/string-format");function b(i,r,m,t,d){var n,e,a;if(e=f(i),e===0)throw new TypeError(s("invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.",e));if(a=g(r,e-1),a===-1)throw new RangeError(s("invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.",e,r));return n=w(null,e),n[a]=new c(m,null),q(i,v(n),t,d)}u.exports=b});var h=o();module.exports=h; -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index a75b3e0..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar args2multislice = require( '@stdlib/slice-base-args2multislice' );\nvar Slice = require( '@stdlib/slice-ctor' );\nvar ndims = require( '@stdlib/ndarray-base-ndims' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' );\nvar filled = require( '@stdlib/array-base-filled' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns a shifted view of an input ndarray along a specified dimension.\n*\n* @param {ndarray} x - input array\n* @param {integer} dim - index of dimension to slice\n* @param {integer} start - starting index (inclusive)\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {TypeError} first argument must be an ndarray having one or more dimensions\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceDimensionFrom( x, 0, 1, false, false );\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 sliceDimensionFrom( x, dim, start, strict, writable ) {\n\tvar args;\n\tvar N;\n\tvar d;\n\n\t// Retrieve array meta data:\n\tN = ndims( x );\n\n\t// Check whether we were provided a zero-dimensional array...\n\tif ( N === 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.', N ) );\n\t}\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, N-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', N, dim ) );\n\t}\n\t// Define a list of slice arguments:\n\targs = filled( null, N );\n\targs[ d ] = new Slice( start, null );\n\n\t// Return a new array view:\n\treturn slice( x, args2multislice( args ), strict, writable );\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceDimensionFrom;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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 shifted view of an input ndarray along a specified dimension.\n*\n* @module @stdlib/ndarray-base-slice-dimension-from\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var sliceDimensionFrom = require( '@stdlib/ndarray-base-slice-dimension-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 = sliceDimensionFrom( x, 0, 1, false, false );\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,EAAkB,QAAS,oCAAqC,EAChEC,EAAQ,QAAS,oBAAqB,EACtCC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAiB,QAAS,sCAAuC,EACjEC,EAAS,QAAS,2BAA4B,EAC9CC,EAAS,QAAS,uBAAwB,EA6C9C,SAASC,EAAoBC,EAAGC,EAAKC,EAAOC,EAAQC,EAAW,CAC9D,IAAIC,EACAC,EACAC,EAMJ,GAHAD,EAAIZ,EAAOM,CAAE,EAGRM,IAAM,EACV,MAAM,IAAI,UAAWR,EAAQ,+GAAgHQ,CAAE,CAAE,EAIlJ,GADAC,EAAIX,EAAgBK,EAAKK,EAAE,CAAE,EACxBC,IAAM,GACV,MAAM,IAAI,WAAYT,EAAQ,6GAA8GQ,EAAGL,CAAI,CAAE,EAGtJ,OAAAI,EAAOR,EAAQ,KAAMS,CAAE,EACvBD,EAAME,CAAE,EAAI,IAAId,EAAOS,EAAO,IAAK,EAG5BP,EAAOK,EAAGR,EAAiBa,CAAK,EAAGF,EAAQC,CAAS,CAC5D,CAKAb,EAAO,QAAUQ,IC7CjB,IAAIS,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "args2multislice", "Slice", "ndims", "slice", "normalizeIndex", "filled", "format", "sliceDimensionFrom", "x", "dim", "start", "strict", "writable", "args", "N", "d", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ffc1f03..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,49 +0,0 @@ - -{{alias}}( x, dim, start, strict, writable ) - Returns a shifted view of an input ndarray along a specified dimension. - - Parameters - ---------- - x: ndarray - Input array. - - dim: integer - Index of dimension to slice. If less than zero, the index is resolved - relative to the last dimension, with the last dimension corresponding to - the value `-1`. - - start: integer - Starting index (inclusive). If less than zero, the corresponding element - along the specified dimension is resolved relative to the last element - along that dimension. For negative integers, the last element - corresponds to the value `-1`. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - writable: boolean - Boolean indicating whether a returned ndarray should be writable. This - parameter only applies to ndarray constructors which support read-only - instances. - - Returns - ------- - out: ndarray - Output array view. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > x.shape - [ 2, 2 ] - > var y = {{alias}}( x, 1, 1, false, false ) - - > 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 9dfeaf3..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,164 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sliceDimensionFrom = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = 0; - - sliceDimensionFrom( empty( 'float64', sh, order ), 1, s, false, false ); // $ExpectType float64ndarray - sliceDimensionFrom( empty( 'float32', sh, order ), 1, s, false, false ); // $ExpectType float32ndarray - sliceDimensionFrom( empty( 'complex128', sh, order ), 1, s, false, false ); // $ExpectType complex128ndarray - sliceDimensionFrom( empty( 'complex64', sh, order ), 1, s, false, false ); // $ExpectType complex64ndarray - sliceDimensionFrom( empty( 'int32', sh, order ), 1, s, false, false ); // $ExpectType int32ndarray - sliceDimensionFrom( empty( 'int16', sh, order ), 1, s, false, false ); // $ExpectType int16ndarray - sliceDimensionFrom( empty( 'int8', sh, order ), 1, s, false, false ); // $ExpectType int8ndarray - sliceDimensionFrom( empty( 'uint32', sh, order ), 1, s, false, false ); // $ExpectType uint32ndarray - sliceDimensionFrom( empty( 'uint16', sh, order ), 1, s, false, false ); // $ExpectType uint16ndarray - sliceDimensionFrom( empty( 'uint8', sh, order ), 1, s, false, false ); // $ExpectType uint8ndarray - sliceDimensionFrom( empty( 'uint8c', sh, order ), 1, s, false, false ); // $ExpectType uint8cndarray - - sliceDimensionFrom( empty( 'float64', sh, order ), 1, s, true, true ); // $ExpectType float64ndarray - sliceDimensionFrom( empty( 'float32', sh, order ), 1, s, true, true ); // $ExpectType float32ndarray - sliceDimensionFrom( empty( 'complex128', sh, order ), 1, s, true, true ); // $ExpectType complex128ndarray - sliceDimensionFrom( empty( 'complex64', sh, order ), 1, s, true, true ); // $ExpectType complex64ndarray - sliceDimensionFrom( empty( 'int32', sh, order ), 1, s, true, true ); // $ExpectType int32ndarray - sliceDimensionFrom( empty( 'int16', sh, order ), 1, s, true, true ); // $ExpectType int16ndarray - sliceDimensionFrom( empty( 'int8', sh, order ), 1, s, true, true ); // $ExpectType int8ndarray - sliceDimensionFrom( empty( 'uint32', sh, order ), 1, s, true, true ); // $ExpectType uint32ndarray - sliceDimensionFrom( empty( 'uint16', sh, order ), 1, s, true, true ); // $ExpectType uint16ndarray - sliceDimensionFrom( empty( 'uint8', sh, order ), 1, s, true, true ); // $ExpectType uint8ndarray - sliceDimensionFrom( empty( 'uint8c', sh, order ), 1, s, true, true ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const s = 0; - - sliceDimensionFrom( '10', 1, s, false, false ); // $ExpectError - sliceDimensionFrom( 10, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( false, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( true, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( null, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( [], 1, s, false, false ); // $ExpectError - sliceDimensionFrom( {}, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( ( x: number ): number => x, 1, s, false, false ); // $ExpectError - - sliceDimensionFrom( '10', 1, s, true, true ); // $ExpectError - sliceDimensionFrom( 10, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( false, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( true, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( null, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( [], 1, s, true, true ); // $ExpectError - sliceDimensionFrom( {}, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( ( x: number ): number => x, 1, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a number... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 1; - - sliceDimensionFrom( x, '5', s, false, false ); // $ExpectError - sliceDimensionFrom( x, false, s, false, false ); // $ExpectError - sliceDimensionFrom( x, true, s, false, false ); // $ExpectError - sliceDimensionFrom( x, null, s, false, false ); // $ExpectError - sliceDimensionFrom( x, undefined, s, false, false ); // $ExpectError - sliceDimensionFrom( x, [ '5' ], s, false, false ); // $ExpectError - sliceDimensionFrom( x, {}, s, false, false ); // $ExpectError - sliceDimensionFrom( x, ( x: number ): number => x, s, false, false ); // $ExpectError - - sliceDimensionFrom( x, '5', s, true, true ); // $ExpectError - sliceDimensionFrom( x, false, s, true, true ); // $ExpectError - sliceDimensionFrom( x, true, s, true, true ); // $ExpectError - sliceDimensionFrom( x, null, s, true, true ); // $ExpectError - sliceDimensionFrom( x, undefined, s, true, true ); // $ExpectError - sliceDimensionFrom( x, [ '5' ], s, true, true ); // $ExpectError - sliceDimensionFrom( x, {}, s, true, true ); // $ExpectError - sliceDimensionFrom( x, ( x: number ): number => x, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceDimensionFrom( x, 1, '5', false, false ); // $ExpectError - sliceDimensionFrom( x, 1, false, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, true, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, null, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, undefined, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, [ '5' ], false, false ); // $ExpectError - sliceDimensionFrom( x, 1, {}, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, ( x: number ): number => x, 1, false, false ); // $ExpectError - - sliceDimensionFrom( x, 1, '5', true, true ); // $ExpectError - sliceDimensionFrom( x, 1, false, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, true, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, null, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, undefined, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, [ '5' ], true, true ); // $ExpectError - sliceDimensionFrom( x, 1, {}, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, ( x: number ): number => x, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x, 1, s, '5', false ); // $ExpectError - sliceDimensionFrom( x, 1, s, 5, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, null, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, undefined, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, [ '5' ], false ); // $ExpectError - sliceDimensionFrom( x, 1, s, {}, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x, 1, s, false, '5' ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, 5 ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, null ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, undefined ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, [ '5' ] ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, {} ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x ); // $ExpectError - sliceDimensionFrom( x, 1 ); // $ExpectError - sliceDimensionFrom( x, 1, s ); // $ExpectError - sliceDimensionFrom( x, 1, s, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index b17162a..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 sliceDimensionFrom = 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 = sliceDimensionFrom( x, 1, 1, false, false ); -// 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 columns of each matrix: -var y2 = sliceDimensionFrom( x, 2, 1, false, false ); -// returns - -var a2 = ndarray2array( y2 ); -console.log( a2 ); -// => [ [ [ 1, 2 ], [ 4, 5 ], [ 7, 8 ] ], [ [ 10, 11 ], [ 13, 14 ], [ 16, 17 ] ], [ [ 19, 20 ], [ 22, 23 ], [ 25, 26 ] ] ] - -// Get the last two matrices: -var y3 = sliceDimensionFrom( x, 0, 1, false, false ); -// returns - -var a3 = ndarray2array( y3 ); -console.log( a3 ); -// => [ [ [ 9, 10, 11 ], [ 12, 13, 14 ], [ 15, 16, 17 ] ], [ [ 18, 19, 20 ], [ 21, 22, 23 ], [ 24, 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 e398649..44225a7 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..64c8acf --- /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/slice-base-args2multislice@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-ctor@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndims@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-normalize-index@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-filled@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function m(m,l,o,j,a){var p,h,v;if(0===(h=r(m)))throw new TypeError(n("1lDF7",h));if(-1===(v=i(l,h-1)))throw new RangeError(n("1lDF8",h,l));return(p=d(null,h))[v]=new e(o,null),t(m,s(p),j,a)}export{m as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..275a0ea --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport Slice from '@stdlib/slice-ctor';\nimport ndims from '@stdlib/ndarray-base-ndims';\nimport slice from '@stdlib/ndarray-base-slice';\nimport normalizeIndex from '@stdlib/ndarray-base-normalize-index';\nimport filled from '@stdlib/array-base-filled';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns a shifted view of an input ndarray along a specified dimension.\n*\n* @param {ndarray} x - input array\n* @param {integer} dim - index of dimension to slice\n* @param {integer} start - starting index (inclusive)\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {TypeError} first argument must be an ndarray having one or more dimensions\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\n*\n* @example\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceDimensionFrom( x, 0, 1, false, false );\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 sliceDimensionFrom( x, dim, start, strict, writable ) {\n\tvar args;\n\tvar N;\n\tvar d;\n\n\t// Retrieve array meta data:\n\tN = ndims( x );\n\n\t// Check whether we were provided a zero-dimensional array...\n\tif ( N === 0 ) {\n\t\tthrow new TypeError( format( '1lDF7', N ) );\n\t}\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, N-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( '1lDF8', N, dim ) );\n\t}\n\t// Define a list of slice arguments:\n\targs = filled( null, N );\n\targs[ d ] = new Slice( start, null );\n\n\t// Return a new array view:\n\treturn slice( x, args2multislice( args ), strict, writable );\n}\n\n\n// EXPORTS //\n\nexport default sliceDimensionFrom;\n"],"names":["sliceDimensionFrom","x","dim","start","strict","writable","args","N","d","ndims","TypeError","format","normalizeIndex","RangeError","filled","Slice","slice","args2multislice"],"mappings":";;wpBAyEA,SAASA,EAAoBC,EAAGC,EAAKC,EAAOC,EAAQC,GACnD,IAAIC,EACAC,EACAC,EAMJ,GAAW,KAHXD,EAAIE,EAAOR,IAIV,MAAM,IAAIS,UAAWC,EAAQ,QAASJ,IAIvC,IAAY,KADZC,EAAII,EAAgBV,EAAKK,EAAE,IAE1B,MAAM,IAAIM,WAAYF,EAAQ,QAASJ,EAAGL,IAO3C,OAJAI,EAAOQ,EAAQ,KAAMP,IACfC,GAAM,IAAIO,EAAOZ,EAAO,MAGvBa,EAAOf,EAAGgB,EAAiBX,GAAQF,EAAQC,EACnD"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index b3f97b2..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 shifted view of an input ndarray along a specified dimension. -* -* @module @stdlib/ndarray-base-slice-dimension-from -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var sliceDimensionFrom = require( '@stdlib/ndarray-base-slice-dimension-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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // 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 5dbaaef..0000000 --- a/lib/main.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var Slice = require( '@stdlib/slice-ctor' ); -var ndims = require( '@stdlib/ndarray-base-ndims' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' ); -var filled = require( '@stdlib/array-base-filled' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param {ndarray} x - input array -* @param {integer} dim - index of dimension to slice -* @param {integer} start - starting index (inclusive) -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @param {boolean} writable - boolean indicating whether a returned array should be writable -* @throws {TypeError} first argument must be an ndarray having one or more dimensions -* @throws {RangeError} dimension index exceeds the number of dimensions -* @throws {RangeError} slice 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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -function sliceDimensionFrom( x, dim, start, strict, writable ) { - var args; - var N; - var d; - - // Retrieve array meta data: - N = ndims( x ); - - // Check whether we were provided a zero-dimensional array... - if ( N === 0 ) { - throw new TypeError( format( '1lDF7', N ) ); - } - // Normalize the dimension index: - d = normalizeIndex( dim, N-1 ); - if ( d === -1 ) { - throw new RangeError( format( '1lDF8', N, dim ) ); - } - // Define a list of slice arguments: - args = filled( null, N ); - args[ d ] = new Slice( start, null ); - - // Return a new array view: - return slice( x, args2multislice( args ), strict, writable ); -} - - -// EXPORTS // - -module.exports = sliceDimensionFrom; diff --git a/package.json b/package.json index cbdca07..eb2ee55 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Return a shifted view of an input ndarray along a specific dimension.", "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,50 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-filled": "^0.2.2", - "@stdlib/ndarray-base-ndims": "^0.2.2", - "@stdlib/ndarray-base-normalize-index": "^0.2.2", - "@stdlib/ndarray-base-slice": "^0.2.2", - "@stdlib/slice-base-args2multislice": "^0.2.2", - "@stdlib/slice-ctor": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/array-typed": "^0.3.0", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-base-empty": "^0.3.0", - "@stdlib/ndarray-base-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..7e0aa9d --- /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 28703b5..0000000 --- a/test/test.js +++ /dev/null @@ -1,616 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 ndarray2array = require( '@stdlib/ndarray-to-array' ); -var baseCtor = require( '@stdlib/ndarray-base-ctor' ); -var ctor = require( '@stdlib/ndarray-ctor' ); -var sliceDimensionFrom = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sliceDimensionFrom, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a zero-dimensional array (strict=false)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error' ); - } - t.end(); - - function badValue( x ) { - return function badValue() { - sliceDimensionFrom( x, 0, 0, false, false ); - }; - } -}); - -tape( 'the function throws an error if provided a zero-dimensional array (strict=true)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error' ); - } - t.end(); - - function badValue( x ) { - return function badValue() { - sliceDimensionFrom( x, 0, 0, true, false ); - }; - } -}); - -tape( 'the function throws an error if the dimension index exceeds the number of dimensions (strict=false)', 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 ], 10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - t.throws( badValue( values[ i ], -10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - } - t.end(); - - function badValue( x, dim ) { - return function badValue() { - sliceDimensionFrom( x, dim, 0, false, false ); - }; - } -}); - -tape( 'the function throws an error if the dimension index exceeds the number of dimensions (strict=true)', 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 ], 10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - t.throws( badValue( values[ i ], -10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - } - t.end(); - - function badValue( x, dim ) { - return function badValue() { - sliceDimensionFrom( x, dim, 0, true, false ); - }; - } -}); - -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, - 20, - 20, - 20 - ]; - 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() { - sliceDimensionFrom( x, 0, s, true, false ); - }; - } -}); - -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, - 20, - 20, - 20, - 10 - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceDimensionFrom( values[ i ], 0, start[ i ], false, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), 0, 'returns expected value' ); - t.strictEqual( actual.dtype, values[ i ].dtype, 'returns expected value' ); - } - t.end(); -}); - -tape( 'in non-strict mode, the function returns an empty array when a starting index is the one more than the last index along a dimension', function test( t ) { - var actual; - var values; - var start; - var dim; - 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' } ) - ]; - - dim = [ - 0, - 1, - 0, - 1, - 4 - ]; - - start = [ - 1, - 1, - 1, - 1, - 1 - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceDimensionFrom( values[ i ], dim[ i ], start[ i ], false, false ); // eslint-disable-line max-len - 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 a shifted view of a provided input array (ndims=1)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 2, true, false ); - - 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 = sliceDimensionFrom( x, 0, -4, true, false ); - - 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)', 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 1, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 2, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, -2, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 1, 1, true, false ); - - 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 = sliceDimensionFrom( x, 1, -2, true, false ); - - 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' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=3)', 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 1, true, false ); - - 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 = sliceDimensionFrom( x, 1, 1, true, false ); - - 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 = sliceDimensionFrom( x, 2, 2, true, false ); - - 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 = sliceDimensionFrom( x, 2, -1, true, false ); - - 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' ); - t.end(); -}); - -tape( 'if a provided ndarray has a constructor supporting read-only instances, the function returns a read-only instance', function test( t ) { - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - x = new baseCtor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports returning writable views', function test( t ) { - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - x = new baseCtor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - t.end(); -}); From 949f5cae2e09733deef569bb5cc7f38f7d13cd05 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 08:25:13 +0000 Subject: [PATCH 50/92] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 2b8e198..5dbaaef 100644 --- a/lib/main.js +++ b/lib/main.js @@ -26,7 +26,7 @@ var ndims = require( '@stdlib/ndarray-base-ndims' ); var slice = require( '@stdlib/ndarray-base-slice' ); var normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' ); var filled = require( '@stdlib/array-base-filled' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -81,12 +81,12 @@ function sliceDimensionFrom( x, dim, start, strict, writable ) { // Check whether we were provided a zero-dimensional array... if ( N === 0 ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.', N ) ); + throw new TypeError( format( '1lDF7', N ) ); } // Normalize the dimension index: d = normalizeIndex( dim, N-1 ); if ( d === -1 ) { - throw new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', N, dim ) ); + throw new RangeError( format( '1lDF8', N, dim ) ); } // Define a list of slice arguments: args = filled( null, N ); diff --git a/package.json b/package.json index 20b83b6..f92cdbb 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/ndarray-base-slice": "^0.2.2", "@stdlib/slice-base-args2multislice": "^0.2.2", "@stdlib/slice-ctor": "^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 b69726423ba3e7c39788b66f80839634d44691a6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 12:52:31 +0000 Subject: [PATCH 51/92] Remove files --- index.d.ts | 534 ------ index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5381 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 44225a7..0000000 --- a/index.d.ts +++ /dev/null @@ -1,534 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceDimensionFrom( x: float64ndarray, dim: number, start: number, strict: boolean, writable: boolean ): float64ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceDimensionFrom( x: float32ndarray, dim: number, start: number, strict: boolean, writable: boolean ): float32ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: int32ndarray, dim: number, start: number, strict: boolean, writable: boolean ): int32ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: int16ndarray, dim: number, start: number, strict: boolean, writable: boolean ): int16ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: int8ndarray, dim: number, start: number, strict: boolean, writable: boolean ): int8ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint32ndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint32ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint16ndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint16ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint8ndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint8ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint8cndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint8cndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceDimensionFrom( x: complex128ndarray, dim: number, start: number, strict: boolean, writable: boolean ): complex128ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceDimensionFrom( x: complex64ndarray, dim: number, start: number, strict: boolean, writable: boolean ): complex64ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: genericndarray, dim: number, start: number, strict: boolean, writable: boolean ): genericndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: typedndarray, dim: number, start: number, strict: boolean, writable: boolean ): typedndarray; - - -// EXPORTS // - -export = sliceDimensionFrom; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 64c8acf..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/slice-base-args2multislice@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-ctor@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndims@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-normalize-index@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-filled@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function m(m,l,o,j,a){var p,h,v;if(0===(h=r(m)))throw new TypeError(n("1lDF7",h));if(-1===(v=i(l,h-1)))throw new RangeError(n("1lDF8",h,l));return(p=d(null,h))[v]=new e(o,null),t(m,s(p),j,a)}export{m as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 275a0ea..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport Slice from '@stdlib/slice-ctor';\nimport ndims from '@stdlib/ndarray-base-ndims';\nimport slice from '@stdlib/ndarray-base-slice';\nimport normalizeIndex from '@stdlib/ndarray-base-normalize-index';\nimport filled from '@stdlib/array-base-filled';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns a shifted view of an input ndarray along a specified dimension.\n*\n* @param {ndarray} x - input array\n* @param {integer} dim - index of dimension to slice\n* @param {integer} start - starting index (inclusive)\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {TypeError} first argument must be an ndarray having one or more dimensions\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\n*\n* @example\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceDimensionFrom( x, 0, 1, false, false );\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 sliceDimensionFrom( x, dim, start, strict, writable ) {\n\tvar args;\n\tvar N;\n\tvar d;\n\n\t// Retrieve array meta data:\n\tN = ndims( x );\n\n\t// Check whether we were provided a zero-dimensional array...\n\tif ( N === 0 ) {\n\t\tthrow new TypeError( format( '1lDF7', N ) );\n\t}\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, N-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( '1lDF8', N, dim ) );\n\t}\n\t// Define a list of slice arguments:\n\targs = filled( null, N );\n\targs[ d ] = new Slice( start, null );\n\n\t// Return a new array view:\n\treturn slice( x, args2multislice( args ), strict, writable );\n}\n\n\n// EXPORTS //\n\nexport default sliceDimensionFrom;\n"],"names":["sliceDimensionFrom","x","dim","start","strict","writable","args","N","d","ndims","TypeError","format","normalizeIndex","RangeError","filled","Slice","slice","args2multislice"],"mappings":";;wpBAyEA,SAASA,EAAoBC,EAAGC,EAAKC,EAAOC,EAAQC,GACnD,IAAIC,EACAC,EACAC,EAMJ,GAAW,KAHXD,EAAIE,EAAOR,IAIV,MAAM,IAAIS,UAAWC,EAAQ,QAASJ,IAIvC,IAAY,KADZC,EAAII,EAAgBV,EAAKK,EAAE,IAE1B,MAAM,IAAIM,WAAYF,EAAQ,QAASJ,EAAGL,IAO3C,OAJAI,EAAOQ,EAAQ,KAAMP,IACfC,GAAM,IAAIO,EAAOZ,EAAO,MAGvBa,EAAOf,EAAGgB,EAAiBX,GAAQF,EAAQC,EACnD"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 7e0aa9d..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 6d0177d622d95e12afb6cbf17e47908b2aa085e1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 12:52:52 +0000 Subject: [PATCH 52/92] 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 | 104 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 45 +- SECURITY.md | 5 - benchmark/benchmark.js | 681 --- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 49 - docs/types/test.ts | 164 - 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 | 102 - package.json | 71 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 616 --- 43 files changed, 4868 insertions(+), 5230 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 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 232a12e..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-09-01T06:19:53.323Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 05d1840..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-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 ced95ae..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-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 60a2bb4..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: '38 14 * * 5' - - # 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 + + ```
@@ -202,7 +193,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]. diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 8a6b7a2..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,681 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 sliceDimensionFrom = require( './../lib' ); - - -// MAIN // - -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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2 ], { 'dtype': 'float64' } ), - empty( [ 2 ], { 'dtype': 'float32' } ), - empty( [ 2 ], { 'dtype': 'int32' } ), - empty( [ 2 ], { 'dtype': 'complex128' } ), - empty( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== '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 9543fcd..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-from" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-from -[production-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-slice-dimension-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 2ab577a..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import sliceDimensionFrom from '../docs/types/index'; -export = sliceDimensionFrom; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 2e11f06..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var l=function(i,r){return function(){return r||i((r={exports:{}}).exports,r),r.exports}};var o=l(function(p,u){"use strict";var v=require("@stdlib/slice-base-args2multislice"),c=require("@stdlib/slice-ctor"),f=require("@stdlib/ndarray-base-ndims"),q=require("@stdlib/ndarray-base-slice"),g=require("@stdlib/ndarray-base-normalize-index"),w=require("@stdlib/array-base-filled"),s=require("@stdlib/string-format");function b(i,r,m,t,d){var n,e,a;if(e=f(i),e===0)throw new TypeError(s("invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.",e));if(a=g(r,e-1),a===-1)throw new RangeError(s("invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.",e,r));return n=w(null,e),n[a]=new c(m,null),q(i,v(n),t,d)}u.exports=b});var h=o();module.exports=h; -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index a75b3e0..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar args2multislice = require( '@stdlib/slice-base-args2multislice' );\nvar Slice = require( '@stdlib/slice-ctor' );\nvar ndims = require( '@stdlib/ndarray-base-ndims' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' );\nvar filled = require( '@stdlib/array-base-filled' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns a shifted view of an input ndarray along a specified dimension.\n*\n* @param {ndarray} x - input array\n* @param {integer} dim - index of dimension to slice\n* @param {integer} start - starting index (inclusive)\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {TypeError} first argument must be an ndarray having one or more dimensions\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceDimensionFrom( x, 0, 1, false, false );\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 sliceDimensionFrom( x, dim, start, strict, writable ) {\n\tvar args;\n\tvar N;\n\tvar d;\n\n\t// Retrieve array meta data:\n\tN = ndims( x );\n\n\t// Check whether we were provided a zero-dimensional array...\n\tif ( N === 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.', N ) );\n\t}\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, N-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', N, dim ) );\n\t}\n\t// Define a list of slice arguments:\n\targs = filled( null, N );\n\targs[ d ] = new Slice( start, null );\n\n\t// Return a new array view:\n\treturn slice( x, args2multislice( args ), strict, writable );\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceDimensionFrom;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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 shifted view of an input ndarray along a specified dimension.\n*\n* @module @stdlib/ndarray-base-slice-dimension-from\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var sliceDimensionFrom = require( '@stdlib/ndarray-base-slice-dimension-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 = sliceDimensionFrom( x, 0, 1, false, false );\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,EAAkB,QAAS,oCAAqC,EAChEC,EAAQ,QAAS,oBAAqB,EACtCC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAiB,QAAS,sCAAuC,EACjEC,EAAS,QAAS,2BAA4B,EAC9CC,EAAS,QAAS,uBAAwB,EA6C9C,SAASC,EAAoBC,EAAGC,EAAKC,EAAOC,EAAQC,EAAW,CAC9D,IAAIC,EACAC,EACAC,EAMJ,GAHAD,EAAIZ,EAAOM,CAAE,EAGRM,IAAM,EACV,MAAM,IAAI,UAAWR,EAAQ,+GAAgHQ,CAAE,CAAE,EAIlJ,GADAC,EAAIX,EAAgBK,EAAKK,EAAE,CAAE,EACxBC,IAAM,GACV,MAAM,IAAI,WAAYT,EAAQ,6GAA8GQ,EAAGL,CAAI,CAAE,EAGtJ,OAAAI,EAAOR,EAAQ,KAAMS,CAAE,EACvBD,EAAME,CAAE,EAAI,IAAId,EAAOS,EAAO,IAAK,EAG5BP,EAAOK,EAAGR,EAAiBa,CAAK,EAAGF,EAAQC,CAAS,CAC5D,CAKAb,EAAO,QAAUQ,IC7CjB,IAAIS,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "args2multislice", "Slice", "ndims", "slice", "normalizeIndex", "filled", "format", "sliceDimensionFrom", "x", "dim", "start", "strict", "writable", "args", "N", "d", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ffc1f03..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,49 +0,0 @@ - -{{alias}}( x, dim, start, strict, writable ) - Returns a shifted view of an input ndarray along a specified dimension. - - Parameters - ---------- - x: ndarray - Input array. - - dim: integer - Index of dimension to slice. If less than zero, the index is resolved - relative to the last dimension, with the last dimension corresponding to - the value `-1`. - - start: integer - Starting index (inclusive). If less than zero, the corresponding element - along the specified dimension is resolved relative to the last element - along that dimension. For negative integers, the last element - corresponds to the value `-1`. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - writable: boolean - Boolean indicating whether a returned ndarray should be writable. This - parameter only applies to ndarray constructors which support read-only - instances. - - Returns - ------- - out: ndarray - Output array view. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > x.shape - [ 2, 2 ] - > var y = {{alias}}( x, 1, 1, false, false ) - - > 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 9dfeaf3..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,164 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sliceDimensionFrom = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = 0; - - sliceDimensionFrom( empty( 'float64', sh, order ), 1, s, false, false ); // $ExpectType float64ndarray - sliceDimensionFrom( empty( 'float32', sh, order ), 1, s, false, false ); // $ExpectType float32ndarray - sliceDimensionFrom( empty( 'complex128', sh, order ), 1, s, false, false ); // $ExpectType complex128ndarray - sliceDimensionFrom( empty( 'complex64', sh, order ), 1, s, false, false ); // $ExpectType complex64ndarray - sliceDimensionFrom( empty( 'int32', sh, order ), 1, s, false, false ); // $ExpectType int32ndarray - sliceDimensionFrom( empty( 'int16', sh, order ), 1, s, false, false ); // $ExpectType int16ndarray - sliceDimensionFrom( empty( 'int8', sh, order ), 1, s, false, false ); // $ExpectType int8ndarray - sliceDimensionFrom( empty( 'uint32', sh, order ), 1, s, false, false ); // $ExpectType uint32ndarray - sliceDimensionFrom( empty( 'uint16', sh, order ), 1, s, false, false ); // $ExpectType uint16ndarray - sliceDimensionFrom( empty( 'uint8', sh, order ), 1, s, false, false ); // $ExpectType uint8ndarray - sliceDimensionFrom( empty( 'uint8c', sh, order ), 1, s, false, false ); // $ExpectType uint8cndarray - - sliceDimensionFrom( empty( 'float64', sh, order ), 1, s, true, true ); // $ExpectType float64ndarray - sliceDimensionFrom( empty( 'float32', sh, order ), 1, s, true, true ); // $ExpectType float32ndarray - sliceDimensionFrom( empty( 'complex128', sh, order ), 1, s, true, true ); // $ExpectType complex128ndarray - sliceDimensionFrom( empty( 'complex64', sh, order ), 1, s, true, true ); // $ExpectType complex64ndarray - sliceDimensionFrom( empty( 'int32', sh, order ), 1, s, true, true ); // $ExpectType int32ndarray - sliceDimensionFrom( empty( 'int16', sh, order ), 1, s, true, true ); // $ExpectType int16ndarray - sliceDimensionFrom( empty( 'int8', sh, order ), 1, s, true, true ); // $ExpectType int8ndarray - sliceDimensionFrom( empty( 'uint32', sh, order ), 1, s, true, true ); // $ExpectType uint32ndarray - sliceDimensionFrom( empty( 'uint16', sh, order ), 1, s, true, true ); // $ExpectType uint16ndarray - sliceDimensionFrom( empty( 'uint8', sh, order ), 1, s, true, true ); // $ExpectType uint8ndarray - sliceDimensionFrom( empty( 'uint8c', sh, order ), 1, s, true, true ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const s = 0; - - sliceDimensionFrom( '10', 1, s, false, false ); // $ExpectError - sliceDimensionFrom( 10, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( false, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( true, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( null, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( [], 1, s, false, false ); // $ExpectError - sliceDimensionFrom( {}, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( ( x: number ): number => x, 1, s, false, false ); // $ExpectError - - sliceDimensionFrom( '10', 1, s, true, true ); // $ExpectError - sliceDimensionFrom( 10, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( false, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( true, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( null, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( [], 1, s, true, true ); // $ExpectError - sliceDimensionFrom( {}, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( ( x: number ): number => x, 1, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a number... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 1; - - sliceDimensionFrom( x, '5', s, false, false ); // $ExpectError - sliceDimensionFrom( x, false, s, false, false ); // $ExpectError - sliceDimensionFrom( x, true, s, false, false ); // $ExpectError - sliceDimensionFrom( x, null, s, false, false ); // $ExpectError - sliceDimensionFrom( x, undefined, s, false, false ); // $ExpectError - sliceDimensionFrom( x, [ '5' ], s, false, false ); // $ExpectError - sliceDimensionFrom( x, {}, s, false, false ); // $ExpectError - sliceDimensionFrom( x, ( x: number ): number => x, s, false, false ); // $ExpectError - - sliceDimensionFrom( x, '5', s, true, true ); // $ExpectError - sliceDimensionFrom( x, false, s, true, true ); // $ExpectError - sliceDimensionFrom( x, true, s, true, true ); // $ExpectError - sliceDimensionFrom( x, null, s, true, true ); // $ExpectError - sliceDimensionFrom( x, undefined, s, true, true ); // $ExpectError - sliceDimensionFrom( x, [ '5' ], s, true, true ); // $ExpectError - sliceDimensionFrom( x, {}, s, true, true ); // $ExpectError - sliceDimensionFrom( x, ( x: number ): number => x, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceDimensionFrom( x, 1, '5', false, false ); // $ExpectError - sliceDimensionFrom( x, 1, false, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, true, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, null, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, undefined, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, [ '5' ], false, false ); // $ExpectError - sliceDimensionFrom( x, 1, {}, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, ( x: number ): number => x, 1, false, false ); // $ExpectError - - sliceDimensionFrom( x, 1, '5', true, true ); // $ExpectError - sliceDimensionFrom( x, 1, false, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, true, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, null, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, undefined, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, [ '5' ], true, true ); // $ExpectError - sliceDimensionFrom( x, 1, {}, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, ( x: number ): number => x, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x, 1, s, '5', false ); // $ExpectError - sliceDimensionFrom( x, 1, s, 5, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, null, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, undefined, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, [ '5' ], false ); // $ExpectError - sliceDimensionFrom( x, 1, s, {}, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x, 1, s, false, '5' ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, 5 ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, null ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, undefined ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, [ '5' ] ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, {} ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x ); // $ExpectError - sliceDimensionFrom( x, 1 ); // $ExpectError - sliceDimensionFrom( x, 1, s ); // $ExpectError - sliceDimensionFrom( x, 1, s, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index b17162a..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 sliceDimensionFrom = 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 = sliceDimensionFrom( x, 1, 1, false, false ); -// 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 columns of each matrix: -var y2 = sliceDimensionFrom( x, 2, 1, false, false ); -// returns - -var a2 = ndarray2array( y2 ); -console.log( a2 ); -// => [ [ [ 1, 2 ], [ 4, 5 ], [ 7, 8 ] ], [ [ 10, 11 ], [ 13, 14 ], [ 16, 17 ] ], [ [ 19, 20 ], [ 22, 23 ], [ 25, 26 ] ] ] - -// Get the last two matrices: -var y3 = sliceDimensionFrom( x, 0, 1, false, false ); -// returns - -var a3 = ndarray2array( y3 ); -console.log( a3 ); -// => [ [ [ 9, 10, 11 ], [ 12, 13, 14 ], [ 15, 16, 17 ] ], [ [ 18, 19, 20 ], [ 21, 22, 23 ], [ 24, 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 e398649..44225a7 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..64c8acf --- /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/slice-base-args2multislice@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-ctor@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndims@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-normalize-index@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-filled@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function m(m,l,o,j,a){var p,h,v;if(0===(h=r(m)))throw new TypeError(n("1lDF7",h));if(-1===(v=i(l,h-1)))throw new RangeError(n("1lDF8",h,l));return(p=d(null,h))[v]=new e(o,null),t(m,s(p),j,a)}export{m as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..275a0ea --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport Slice from '@stdlib/slice-ctor';\nimport ndims from '@stdlib/ndarray-base-ndims';\nimport slice from '@stdlib/ndarray-base-slice';\nimport normalizeIndex from '@stdlib/ndarray-base-normalize-index';\nimport filled from '@stdlib/array-base-filled';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns a shifted view of an input ndarray along a specified dimension.\n*\n* @param {ndarray} x - input array\n* @param {integer} dim - index of dimension to slice\n* @param {integer} start - starting index (inclusive)\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {TypeError} first argument must be an ndarray having one or more dimensions\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\n*\n* @example\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceDimensionFrom( x, 0, 1, false, false );\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 sliceDimensionFrom( x, dim, start, strict, writable ) {\n\tvar args;\n\tvar N;\n\tvar d;\n\n\t// Retrieve array meta data:\n\tN = ndims( x );\n\n\t// Check whether we were provided a zero-dimensional array...\n\tif ( N === 0 ) {\n\t\tthrow new TypeError( format( '1lDF7', N ) );\n\t}\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, N-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( '1lDF8', N, dim ) );\n\t}\n\t// Define a list of slice arguments:\n\targs = filled( null, N );\n\targs[ d ] = new Slice( start, null );\n\n\t// Return a new array view:\n\treturn slice( x, args2multislice( args ), strict, writable );\n}\n\n\n// EXPORTS //\n\nexport default sliceDimensionFrom;\n"],"names":["sliceDimensionFrom","x","dim","start","strict","writable","args","N","d","ndims","TypeError","format","normalizeIndex","RangeError","filled","Slice","slice","args2multislice"],"mappings":";;wpBAyEA,SAASA,EAAoBC,EAAGC,EAAKC,EAAOC,EAAQC,GACnD,IAAIC,EACAC,EACAC,EAMJ,GAAW,KAHXD,EAAIE,EAAOR,IAIV,MAAM,IAAIS,UAAWC,EAAQ,QAASJ,IAIvC,IAAY,KADZC,EAAII,EAAgBV,EAAKK,EAAE,IAE1B,MAAM,IAAIM,WAAYF,EAAQ,QAASJ,EAAGL,IAO3C,OAJAI,EAAOQ,EAAQ,KAAMP,IACfC,GAAM,IAAIO,EAAOZ,EAAO,MAGvBa,EAAOf,EAAGgB,EAAiBX,GAAQF,EAAQC,EACnD"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index b3f97b2..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 shifted view of an input ndarray along a specified dimension. -* -* @module @stdlib/ndarray-base-slice-dimension-from -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var sliceDimensionFrom = require( '@stdlib/ndarray-base-slice-dimension-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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // 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 5dbaaef..0000000 --- a/lib/main.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var Slice = require( '@stdlib/slice-ctor' ); -var ndims = require( '@stdlib/ndarray-base-ndims' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' ); -var filled = require( '@stdlib/array-base-filled' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param {ndarray} x - input array -* @param {integer} dim - index of dimension to slice -* @param {integer} start - starting index (inclusive) -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @param {boolean} writable - boolean indicating whether a returned array should be writable -* @throws {TypeError} first argument must be an ndarray having one or more dimensions -* @throws {RangeError} dimension index exceeds the number of dimensions -* @throws {RangeError} slice 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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -function sliceDimensionFrom( x, dim, start, strict, writable ) { - var args; - var N; - var d; - - // Retrieve array meta data: - N = ndims( x ); - - // Check whether we were provided a zero-dimensional array... - if ( N === 0 ) { - throw new TypeError( format( '1lDF7', N ) ); - } - // Normalize the dimension index: - d = normalizeIndex( dim, N-1 ); - if ( d === -1 ) { - throw new RangeError( format( '1lDF8', N, dim ) ); - } - // Define a list of slice arguments: - args = filled( null, N ); - args[ d ] = new Slice( start, null ); - - // Return a new array view: - return slice( x, args2multislice( args ), strict, writable ); -} - - -// EXPORTS // - -module.exports = sliceDimensionFrom; diff --git a/package.json b/package.json index f92cdbb..eb2ee55 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Return a shifted view of an input ndarray along a specific dimension.", "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,50 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-filled": "^0.2.2", - "@stdlib/ndarray-base-ndims": "^0.2.2", - "@stdlib/ndarray-base-normalize-index": "^0.2.2", - "@stdlib/ndarray-base-slice": "^0.2.2", - "@stdlib/slice-base-args2multislice": "^0.2.2", - "@stdlib/slice-ctor": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/array-typed": "^0.3.0", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-base-empty": "^0.3.0", - "@stdlib/ndarray-base-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..7e0aa9d --- /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 28703b5..0000000 --- a/test/test.js +++ /dev/null @@ -1,616 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 ndarray2array = require( '@stdlib/ndarray-to-array' ); -var baseCtor = require( '@stdlib/ndarray-base-ctor' ); -var ctor = require( '@stdlib/ndarray-ctor' ); -var sliceDimensionFrom = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sliceDimensionFrom, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a zero-dimensional array (strict=false)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error' ); - } - t.end(); - - function badValue( x ) { - return function badValue() { - sliceDimensionFrom( x, 0, 0, false, false ); - }; - } -}); - -tape( 'the function throws an error if provided a zero-dimensional array (strict=true)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error' ); - } - t.end(); - - function badValue( x ) { - return function badValue() { - sliceDimensionFrom( x, 0, 0, true, false ); - }; - } -}); - -tape( 'the function throws an error if the dimension index exceeds the number of dimensions (strict=false)', 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 ], 10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - t.throws( badValue( values[ i ], -10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - } - t.end(); - - function badValue( x, dim ) { - return function badValue() { - sliceDimensionFrom( x, dim, 0, false, false ); - }; - } -}); - -tape( 'the function throws an error if the dimension index exceeds the number of dimensions (strict=true)', 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 ], 10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - t.throws( badValue( values[ i ], -10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - } - t.end(); - - function badValue( x, dim ) { - return function badValue() { - sliceDimensionFrom( x, dim, 0, true, false ); - }; - } -}); - -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, - 20, - 20, - 20 - ]; - 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() { - sliceDimensionFrom( x, 0, s, true, false ); - }; - } -}); - -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, - 20, - 20, - 20, - 10 - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceDimensionFrom( values[ i ], 0, start[ i ], false, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), 0, 'returns expected value' ); - t.strictEqual( actual.dtype, values[ i ].dtype, 'returns expected value' ); - } - t.end(); -}); - -tape( 'in non-strict mode, the function returns an empty array when a starting index is the one more than the last index along a dimension', function test( t ) { - var actual; - var values; - var start; - var dim; - 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' } ) - ]; - - dim = [ - 0, - 1, - 0, - 1, - 4 - ]; - - start = [ - 1, - 1, - 1, - 1, - 1 - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceDimensionFrom( values[ i ], dim[ i ], start[ i ], false, false ); // eslint-disable-line max-len - 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 a shifted view of a provided input array (ndims=1)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 2, true, false ); - - 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 = sliceDimensionFrom( x, 0, -4, true, false ); - - 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)', 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 1, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 2, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, -2, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 1, 1, true, false ); - - 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 = sliceDimensionFrom( x, 1, -2, true, false ); - - 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' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=3)', 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 1, true, false ); - - 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 = sliceDimensionFrom( x, 1, 1, true, false ); - - 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 = sliceDimensionFrom( x, 2, 2, true, false ); - - 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 = sliceDimensionFrom( x, 2, -1, true, false ); - - 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' ); - t.end(); -}); - -tape( 'if a provided ndarray has a constructor supporting read-only instances, the function returns a read-only instance', function test( t ) { - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - x = new baseCtor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports returning writable views', function test( t ) { - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - x = new baseCtor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - t.end(); -}); From c3052aee50ac2ec674cf562bf8c27bb9e23a1b78 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 22 Sep 2024 08:06:09 +0000 Subject: [PATCH 53/92] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 54bb1c2..50e4c67 100644 --- a/lib/main.js +++ b/lib/main.js @@ -26,7 +26,7 @@ var ndims = require( '@stdlib/ndarray-base-ndims' ); var slice = require( '@stdlib/ndarray-base-slice' ); var normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' ); var nulls = require( '@stdlib/array-base-nulls' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -81,12 +81,12 @@ function sliceDimensionFrom( x, dim, start, strict, writable ) { // Check whether we were provided a zero-dimensional array... if ( N === 0 ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.', N ) ); + throw new TypeError( format( '1lDF7', N ) ); } // Normalize the dimension index: d = normalizeIndex( dim, N-1 ); if ( d === -1 ) { - throw new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', N, dim ) ); + throw new RangeError( format( '1lDF8', N, dim ) ); } // Define a list of slice arguments: args = nulls( N ); diff --git a/package.json b/package.json index 524b4e6..2e535c3 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/ndarray-base-slice": "^0.2.2", "@stdlib/slice-base-args2multislice": "^0.2.2", "@stdlib/slice-ctor": "^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 e7e64e238908adf1b5d8122291065f9452298429 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 22 Sep 2024 08:08:05 +0000 Subject: [PATCH 54/92] Remove files --- index.d.ts | 534 ------ index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5381 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 44225a7..0000000 --- a/index.d.ts +++ /dev/null @@ -1,534 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceDimensionFrom( x: float64ndarray, dim: number, start: number, strict: boolean, writable: boolean ): float64ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceDimensionFrom( x: float32ndarray, dim: number, start: number, strict: boolean, writable: boolean ): float32ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: int32ndarray, dim: number, start: number, strict: boolean, writable: boolean ): int32ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: int16ndarray, dim: number, start: number, strict: boolean, writable: boolean ): int16ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: int8ndarray, dim: number, start: number, strict: boolean, writable: boolean ): int8ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint32ndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint32ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint16ndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint16ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint8ndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint8ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint8cndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint8cndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceDimensionFrom( x: complex128ndarray, dim: number, start: number, strict: boolean, writable: boolean ): complex128ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceDimensionFrom( x: complex64ndarray, dim: number, start: number, strict: boolean, writable: boolean ): complex64ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: genericndarray, dim: number, start: number, strict: boolean, writable: boolean ): genericndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: typedndarray, dim: number, start: number, strict: boolean, writable: boolean ): typedndarray; - - -// EXPORTS // - -export = sliceDimensionFrom; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 64c8acf..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/slice-base-args2multislice@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-ctor@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndims@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-normalize-index@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-filled@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function m(m,l,o,j,a){var p,h,v;if(0===(h=r(m)))throw new TypeError(n("1lDF7",h));if(-1===(v=i(l,h-1)))throw new RangeError(n("1lDF8",h,l));return(p=d(null,h))[v]=new e(o,null),t(m,s(p),j,a)}export{m as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 275a0ea..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport Slice from '@stdlib/slice-ctor';\nimport ndims from '@stdlib/ndarray-base-ndims';\nimport slice from '@stdlib/ndarray-base-slice';\nimport normalizeIndex from '@stdlib/ndarray-base-normalize-index';\nimport filled from '@stdlib/array-base-filled';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns a shifted view of an input ndarray along a specified dimension.\n*\n* @param {ndarray} x - input array\n* @param {integer} dim - index of dimension to slice\n* @param {integer} start - starting index (inclusive)\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {TypeError} first argument must be an ndarray having one or more dimensions\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\n*\n* @example\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceDimensionFrom( x, 0, 1, false, false );\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 sliceDimensionFrom( x, dim, start, strict, writable ) {\n\tvar args;\n\tvar N;\n\tvar d;\n\n\t// Retrieve array meta data:\n\tN = ndims( x );\n\n\t// Check whether we were provided a zero-dimensional array...\n\tif ( N === 0 ) {\n\t\tthrow new TypeError( format( '1lDF7', N ) );\n\t}\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, N-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( '1lDF8', N, dim ) );\n\t}\n\t// Define a list of slice arguments:\n\targs = filled( null, N );\n\targs[ d ] = new Slice( start, null );\n\n\t// Return a new array view:\n\treturn slice( x, args2multislice( args ), strict, writable );\n}\n\n\n// EXPORTS //\n\nexport default sliceDimensionFrom;\n"],"names":["sliceDimensionFrom","x","dim","start","strict","writable","args","N","d","ndims","TypeError","format","normalizeIndex","RangeError","filled","Slice","slice","args2multislice"],"mappings":";;wpBAyEA,SAASA,EAAoBC,EAAGC,EAAKC,EAAOC,EAAQC,GACnD,IAAIC,EACAC,EACAC,EAMJ,GAAW,KAHXD,EAAIE,EAAOR,IAIV,MAAM,IAAIS,UAAWC,EAAQ,QAASJ,IAIvC,IAAY,KADZC,EAAII,EAAgBV,EAAKK,EAAE,IAE1B,MAAM,IAAIM,WAAYF,EAAQ,QAASJ,EAAGL,IAO3C,OAJAI,EAAOQ,EAAQ,KAAMP,IACfC,GAAM,IAAIO,EAAOZ,EAAO,MAGvBa,EAAOf,EAAGgB,EAAiBX,GAAQF,EAAQC,EACnD"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 7e0aa9d..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 1af2d6bf4e5bfe1225bd296e100b39624896eb8b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 22 Sep 2024 08:08:24 +0000 Subject: [PATCH 55/92] 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 | 138 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 45 +- SECURITY.md | 5 - benchmark/benchmark.js | 681 --- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 49 - docs/types/test.ts | 164 - 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 | 102 - package.json | 71 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 616 --- 42 files changed, 4868 insertions(+), 5263 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 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 05d1840..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-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 ced95ae..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-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 60a2bb4..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: '38 14 * * 5' - - # 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 + + ```
@@ -202,7 +193,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]. diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 8a6b7a2..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,681 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 sliceDimensionFrom = require( './../lib' ); - - -// MAIN // - -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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2 ], { 'dtype': 'float64' } ), - empty( [ 2 ], { 'dtype': 'float32' } ), - empty( [ 2 ], { 'dtype': 'int32' } ), - empty( [ 2 ], { 'dtype': 'complex128' } ), - empty( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== '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 9543fcd..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-from" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-from -[production-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-slice-dimension-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 2ab577a..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import sliceDimensionFrom from '../docs/types/index'; -export = sliceDimensionFrom; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 2f5466d..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var v=function(i,r){return function(){return r||i((r={exports:{}}).exports,r),r.exports}};var o=v(function(p,u){"use strict";var l=require("@stdlib/slice-base-args2multislice"),c=require("@stdlib/slice-ctor"),q=require("@stdlib/ndarray-base-ndims"),f=require("@stdlib/ndarray-base-slice"),g=require("@stdlib/ndarray-base-normalize-index"),w=require("@stdlib/array-base-nulls"),s=require("@stdlib/string-format");function b(i,r,m,t,d){var n,e,a;if(e=q(i),e===0)throw new TypeError(s("invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.",e));if(a=g(r,e-1),a===-1)throw new RangeError(s("invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.",e,r));return n=w(e),n[a]=new c(m,null),f(i,l(n),t,d)}u.exports=b});var h=o();module.exports=h; -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 19dddde..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar args2multislice = require( '@stdlib/slice-base-args2multislice' );\nvar Slice = require( '@stdlib/slice-ctor' );\nvar ndims = require( '@stdlib/ndarray-base-ndims' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' );\nvar nulls = require( '@stdlib/array-base-nulls' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns a shifted view of an input ndarray along a specified dimension.\n*\n* @param {ndarray} x - input array\n* @param {integer} dim - index of dimension to slice\n* @param {integer} start - starting index (inclusive)\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {TypeError} first argument must be an ndarray having one or more dimensions\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceDimensionFrom( x, 0, 1, false, false );\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 sliceDimensionFrom( x, dim, start, strict, writable ) {\n\tvar args;\n\tvar N;\n\tvar d;\n\n\t// Retrieve array meta data:\n\tN = ndims( x );\n\n\t// Check whether we were provided a zero-dimensional array...\n\tif ( N === 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.', N ) );\n\t}\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, N-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', N, dim ) );\n\t}\n\t// Define a list of slice arguments:\n\targs = nulls( N );\n\targs[ d ] = new Slice( start, null );\n\n\t// Return a new array view:\n\treturn slice( x, args2multislice( args ), strict, writable );\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceDimensionFrom;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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 shifted view of an input ndarray along a specified dimension.\n*\n* @module @stdlib/ndarray-base-slice-dimension-from\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var sliceDimensionFrom = require( '@stdlib/ndarray-base-slice-dimension-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 = sliceDimensionFrom( x, 0, 1, false, false );\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,EAAkB,QAAS,oCAAqC,EAChEC,EAAQ,QAAS,oBAAqB,EACtCC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAiB,QAAS,sCAAuC,EACjEC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAS,QAAS,uBAAwB,EA6C9C,SAASC,EAAoBC,EAAGC,EAAKC,EAAOC,EAAQC,EAAW,CAC9D,IAAIC,EACAC,EACAC,EAMJ,GAHAD,EAAIZ,EAAOM,CAAE,EAGRM,IAAM,EACV,MAAM,IAAI,UAAWR,EAAQ,+GAAgHQ,CAAE,CAAE,EAIlJ,GADAC,EAAIX,EAAgBK,EAAKK,EAAE,CAAE,EACxBC,IAAM,GACV,MAAM,IAAI,WAAYT,EAAQ,6GAA8GQ,EAAGL,CAAI,CAAE,EAGtJ,OAAAI,EAAOR,EAAOS,CAAE,EAChBD,EAAME,CAAE,EAAI,IAAId,EAAOS,EAAO,IAAK,EAG5BP,EAAOK,EAAGR,EAAiBa,CAAK,EAAGF,EAAQC,CAAS,CAC5D,CAKAb,EAAO,QAAUQ,IC7CjB,IAAIS,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "args2multislice", "Slice", "ndims", "slice", "normalizeIndex", "nulls", "format", "sliceDimensionFrom", "x", "dim", "start", "strict", "writable", "args", "N", "d", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ffc1f03..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,49 +0,0 @@ - -{{alias}}( x, dim, start, strict, writable ) - Returns a shifted view of an input ndarray along a specified dimension. - - Parameters - ---------- - x: ndarray - Input array. - - dim: integer - Index of dimension to slice. If less than zero, the index is resolved - relative to the last dimension, with the last dimension corresponding to - the value `-1`. - - start: integer - Starting index (inclusive). If less than zero, the corresponding element - along the specified dimension is resolved relative to the last element - along that dimension. For negative integers, the last element - corresponds to the value `-1`. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - writable: boolean - Boolean indicating whether a returned ndarray should be writable. This - parameter only applies to ndarray constructors which support read-only - instances. - - Returns - ------- - out: ndarray - Output array view. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > x.shape - [ 2, 2 ] - > var y = {{alias}}( x, 1, 1, false, false ) - - > 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 9dfeaf3..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,164 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sliceDimensionFrom = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = 0; - - sliceDimensionFrom( empty( 'float64', sh, order ), 1, s, false, false ); // $ExpectType float64ndarray - sliceDimensionFrom( empty( 'float32', sh, order ), 1, s, false, false ); // $ExpectType float32ndarray - sliceDimensionFrom( empty( 'complex128', sh, order ), 1, s, false, false ); // $ExpectType complex128ndarray - sliceDimensionFrom( empty( 'complex64', sh, order ), 1, s, false, false ); // $ExpectType complex64ndarray - sliceDimensionFrom( empty( 'int32', sh, order ), 1, s, false, false ); // $ExpectType int32ndarray - sliceDimensionFrom( empty( 'int16', sh, order ), 1, s, false, false ); // $ExpectType int16ndarray - sliceDimensionFrom( empty( 'int8', sh, order ), 1, s, false, false ); // $ExpectType int8ndarray - sliceDimensionFrom( empty( 'uint32', sh, order ), 1, s, false, false ); // $ExpectType uint32ndarray - sliceDimensionFrom( empty( 'uint16', sh, order ), 1, s, false, false ); // $ExpectType uint16ndarray - sliceDimensionFrom( empty( 'uint8', sh, order ), 1, s, false, false ); // $ExpectType uint8ndarray - sliceDimensionFrom( empty( 'uint8c', sh, order ), 1, s, false, false ); // $ExpectType uint8cndarray - - sliceDimensionFrom( empty( 'float64', sh, order ), 1, s, true, true ); // $ExpectType float64ndarray - sliceDimensionFrom( empty( 'float32', sh, order ), 1, s, true, true ); // $ExpectType float32ndarray - sliceDimensionFrom( empty( 'complex128', sh, order ), 1, s, true, true ); // $ExpectType complex128ndarray - sliceDimensionFrom( empty( 'complex64', sh, order ), 1, s, true, true ); // $ExpectType complex64ndarray - sliceDimensionFrom( empty( 'int32', sh, order ), 1, s, true, true ); // $ExpectType int32ndarray - sliceDimensionFrom( empty( 'int16', sh, order ), 1, s, true, true ); // $ExpectType int16ndarray - sliceDimensionFrom( empty( 'int8', sh, order ), 1, s, true, true ); // $ExpectType int8ndarray - sliceDimensionFrom( empty( 'uint32', sh, order ), 1, s, true, true ); // $ExpectType uint32ndarray - sliceDimensionFrom( empty( 'uint16', sh, order ), 1, s, true, true ); // $ExpectType uint16ndarray - sliceDimensionFrom( empty( 'uint8', sh, order ), 1, s, true, true ); // $ExpectType uint8ndarray - sliceDimensionFrom( empty( 'uint8c', sh, order ), 1, s, true, true ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const s = 0; - - sliceDimensionFrom( '10', 1, s, false, false ); // $ExpectError - sliceDimensionFrom( 10, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( false, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( true, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( null, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( [], 1, s, false, false ); // $ExpectError - sliceDimensionFrom( {}, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( ( x: number ): number => x, 1, s, false, false ); // $ExpectError - - sliceDimensionFrom( '10', 1, s, true, true ); // $ExpectError - sliceDimensionFrom( 10, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( false, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( true, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( null, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( [], 1, s, true, true ); // $ExpectError - sliceDimensionFrom( {}, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( ( x: number ): number => x, 1, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a number... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 1; - - sliceDimensionFrom( x, '5', s, false, false ); // $ExpectError - sliceDimensionFrom( x, false, s, false, false ); // $ExpectError - sliceDimensionFrom( x, true, s, false, false ); // $ExpectError - sliceDimensionFrom( x, null, s, false, false ); // $ExpectError - sliceDimensionFrom( x, undefined, s, false, false ); // $ExpectError - sliceDimensionFrom( x, [ '5' ], s, false, false ); // $ExpectError - sliceDimensionFrom( x, {}, s, false, false ); // $ExpectError - sliceDimensionFrom( x, ( x: number ): number => x, s, false, false ); // $ExpectError - - sliceDimensionFrom( x, '5', s, true, true ); // $ExpectError - sliceDimensionFrom( x, false, s, true, true ); // $ExpectError - sliceDimensionFrom( x, true, s, true, true ); // $ExpectError - sliceDimensionFrom( x, null, s, true, true ); // $ExpectError - sliceDimensionFrom( x, undefined, s, true, true ); // $ExpectError - sliceDimensionFrom( x, [ '5' ], s, true, true ); // $ExpectError - sliceDimensionFrom( x, {}, s, true, true ); // $ExpectError - sliceDimensionFrom( x, ( x: number ): number => x, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceDimensionFrom( x, 1, '5', false, false ); // $ExpectError - sliceDimensionFrom( x, 1, false, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, true, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, null, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, undefined, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, [ '5' ], false, false ); // $ExpectError - sliceDimensionFrom( x, 1, {}, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, ( x: number ): number => x, 1, false, false ); // $ExpectError - - sliceDimensionFrom( x, 1, '5', true, true ); // $ExpectError - sliceDimensionFrom( x, 1, false, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, true, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, null, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, undefined, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, [ '5' ], true, true ); // $ExpectError - sliceDimensionFrom( x, 1, {}, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, ( x: number ): number => x, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x, 1, s, '5', false ); // $ExpectError - sliceDimensionFrom( x, 1, s, 5, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, null, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, undefined, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, [ '5' ], false ); // $ExpectError - sliceDimensionFrom( x, 1, s, {}, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x, 1, s, false, '5' ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, 5 ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, null ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, undefined ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, [ '5' ] ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, {} ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x ); // $ExpectError - sliceDimensionFrom( x, 1 ); // $ExpectError - sliceDimensionFrom( x, 1, s ); // $ExpectError - sliceDimensionFrom( x, 1, s, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index b17162a..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 sliceDimensionFrom = 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 = sliceDimensionFrom( x, 1, 1, false, false ); -// 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 columns of each matrix: -var y2 = sliceDimensionFrom( x, 2, 1, false, false ); -// returns - -var a2 = ndarray2array( y2 ); -console.log( a2 ); -// => [ [ [ 1, 2 ], [ 4, 5 ], [ 7, 8 ] ], [ [ 10, 11 ], [ 13, 14 ], [ 16, 17 ] ], [ [ 19, 20 ], [ 22, 23 ], [ 25, 26 ] ] ] - -// Get the last two matrices: -var y3 = sliceDimensionFrom( x, 0, 1, false, false ); -// returns - -var a3 = ndarray2array( y3 ); -console.log( a3 ); -// => [ [ [ 9, 10, 11 ], [ 12, 13, 14 ], [ 15, 16, 17 ] ], [ [ 18, 19, 20 ], [ 21, 22, 23 ], [ 24, 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 e398649..44225a7 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..06b4442 --- /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/slice-base-args2multislice@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-ctor@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndims@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-normalize-index@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-nulls@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function m(m,l,o,j,a){var p,h,v;if(0===(h=r(m)))throw new TypeError(d("1lDF7",h));if(-1===(v=i(l,h-1)))throw new RangeError(d("1lDF8",h,l));return(p=n(h))[v]=new e(o,null),t(m,s(p),j,a)}export{m as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..18102ad --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport Slice from '@stdlib/slice-ctor';\nimport ndims from '@stdlib/ndarray-base-ndims';\nimport slice from '@stdlib/ndarray-base-slice';\nimport normalizeIndex from '@stdlib/ndarray-base-normalize-index';\nimport nulls from '@stdlib/array-base-nulls';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns a shifted view of an input ndarray along a specified dimension.\n*\n* @param {ndarray} x - input array\n* @param {integer} dim - index of dimension to slice\n* @param {integer} start - starting index (inclusive)\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {TypeError} first argument must be an ndarray having one or more dimensions\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\n*\n* @example\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceDimensionFrom( x, 0, 1, false, false );\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 sliceDimensionFrom( x, dim, start, strict, writable ) {\n\tvar args;\n\tvar N;\n\tvar d;\n\n\t// Retrieve array meta data:\n\tN = ndims( x );\n\n\t// Check whether we were provided a zero-dimensional array...\n\tif ( N === 0 ) {\n\t\tthrow new TypeError( format( '1lDF7', N ) );\n\t}\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, N-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( '1lDF8', N, dim ) );\n\t}\n\t// Define a list of slice arguments:\n\targs = nulls( N );\n\targs[ d ] = new Slice( start, null );\n\n\t// Return a new array view:\n\treturn slice( x, args2multislice( args ), strict, writable );\n}\n\n\n// EXPORTS //\n\nexport default sliceDimensionFrom;\n"],"names":["sliceDimensionFrom","x","dim","start","strict","writable","args","N","d","ndims","TypeError","format","normalizeIndex","RangeError","nulls","Slice","slice","args2multislice"],"mappings":";;gpBAyEA,SAASA,EAAoBC,EAAGC,EAAKC,EAAOC,EAAQC,GACnD,IAAIC,EACAC,EACAC,EAMJ,GAAW,KAHXD,EAAIE,EAAOR,IAIV,MAAM,IAAIS,UAAWC,EAAQ,QAASJ,IAIvC,IAAY,KADZC,EAAII,EAAgBV,EAAKK,EAAE,IAE1B,MAAM,IAAIM,WAAYF,EAAQ,QAASJ,EAAGL,IAO3C,OAJAI,EAAOQ,EAAOP,IACRC,GAAM,IAAIO,EAAOZ,EAAO,MAGvBa,EAAOf,EAAGgB,EAAiBX,GAAQF,EAAQC,EACnD"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index b3f97b2..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 shifted view of an input ndarray along a specified dimension. -* -* @module @stdlib/ndarray-base-slice-dimension-from -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var sliceDimensionFrom = require( '@stdlib/ndarray-base-slice-dimension-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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // 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 50e4c67..0000000 --- a/lib/main.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var Slice = require( '@stdlib/slice-ctor' ); -var ndims = require( '@stdlib/ndarray-base-ndims' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' ); -var nulls = require( '@stdlib/array-base-nulls' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param {ndarray} x - input array -* @param {integer} dim - index of dimension to slice -* @param {integer} start - starting index (inclusive) -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @param {boolean} writable - boolean indicating whether a returned array should be writable -* @throws {TypeError} first argument must be an ndarray having one or more dimensions -* @throws {RangeError} dimension index exceeds the number of dimensions -* @throws {RangeError} slice 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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -function sliceDimensionFrom( x, dim, start, strict, writable ) { - var args; - var N; - var d; - - // Retrieve array meta data: - N = ndims( x ); - - // Check whether we were provided a zero-dimensional array... - if ( N === 0 ) { - throw new TypeError( format( '1lDF7', N ) ); - } - // Normalize the dimension index: - d = normalizeIndex( dim, N-1 ); - if ( d === -1 ) { - throw new RangeError( format( '1lDF8', N, dim ) ); - } - // Define a list of slice arguments: - args = nulls( N ); - args[ d ] = new Slice( start, null ); - - // Return a new array view: - return slice( x, args2multislice( args ), strict, writable ); -} - - -// EXPORTS // - -module.exports = sliceDimensionFrom; diff --git a/package.json b/package.json index 2e535c3..eb2ee55 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Return a shifted view of an input ndarray along a specific dimension.", "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,50 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-nulls": "github:stdlib-js/array-base-nulls#main", - "@stdlib/ndarray-base-ndims": "^0.2.2", - "@stdlib/ndarray-base-normalize-index": "^0.2.2", - "@stdlib/ndarray-base-slice": "^0.2.2", - "@stdlib/slice-base-args2multislice": "^0.2.2", - "@stdlib/slice-ctor": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/array-typed": "^0.3.0", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-base-empty": "^0.3.0", - "@stdlib/ndarray-base-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..8f38f04 --- /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 28703b5..0000000 --- a/test/test.js +++ /dev/null @@ -1,616 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 ndarray2array = require( '@stdlib/ndarray-to-array' ); -var baseCtor = require( '@stdlib/ndarray-base-ctor' ); -var ctor = require( '@stdlib/ndarray-ctor' ); -var sliceDimensionFrom = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sliceDimensionFrom, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a zero-dimensional array (strict=false)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error' ); - } - t.end(); - - function badValue( x ) { - return function badValue() { - sliceDimensionFrom( x, 0, 0, false, false ); - }; - } -}); - -tape( 'the function throws an error if provided a zero-dimensional array (strict=true)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error' ); - } - t.end(); - - function badValue( x ) { - return function badValue() { - sliceDimensionFrom( x, 0, 0, true, false ); - }; - } -}); - -tape( 'the function throws an error if the dimension index exceeds the number of dimensions (strict=false)', 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 ], 10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - t.throws( badValue( values[ i ], -10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - } - t.end(); - - function badValue( x, dim ) { - return function badValue() { - sliceDimensionFrom( x, dim, 0, false, false ); - }; - } -}); - -tape( 'the function throws an error if the dimension index exceeds the number of dimensions (strict=true)', 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 ], 10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - t.throws( badValue( values[ i ], -10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - } - t.end(); - - function badValue( x, dim ) { - return function badValue() { - sliceDimensionFrom( x, dim, 0, true, false ); - }; - } -}); - -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, - 20, - 20, - 20 - ]; - 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() { - sliceDimensionFrom( x, 0, s, true, false ); - }; - } -}); - -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, - 20, - 20, - 20, - 10 - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceDimensionFrom( values[ i ], 0, start[ i ], false, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), 0, 'returns expected value' ); - t.strictEqual( actual.dtype, values[ i ].dtype, 'returns expected value' ); - } - t.end(); -}); - -tape( 'in non-strict mode, the function returns an empty array when a starting index is the one more than the last index along a dimension', function test( t ) { - var actual; - var values; - var start; - var dim; - 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' } ) - ]; - - dim = [ - 0, - 1, - 0, - 1, - 4 - ]; - - start = [ - 1, - 1, - 1, - 1, - 1 - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceDimensionFrom( values[ i ], dim[ i ], start[ i ], false, false ); // eslint-disable-line max-len - 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 a shifted view of a provided input array (ndims=1)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 2, true, false ); - - 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 = sliceDimensionFrom( x, 0, -4, true, false ); - - 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)', 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 1, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 2, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, -2, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 1, 1, true, false ); - - 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 = sliceDimensionFrom( x, 1, -2, true, false ); - - 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' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=3)', 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 1, true, false ); - - 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 = sliceDimensionFrom( x, 1, 1, true, false ); - - 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 = sliceDimensionFrom( x, 2, 2, true, false ); - - 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 = sliceDimensionFrom( x, 2, -1, true, false ); - - 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' ); - t.end(); -}); - -tape( 'if a provided ndarray has a constructor supporting read-only instances, the function returns a read-only instance', function test( t ) { - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - x = new baseCtor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports returning writable views', function test( t ) { - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - x = new baseCtor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - t.end(); -}); From 2f35519dafe0a7fa1c342c4f51340790f9ab9d06 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 28 Sep 2024 18:15:42 +0000 Subject: [PATCH 56/92] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 54bb1c2..50e4c67 100644 --- a/lib/main.js +++ b/lib/main.js @@ -26,7 +26,7 @@ var ndims = require( '@stdlib/ndarray-base-ndims' ); var slice = require( '@stdlib/ndarray-base-slice' ); var normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' ); var nulls = require( '@stdlib/array-base-nulls' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -81,12 +81,12 @@ function sliceDimensionFrom( x, dim, start, strict, writable ) { // Check whether we were provided a zero-dimensional array... if ( N === 0 ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.', N ) ); + throw new TypeError( format( '1lDF7', N ) ); } // Normalize the dimension index: d = normalizeIndex( dim, N-1 ); if ( d === -1 ) { - throw new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', N, dim ) ); + throw new RangeError( format( '1lDF8', N, dim ) ); } // Define a list of slice arguments: args = nulls( N ); diff --git a/package.json b/package.json index 524b4e6..2e535c3 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/ndarray-base-slice": "^0.2.2", "@stdlib/slice-base-args2multislice": "^0.2.2", "@stdlib/slice-ctor": "^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 c8bdd6d42ce53a32cc0c8811a4cee3ad2949aba3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 28 Sep 2024 18:18:44 +0000 Subject: [PATCH 57/92] Remove files --- index.d.ts | 534 ------ index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5381 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 44225a7..0000000 --- a/index.d.ts +++ /dev/null @@ -1,534 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceDimensionFrom( x: float64ndarray, dim: number, start: number, strict: boolean, writable: boolean ): float64ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceDimensionFrom( x: float32ndarray, dim: number, start: number, strict: boolean, writable: boolean ): float32ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: int32ndarray, dim: number, start: number, strict: boolean, writable: boolean ): int32ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: int16ndarray, dim: number, start: number, strict: boolean, writable: boolean ): int16ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: int8ndarray, dim: number, start: number, strict: boolean, writable: boolean ): int8ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint32ndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint32ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint16ndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint16ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint8ndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint8ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint8cndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint8cndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceDimensionFrom( x: complex128ndarray, dim: number, start: number, strict: boolean, writable: boolean ): complex128ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceDimensionFrom( x: complex64ndarray, dim: number, start: number, strict: boolean, writable: boolean ): complex64ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: genericndarray, dim: number, start: number, strict: boolean, writable: boolean ): genericndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: typedndarray, dim: number, start: number, strict: boolean, writable: boolean ): typedndarray; - - -// EXPORTS // - -export = sliceDimensionFrom; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 06b4442..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/slice-base-args2multislice@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-ctor@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndims@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-normalize-index@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-nulls@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function m(m,l,o,j,a){var p,h,v;if(0===(h=r(m)))throw new TypeError(d("1lDF7",h));if(-1===(v=i(l,h-1)))throw new RangeError(d("1lDF8",h,l));return(p=n(h))[v]=new e(o,null),t(m,s(p),j,a)}export{m as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 18102ad..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport Slice from '@stdlib/slice-ctor';\nimport ndims from '@stdlib/ndarray-base-ndims';\nimport slice from '@stdlib/ndarray-base-slice';\nimport normalizeIndex from '@stdlib/ndarray-base-normalize-index';\nimport nulls from '@stdlib/array-base-nulls';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns a shifted view of an input ndarray along a specified dimension.\n*\n* @param {ndarray} x - input array\n* @param {integer} dim - index of dimension to slice\n* @param {integer} start - starting index (inclusive)\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {TypeError} first argument must be an ndarray having one or more dimensions\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\n*\n* @example\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceDimensionFrom( x, 0, 1, false, false );\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 sliceDimensionFrom( x, dim, start, strict, writable ) {\n\tvar args;\n\tvar N;\n\tvar d;\n\n\t// Retrieve array meta data:\n\tN = ndims( x );\n\n\t// Check whether we were provided a zero-dimensional array...\n\tif ( N === 0 ) {\n\t\tthrow new TypeError( format( '1lDF7', N ) );\n\t}\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, N-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( '1lDF8', N, dim ) );\n\t}\n\t// Define a list of slice arguments:\n\targs = nulls( N );\n\targs[ d ] = new Slice( start, null );\n\n\t// Return a new array view:\n\treturn slice( x, args2multislice( args ), strict, writable );\n}\n\n\n// EXPORTS //\n\nexport default sliceDimensionFrom;\n"],"names":["sliceDimensionFrom","x","dim","start","strict","writable","args","N","d","ndims","TypeError","format","normalizeIndex","RangeError","nulls","Slice","slice","args2multislice"],"mappings":";;gpBAyEA,SAASA,EAAoBC,EAAGC,EAAKC,EAAOC,EAAQC,GACnD,IAAIC,EACAC,EACAC,EAMJ,GAAW,KAHXD,EAAIE,EAAOR,IAIV,MAAM,IAAIS,UAAWC,EAAQ,QAASJ,IAIvC,IAAY,KADZC,EAAII,EAAgBV,EAAKK,EAAE,IAE1B,MAAM,IAAIM,WAAYF,EAAQ,QAASJ,EAAGL,IAO3C,OAJAI,EAAOQ,EAAOP,IACRC,GAAM,IAAIO,EAAOZ,EAAO,MAGvBa,EAAOf,EAAGgB,EAAiBX,GAAQF,EAAQC,EACnD"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 8f38f04..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From a6cdfa7cb138ca830ed773008943553215951d72 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 28 Sep 2024 18:19:12 +0000 Subject: [PATCH 58/92] 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 | 150 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 45 +- SECURITY.md | 5 - benchmark/benchmark.js | 681 --- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 49 - docs/types/test.ts | 164 - 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 | 102 - package.json | 71 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 616 --- 42 files changed, 4868 insertions(+), 5275 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 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 05d1840..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-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 ced95ae..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-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 60a2bb4..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: '38 14 * * 5' - - # 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 + + ```
@@ -202,7 +193,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]. diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 8a6b7a2..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,681 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 sliceDimensionFrom = require( './../lib' ); - - -// MAIN // - -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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2 ], { 'dtype': 'float64' } ), - empty( [ 2 ], { 'dtype': 'float32' } ), - empty( [ 2 ], { 'dtype': 'int32' } ), - empty( [ 2 ], { 'dtype': 'complex128' } ), - empty( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== '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 9543fcd..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-from" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-from -[production-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-slice-dimension-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 2ab577a..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import sliceDimensionFrom from '../docs/types/index'; -export = sliceDimensionFrom; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 2f5466d..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var v=function(i,r){return function(){return r||i((r={exports:{}}).exports,r),r.exports}};var o=v(function(p,u){"use strict";var l=require("@stdlib/slice-base-args2multislice"),c=require("@stdlib/slice-ctor"),q=require("@stdlib/ndarray-base-ndims"),f=require("@stdlib/ndarray-base-slice"),g=require("@stdlib/ndarray-base-normalize-index"),w=require("@stdlib/array-base-nulls"),s=require("@stdlib/string-format");function b(i,r,m,t,d){var n,e,a;if(e=q(i),e===0)throw new TypeError(s("invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.",e));if(a=g(r,e-1),a===-1)throw new RangeError(s("invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.",e,r));return n=w(e),n[a]=new c(m,null),f(i,l(n),t,d)}u.exports=b});var h=o();module.exports=h; -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 19dddde..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar args2multislice = require( '@stdlib/slice-base-args2multislice' );\nvar Slice = require( '@stdlib/slice-ctor' );\nvar ndims = require( '@stdlib/ndarray-base-ndims' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' );\nvar nulls = require( '@stdlib/array-base-nulls' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns a shifted view of an input ndarray along a specified dimension.\n*\n* @param {ndarray} x - input array\n* @param {integer} dim - index of dimension to slice\n* @param {integer} start - starting index (inclusive)\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {TypeError} first argument must be an ndarray having one or more dimensions\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceDimensionFrom( x, 0, 1, false, false );\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 sliceDimensionFrom( x, dim, start, strict, writable ) {\n\tvar args;\n\tvar N;\n\tvar d;\n\n\t// Retrieve array meta data:\n\tN = ndims( x );\n\n\t// Check whether we were provided a zero-dimensional array...\n\tif ( N === 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.', N ) );\n\t}\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, N-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', N, dim ) );\n\t}\n\t// Define a list of slice arguments:\n\targs = nulls( N );\n\targs[ d ] = new Slice( start, null );\n\n\t// Return a new array view:\n\treturn slice( x, args2multislice( args ), strict, writable );\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceDimensionFrom;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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 shifted view of an input ndarray along a specified dimension.\n*\n* @module @stdlib/ndarray-base-slice-dimension-from\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var sliceDimensionFrom = require( '@stdlib/ndarray-base-slice-dimension-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 = sliceDimensionFrom( x, 0, 1, false, false );\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,EAAkB,QAAS,oCAAqC,EAChEC,EAAQ,QAAS,oBAAqB,EACtCC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAiB,QAAS,sCAAuC,EACjEC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAS,QAAS,uBAAwB,EA6C9C,SAASC,EAAoBC,EAAGC,EAAKC,EAAOC,EAAQC,EAAW,CAC9D,IAAIC,EACAC,EACAC,EAMJ,GAHAD,EAAIZ,EAAOM,CAAE,EAGRM,IAAM,EACV,MAAM,IAAI,UAAWR,EAAQ,+GAAgHQ,CAAE,CAAE,EAIlJ,GADAC,EAAIX,EAAgBK,EAAKK,EAAE,CAAE,EACxBC,IAAM,GACV,MAAM,IAAI,WAAYT,EAAQ,6GAA8GQ,EAAGL,CAAI,CAAE,EAGtJ,OAAAI,EAAOR,EAAOS,CAAE,EAChBD,EAAME,CAAE,EAAI,IAAId,EAAOS,EAAO,IAAK,EAG5BP,EAAOK,EAAGR,EAAiBa,CAAK,EAAGF,EAAQC,CAAS,CAC5D,CAKAb,EAAO,QAAUQ,IC7CjB,IAAIS,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "args2multislice", "Slice", "ndims", "slice", "normalizeIndex", "nulls", "format", "sliceDimensionFrom", "x", "dim", "start", "strict", "writable", "args", "N", "d", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ffc1f03..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,49 +0,0 @@ - -{{alias}}( x, dim, start, strict, writable ) - Returns a shifted view of an input ndarray along a specified dimension. - - Parameters - ---------- - x: ndarray - Input array. - - dim: integer - Index of dimension to slice. If less than zero, the index is resolved - relative to the last dimension, with the last dimension corresponding to - the value `-1`. - - start: integer - Starting index (inclusive). If less than zero, the corresponding element - along the specified dimension is resolved relative to the last element - along that dimension. For negative integers, the last element - corresponds to the value `-1`. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - writable: boolean - Boolean indicating whether a returned ndarray should be writable. This - parameter only applies to ndarray constructors which support read-only - instances. - - Returns - ------- - out: ndarray - Output array view. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > x.shape - [ 2, 2 ] - > var y = {{alias}}( x, 1, 1, false, false ) - - > 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 9dfeaf3..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,164 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sliceDimensionFrom = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = 0; - - sliceDimensionFrom( empty( 'float64', sh, order ), 1, s, false, false ); // $ExpectType float64ndarray - sliceDimensionFrom( empty( 'float32', sh, order ), 1, s, false, false ); // $ExpectType float32ndarray - sliceDimensionFrom( empty( 'complex128', sh, order ), 1, s, false, false ); // $ExpectType complex128ndarray - sliceDimensionFrom( empty( 'complex64', sh, order ), 1, s, false, false ); // $ExpectType complex64ndarray - sliceDimensionFrom( empty( 'int32', sh, order ), 1, s, false, false ); // $ExpectType int32ndarray - sliceDimensionFrom( empty( 'int16', sh, order ), 1, s, false, false ); // $ExpectType int16ndarray - sliceDimensionFrom( empty( 'int8', sh, order ), 1, s, false, false ); // $ExpectType int8ndarray - sliceDimensionFrom( empty( 'uint32', sh, order ), 1, s, false, false ); // $ExpectType uint32ndarray - sliceDimensionFrom( empty( 'uint16', sh, order ), 1, s, false, false ); // $ExpectType uint16ndarray - sliceDimensionFrom( empty( 'uint8', sh, order ), 1, s, false, false ); // $ExpectType uint8ndarray - sliceDimensionFrom( empty( 'uint8c', sh, order ), 1, s, false, false ); // $ExpectType uint8cndarray - - sliceDimensionFrom( empty( 'float64', sh, order ), 1, s, true, true ); // $ExpectType float64ndarray - sliceDimensionFrom( empty( 'float32', sh, order ), 1, s, true, true ); // $ExpectType float32ndarray - sliceDimensionFrom( empty( 'complex128', sh, order ), 1, s, true, true ); // $ExpectType complex128ndarray - sliceDimensionFrom( empty( 'complex64', sh, order ), 1, s, true, true ); // $ExpectType complex64ndarray - sliceDimensionFrom( empty( 'int32', sh, order ), 1, s, true, true ); // $ExpectType int32ndarray - sliceDimensionFrom( empty( 'int16', sh, order ), 1, s, true, true ); // $ExpectType int16ndarray - sliceDimensionFrom( empty( 'int8', sh, order ), 1, s, true, true ); // $ExpectType int8ndarray - sliceDimensionFrom( empty( 'uint32', sh, order ), 1, s, true, true ); // $ExpectType uint32ndarray - sliceDimensionFrom( empty( 'uint16', sh, order ), 1, s, true, true ); // $ExpectType uint16ndarray - sliceDimensionFrom( empty( 'uint8', sh, order ), 1, s, true, true ); // $ExpectType uint8ndarray - sliceDimensionFrom( empty( 'uint8c', sh, order ), 1, s, true, true ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const s = 0; - - sliceDimensionFrom( '10', 1, s, false, false ); // $ExpectError - sliceDimensionFrom( 10, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( false, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( true, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( null, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( [], 1, s, false, false ); // $ExpectError - sliceDimensionFrom( {}, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( ( x: number ): number => x, 1, s, false, false ); // $ExpectError - - sliceDimensionFrom( '10', 1, s, true, true ); // $ExpectError - sliceDimensionFrom( 10, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( false, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( true, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( null, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( [], 1, s, true, true ); // $ExpectError - sliceDimensionFrom( {}, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( ( x: number ): number => x, 1, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a number... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 1; - - sliceDimensionFrom( x, '5', s, false, false ); // $ExpectError - sliceDimensionFrom( x, false, s, false, false ); // $ExpectError - sliceDimensionFrom( x, true, s, false, false ); // $ExpectError - sliceDimensionFrom( x, null, s, false, false ); // $ExpectError - sliceDimensionFrom( x, undefined, s, false, false ); // $ExpectError - sliceDimensionFrom( x, [ '5' ], s, false, false ); // $ExpectError - sliceDimensionFrom( x, {}, s, false, false ); // $ExpectError - sliceDimensionFrom( x, ( x: number ): number => x, s, false, false ); // $ExpectError - - sliceDimensionFrom( x, '5', s, true, true ); // $ExpectError - sliceDimensionFrom( x, false, s, true, true ); // $ExpectError - sliceDimensionFrom( x, true, s, true, true ); // $ExpectError - sliceDimensionFrom( x, null, s, true, true ); // $ExpectError - sliceDimensionFrom( x, undefined, s, true, true ); // $ExpectError - sliceDimensionFrom( x, [ '5' ], s, true, true ); // $ExpectError - sliceDimensionFrom( x, {}, s, true, true ); // $ExpectError - sliceDimensionFrom( x, ( x: number ): number => x, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceDimensionFrom( x, 1, '5', false, false ); // $ExpectError - sliceDimensionFrom( x, 1, false, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, true, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, null, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, undefined, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, [ '5' ], false, false ); // $ExpectError - sliceDimensionFrom( x, 1, {}, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, ( x: number ): number => x, 1, false, false ); // $ExpectError - - sliceDimensionFrom( x, 1, '5', true, true ); // $ExpectError - sliceDimensionFrom( x, 1, false, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, true, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, null, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, undefined, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, [ '5' ], true, true ); // $ExpectError - sliceDimensionFrom( x, 1, {}, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, ( x: number ): number => x, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x, 1, s, '5', false ); // $ExpectError - sliceDimensionFrom( x, 1, s, 5, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, null, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, undefined, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, [ '5' ], false ); // $ExpectError - sliceDimensionFrom( x, 1, s, {}, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x, 1, s, false, '5' ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, 5 ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, null ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, undefined ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, [ '5' ] ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, {} ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x ); // $ExpectError - sliceDimensionFrom( x, 1 ); // $ExpectError - sliceDimensionFrom( x, 1, s ); // $ExpectError - sliceDimensionFrom( x, 1, s, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index b17162a..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 sliceDimensionFrom = 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 = sliceDimensionFrom( x, 1, 1, false, false ); -// 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 columns of each matrix: -var y2 = sliceDimensionFrom( x, 2, 1, false, false ); -// returns - -var a2 = ndarray2array( y2 ); -console.log( a2 ); -// => [ [ [ 1, 2 ], [ 4, 5 ], [ 7, 8 ] ], [ [ 10, 11 ], [ 13, 14 ], [ 16, 17 ] ], [ [ 19, 20 ], [ 22, 23 ], [ 25, 26 ] ] ] - -// Get the last two matrices: -var y3 = sliceDimensionFrom( x, 0, 1, false, false ); -// returns - -var a3 = ndarray2array( y3 ); -console.log( a3 ); -// => [ [ [ 9, 10, 11 ], [ 12, 13, 14 ], [ 15, 16, 17 ] ], [ [ 18, 19, 20 ], [ 21, 22, 23 ], [ 24, 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 22f5594..49b5959 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..06b4442 --- /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/slice-base-args2multislice@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-ctor@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndims@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-normalize-index@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-nulls@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function m(m,l,o,j,a){var p,h,v;if(0===(h=r(m)))throw new TypeError(d("1lDF7",h));if(-1===(v=i(l,h-1)))throw new RangeError(d("1lDF8",h,l));return(p=n(h))[v]=new e(o,null),t(m,s(p),j,a)}export{m as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..18102ad --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport Slice from '@stdlib/slice-ctor';\nimport ndims from '@stdlib/ndarray-base-ndims';\nimport slice from '@stdlib/ndarray-base-slice';\nimport normalizeIndex from '@stdlib/ndarray-base-normalize-index';\nimport nulls from '@stdlib/array-base-nulls';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns a shifted view of an input ndarray along a specified dimension.\n*\n* @param {ndarray} x - input array\n* @param {integer} dim - index of dimension to slice\n* @param {integer} start - starting index (inclusive)\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {TypeError} first argument must be an ndarray having one or more dimensions\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\n*\n* @example\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceDimensionFrom( x, 0, 1, false, false );\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 sliceDimensionFrom( x, dim, start, strict, writable ) {\n\tvar args;\n\tvar N;\n\tvar d;\n\n\t// Retrieve array meta data:\n\tN = ndims( x );\n\n\t// Check whether we were provided a zero-dimensional array...\n\tif ( N === 0 ) {\n\t\tthrow new TypeError( format( '1lDF7', N ) );\n\t}\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, N-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( '1lDF8', N, dim ) );\n\t}\n\t// Define a list of slice arguments:\n\targs = nulls( N );\n\targs[ d ] = new Slice( start, null );\n\n\t// Return a new array view:\n\treturn slice( x, args2multislice( args ), strict, writable );\n}\n\n\n// EXPORTS //\n\nexport default sliceDimensionFrom;\n"],"names":["sliceDimensionFrom","x","dim","start","strict","writable","args","N","d","ndims","TypeError","format","normalizeIndex","RangeError","nulls","Slice","slice","args2multislice"],"mappings":";;gpBAyEA,SAASA,EAAoBC,EAAGC,EAAKC,EAAOC,EAAQC,GACnD,IAAIC,EACAC,EACAC,EAMJ,GAAW,KAHXD,EAAIE,EAAOR,IAIV,MAAM,IAAIS,UAAWC,EAAQ,QAASJ,IAIvC,IAAY,KADZC,EAAII,EAAgBV,EAAKK,EAAE,IAE1B,MAAM,IAAIM,WAAYF,EAAQ,QAASJ,EAAGL,IAO3C,OAJAI,EAAOQ,EAAOP,IACRC,GAAM,IAAIO,EAAOZ,EAAO,MAGvBa,EAAOf,EAAGgB,EAAiBX,GAAQF,EAAQC,EACnD"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index b3f97b2..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 shifted view of an input ndarray along a specified dimension. -* -* @module @stdlib/ndarray-base-slice-dimension-from -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var sliceDimensionFrom = require( '@stdlib/ndarray-base-slice-dimension-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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // 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 50e4c67..0000000 --- a/lib/main.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var Slice = require( '@stdlib/slice-ctor' ); -var ndims = require( '@stdlib/ndarray-base-ndims' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' ); -var nulls = require( '@stdlib/array-base-nulls' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param {ndarray} x - input array -* @param {integer} dim - index of dimension to slice -* @param {integer} start - starting index (inclusive) -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @param {boolean} writable - boolean indicating whether a returned array should be writable -* @throws {TypeError} first argument must be an ndarray having one or more dimensions -* @throws {RangeError} dimension index exceeds the number of dimensions -* @throws {RangeError} slice 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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -function sliceDimensionFrom( x, dim, start, strict, writable ) { - var args; - var N; - var d; - - // Retrieve array meta data: - N = ndims( x ); - - // Check whether we were provided a zero-dimensional array... - if ( N === 0 ) { - throw new TypeError( format( '1lDF7', N ) ); - } - // Normalize the dimension index: - d = normalizeIndex( dim, N-1 ); - if ( d === -1 ) { - throw new RangeError( format( '1lDF8', N, dim ) ); - } - // Define a list of slice arguments: - args = nulls( N ); - args[ d ] = new Slice( start, null ); - - // Return a new array view: - return slice( x, args2multislice( args ), strict, writable ); -} - - -// EXPORTS // - -module.exports = sliceDimensionFrom; diff --git a/package.json b/package.json index 2e535c3..eb2ee55 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Return a shifted view of an input ndarray along a specific dimension.", "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,50 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-nulls": "github:stdlib-js/array-base-nulls#main", - "@stdlib/ndarray-base-ndims": "^0.2.2", - "@stdlib/ndarray-base-normalize-index": "^0.2.2", - "@stdlib/ndarray-base-slice": "^0.2.2", - "@stdlib/slice-base-args2multislice": "^0.2.2", - "@stdlib/slice-ctor": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/array-typed": "^0.3.0", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-base-empty": "^0.3.0", - "@stdlib/ndarray-base-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..8f38f04 --- /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 28703b5..0000000 --- a/test/test.js +++ /dev/null @@ -1,616 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 ndarray2array = require( '@stdlib/ndarray-to-array' ); -var baseCtor = require( '@stdlib/ndarray-base-ctor' ); -var ctor = require( '@stdlib/ndarray-ctor' ); -var sliceDimensionFrom = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sliceDimensionFrom, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a zero-dimensional array (strict=false)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error' ); - } - t.end(); - - function badValue( x ) { - return function badValue() { - sliceDimensionFrom( x, 0, 0, false, false ); - }; - } -}); - -tape( 'the function throws an error if provided a zero-dimensional array (strict=true)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error' ); - } - t.end(); - - function badValue( x ) { - return function badValue() { - sliceDimensionFrom( x, 0, 0, true, false ); - }; - } -}); - -tape( 'the function throws an error if the dimension index exceeds the number of dimensions (strict=false)', 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 ], 10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - t.throws( badValue( values[ i ], -10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - } - t.end(); - - function badValue( x, dim ) { - return function badValue() { - sliceDimensionFrom( x, dim, 0, false, false ); - }; - } -}); - -tape( 'the function throws an error if the dimension index exceeds the number of dimensions (strict=true)', 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 ], 10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - t.throws( badValue( values[ i ], -10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - } - t.end(); - - function badValue( x, dim ) { - return function badValue() { - sliceDimensionFrom( x, dim, 0, true, false ); - }; - } -}); - -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, - 20, - 20, - 20 - ]; - 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() { - sliceDimensionFrom( x, 0, s, true, false ); - }; - } -}); - -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, - 20, - 20, - 20, - 10 - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceDimensionFrom( values[ i ], 0, start[ i ], false, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), 0, 'returns expected value' ); - t.strictEqual( actual.dtype, values[ i ].dtype, 'returns expected value' ); - } - t.end(); -}); - -tape( 'in non-strict mode, the function returns an empty array when a starting index is the one more than the last index along a dimension', function test( t ) { - var actual; - var values; - var start; - var dim; - 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' } ) - ]; - - dim = [ - 0, - 1, - 0, - 1, - 4 - ]; - - start = [ - 1, - 1, - 1, - 1, - 1 - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceDimensionFrom( values[ i ], dim[ i ], start[ i ], false, false ); // eslint-disable-line max-len - 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 a shifted view of a provided input array (ndims=1)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 2, true, false ); - - 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 = sliceDimensionFrom( x, 0, -4, true, false ); - - 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)', 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 1, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 2, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, -2, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 1, 1, true, false ); - - 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 = sliceDimensionFrom( x, 1, -2, true, false ); - - 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' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=3)', 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 1, true, false ); - - 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 = sliceDimensionFrom( x, 1, 1, true, false ); - - 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 = sliceDimensionFrom( x, 2, 2, true, false ); - - 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 = sliceDimensionFrom( x, 2, -1, true, false ); - - 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' ); - t.end(); -}); - -tape( 'if a provided ndarray has a constructor supporting read-only instances, the function returns a read-only instance', function test( t ) { - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - x = new baseCtor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports returning writable views', function test( t ) { - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - x = new baseCtor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - t.end(); -}); From d2a0c8adecc2171a8cfe93795a95af04553714cb Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Oct 2024 08:42:14 +0000 Subject: [PATCH 59/92] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 54bb1c2..50e4c67 100644 --- a/lib/main.js +++ b/lib/main.js @@ -26,7 +26,7 @@ var ndims = require( '@stdlib/ndarray-base-ndims' ); var slice = require( '@stdlib/ndarray-base-slice' ); var normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' ); var nulls = require( '@stdlib/array-base-nulls' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -81,12 +81,12 @@ function sliceDimensionFrom( x, dim, start, strict, writable ) { // Check whether we were provided a zero-dimensional array... if ( N === 0 ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.', N ) ); + throw new TypeError( format( '1lDF7', N ) ); } // Normalize the dimension index: d = normalizeIndex( dim, N-1 ); if ( d === -1 ) { - throw new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', N, dim ) ); + throw new RangeError( format( '1lDF8', N, dim ) ); } // Define a list of slice arguments: args = nulls( N ); diff --git a/package.json b/package.json index 524b4e6..2e535c3 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/ndarray-base-slice": "^0.2.2", "@stdlib/slice-base-args2multislice": "^0.2.2", "@stdlib/slice-ctor": "^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 7e25431029db75f97afe74799149f0e8a5d1069b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Oct 2024 13:23:56 +0000 Subject: [PATCH 60/92] Remove files --- index.d.ts | 534 ------ index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5381 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 49b5959..0000000 --- a/index.d.ts +++ /dev/null @@ -1,534 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceDimensionFrom( x: float64ndarray, dim: number, start: number, strict: boolean, writable: boolean ): float64ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceDimensionFrom( x: float32ndarray, dim: number, start: number, strict: boolean, writable: boolean ): float32ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: int32ndarray, dim: number, start: number, strict: boolean, writable: boolean ): int32ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: int16ndarray, dim: number, start: number, strict: boolean, writable: boolean ): int16ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: int8ndarray, dim: number, start: number, strict: boolean, writable: boolean ): int8ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint32ndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint32ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint16ndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint16ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint8ndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint8ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint8cndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint8cndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceDimensionFrom( x: complex128ndarray, dim: number, start: number, strict: boolean, writable: boolean ): complex128ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceDimensionFrom( x: complex64ndarray, dim: number, start: number, strict: boolean, writable: boolean ): complex64ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: genericndarray, dim: number, start: number, strict: boolean, writable: boolean ): genericndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: typedndarray, dim: number, start: number, strict: boolean, writable: boolean ): typedndarray; - - -// EXPORTS // - -export = sliceDimensionFrom; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 06b4442..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/slice-base-args2multislice@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-ctor@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndims@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-normalize-index@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-nulls@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function m(m,l,o,j,a){var p,h,v;if(0===(h=r(m)))throw new TypeError(d("1lDF7",h));if(-1===(v=i(l,h-1)))throw new RangeError(d("1lDF8",h,l));return(p=n(h))[v]=new e(o,null),t(m,s(p),j,a)}export{m as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 18102ad..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport Slice from '@stdlib/slice-ctor';\nimport ndims from '@stdlib/ndarray-base-ndims';\nimport slice from '@stdlib/ndarray-base-slice';\nimport normalizeIndex from '@stdlib/ndarray-base-normalize-index';\nimport nulls from '@stdlib/array-base-nulls';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns a shifted view of an input ndarray along a specified dimension.\n*\n* @param {ndarray} x - input array\n* @param {integer} dim - index of dimension to slice\n* @param {integer} start - starting index (inclusive)\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {TypeError} first argument must be an ndarray having one or more dimensions\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\n*\n* @example\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceDimensionFrom( x, 0, 1, false, false );\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 sliceDimensionFrom( x, dim, start, strict, writable ) {\n\tvar args;\n\tvar N;\n\tvar d;\n\n\t// Retrieve array meta data:\n\tN = ndims( x );\n\n\t// Check whether we were provided a zero-dimensional array...\n\tif ( N === 0 ) {\n\t\tthrow new TypeError( format( '1lDF7', N ) );\n\t}\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, N-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( '1lDF8', N, dim ) );\n\t}\n\t// Define a list of slice arguments:\n\targs = nulls( N );\n\targs[ d ] = new Slice( start, null );\n\n\t// Return a new array view:\n\treturn slice( x, args2multislice( args ), strict, writable );\n}\n\n\n// EXPORTS //\n\nexport default sliceDimensionFrom;\n"],"names":["sliceDimensionFrom","x","dim","start","strict","writable","args","N","d","ndims","TypeError","format","normalizeIndex","RangeError","nulls","Slice","slice","args2multislice"],"mappings":";;gpBAyEA,SAASA,EAAoBC,EAAGC,EAAKC,EAAOC,EAAQC,GACnD,IAAIC,EACAC,EACAC,EAMJ,GAAW,KAHXD,EAAIE,EAAOR,IAIV,MAAM,IAAIS,UAAWC,EAAQ,QAASJ,IAIvC,IAAY,KADZC,EAAII,EAAgBV,EAAKK,EAAE,IAE1B,MAAM,IAAIM,WAAYF,EAAQ,QAASJ,EAAGL,IAO3C,OAJAI,EAAOQ,EAAOP,IACRC,GAAM,IAAIO,EAAOZ,EAAO,MAGvBa,EAAOf,EAAGgB,EAAiBX,GAAQF,EAAQC,EACnD"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 8f38f04..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 3053a8453ac182b6df39de30781cfd6c5b042d01 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Oct 2024 13:24:17 +0000 Subject: [PATCH 61/92] 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 | 150 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 45 +- SECURITY.md | 5 - benchmark/benchmark.js | 681 --- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 49 - docs/types/test.ts | 164 - 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 | 102 - package.json | 71 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 616 --- 43 files changed, 4868 insertions(+), 5276 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 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 6ef6d92..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-10-01T06:32:00.085Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 05d1840..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-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 ced95ae..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-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 60a2bb4..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: '38 14 * * 5' - - # 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 + + ```
@@ -202,7 +193,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]. diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 8a6b7a2..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,681 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 sliceDimensionFrom = require( './../lib' ); - - -// MAIN // - -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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2 ], { 'dtype': 'float64' } ), - empty( [ 2 ], { 'dtype': 'float32' } ), - empty( [ 2 ], { 'dtype': 'int32' } ), - empty( [ 2 ], { 'dtype': 'complex128' } ), - empty( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== '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 9543fcd..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-from" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-from -[production-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-slice-dimension-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 2ab577a..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import sliceDimensionFrom from '../docs/types/index'; -export = sliceDimensionFrom; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 2f5466d..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var v=function(i,r){return function(){return r||i((r={exports:{}}).exports,r),r.exports}};var o=v(function(p,u){"use strict";var l=require("@stdlib/slice-base-args2multislice"),c=require("@stdlib/slice-ctor"),q=require("@stdlib/ndarray-base-ndims"),f=require("@stdlib/ndarray-base-slice"),g=require("@stdlib/ndarray-base-normalize-index"),w=require("@stdlib/array-base-nulls"),s=require("@stdlib/string-format");function b(i,r,m,t,d){var n,e,a;if(e=q(i),e===0)throw new TypeError(s("invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.",e));if(a=g(r,e-1),a===-1)throw new RangeError(s("invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.",e,r));return n=w(e),n[a]=new c(m,null),f(i,l(n),t,d)}u.exports=b});var h=o();module.exports=h; -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 19dddde..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar args2multislice = require( '@stdlib/slice-base-args2multislice' );\nvar Slice = require( '@stdlib/slice-ctor' );\nvar ndims = require( '@stdlib/ndarray-base-ndims' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' );\nvar nulls = require( '@stdlib/array-base-nulls' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns a shifted view of an input ndarray along a specified dimension.\n*\n* @param {ndarray} x - input array\n* @param {integer} dim - index of dimension to slice\n* @param {integer} start - starting index (inclusive)\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {TypeError} first argument must be an ndarray having one or more dimensions\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceDimensionFrom( x, 0, 1, false, false );\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 sliceDimensionFrom( x, dim, start, strict, writable ) {\n\tvar args;\n\tvar N;\n\tvar d;\n\n\t// Retrieve array meta data:\n\tN = ndims( x );\n\n\t// Check whether we were provided a zero-dimensional array...\n\tif ( N === 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.', N ) );\n\t}\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, N-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', N, dim ) );\n\t}\n\t// Define a list of slice arguments:\n\targs = nulls( N );\n\targs[ d ] = new Slice( start, null );\n\n\t// Return a new array view:\n\treturn slice( x, args2multislice( args ), strict, writable );\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceDimensionFrom;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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 shifted view of an input ndarray along a specified dimension.\n*\n* @module @stdlib/ndarray-base-slice-dimension-from\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var sliceDimensionFrom = require( '@stdlib/ndarray-base-slice-dimension-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 = sliceDimensionFrom( x, 0, 1, false, false );\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,EAAkB,QAAS,oCAAqC,EAChEC,EAAQ,QAAS,oBAAqB,EACtCC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAiB,QAAS,sCAAuC,EACjEC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAS,QAAS,uBAAwB,EA6C9C,SAASC,EAAoBC,EAAGC,EAAKC,EAAOC,EAAQC,EAAW,CAC9D,IAAIC,EACAC,EACAC,EAMJ,GAHAD,EAAIZ,EAAOM,CAAE,EAGRM,IAAM,EACV,MAAM,IAAI,UAAWR,EAAQ,+GAAgHQ,CAAE,CAAE,EAIlJ,GADAC,EAAIX,EAAgBK,EAAKK,EAAE,CAAE,EACxBC,IAAM,GACV,MAAM,IAAI,WAAYT,EAAQ,6GAA8GQ,EAAGL,CAAI,CAAE,EAGtJ,OAAAI,EAAOR,EAAOS,CAAE,EAChBD,EAAME,CAAE,EAAI,IAAId,EAAOS,EAAO,IAAK,EAG5BP,EAAOK,EAAGR,EAAiBa,CAAK,EAAGF,EAAQC,CAAS,CAC5D,CAKAb,EAAO,QAAUQ,IC7CjB,IAAIS,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "args2multislice", "Slice", "ndims", "slice", "normalizeIndex", "nulls", "format", "sliceDimensionFrom", "x", "dim", "start", "strict", "writable", "args", "N", "d", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ffc1f03..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,49 +0,0 @@ - -{{alias}}( x, dim, start, strict, writable ) - Returns a shifted view of an input ndarray along a specified dimension. - - Parameters - ---------- - x: ndarray - Input array. - - dim: integer - Index of dimension to slice. If less than zero, the index is resolved - relative to the last dimension, with the last dimension corresponding to - the value `-1`. - - start: integer - Starting index (inclusive). If less than zero, the corresponding element - along the specified dimension is resolved relative to the last element - along that dimension. For negative integers, the last element - corresponds to the value `-1`. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - writable: boolean - Boolean indicating whether a returned ndarray should be writable. This - parameter only applies to ndarray constructors which support read-only - instances. - - Returns - ------- - out: ndarray - Output array view. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > x.shape - [ 2, 2 ] - > var y = {{alias}}( x, 1, 1, false, false ) - - > 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 9dfeaf3..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,164 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sliceDimensionFrom = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = 0; - - sliceDimensionFrom( empty( 'float64', sh, order ), 1, s, false, false ); // $ExpectType float64ndarray - sliceDimensionFrom( empty( 'float32', sh, order ), 1, s, false, false ); // $ExpectType float32ndarray - sliceDimensionFrom( empty( 'complex128', sh, order ), 1, s, false, false ); // $ExpectType complex128ndarray - sliceDimensionFrom( empty( 'complex64', sh, order ), 1, s, false, false ); // $ExpectType complex64ndarray - sliceDimensionFrom( empty( 'int32', sh, order ), 1, s, false, false ); // $ExpectType int32ndarray - sliceDimensionFrom( empty( 'int16', sh, order ), 1, s, false, false ); // $ExpectType int16ndarray - sliceDimensionFrom( empty( 'int8', sh, order ), 1, s, false, false ); // $ExpectType int8ndarray - sliceDimensionFrom( empty( 'uint32', sh, order ), 1, s, false, false ); // $ExpectType uint32ndarray - sliceDimensionFrom( empty( 'uint16', sh, order ), 1, s, false, false ); // $ExpectType uint16ndarray - sliceDimensionFrom( empty( 'uint8', sh, order ), 1, s, false, false ); // $ExpectType uint8ndarray - sliceDimensionFrom( empty( 'uint8c', sh, order ), 1, s, false, false ); // $ExpectType uint8cndarray - - sliceDimensionFrom( empty( 'float64', sh, order ), 1, s, true, true ); // $ExpectType float64ndarray - sliceDimensionFrom( empty( 'float32', sh, order ), 1, s, true, true ); // $ExpectType float32ndarray - sliceDimensionFrom( empty( 'complex128', sh, order ), 1, s, true, true ); // $ExpectType complex128ndarray - sliceDimensionFrom( empty( 'complex64', sh, order ), 1, s, true, true ); // $ExpectType complex64ndarray - sliceDimensionFrom( empty( 'int32', sh, order ), 1, s, true, true ); // $ExpectType int32ndarray - sliceDimensionFrom( empty( 'int16', sh, order ), 1, s, true, true ); // $ExpectType int16ndarray - sliceDimensionFrom( empty( 'int8', sh, order ), 1, s, true, true ); // $ExpectType int8ndarray - sliceDimensionFrom( empty( 'uint32', sh, order ), 1, s, true, true ); // $ExpectType uint32ndarray - sliceDimensionFrom( empty( 'uint16', sh, order ), 1, s, true, true ); // $ExpectType uint16ndarray - sliceDimensionFrom( empty( 'uint8', sh, order ), 1, s, true, true ); // $ExpectType uint8ndarray - sliceDimensionFrom( empty( 'uint8c', sh, order ), 1, s, true, true ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const s = 0; - - sliceDimensionFrom( '10', 1, s, false, false ); // $ExpectError - sliceDimensionFrom( 10, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( false, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( true, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( null, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( [], 1, s, false, false ); // $ExpectError - sliceDimensionFrom( {}, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( ( x: number ): number => x, 1, s, false, false ); // $ExpectError - - sliceDimensionFrom( '10', 1, s, true, true ); // $ExpectError - sliceDimensionFrom( 10, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( false, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( true, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( null, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( [], 1, s, true, true ); // $ExpectError - sliceDimensionFrom( {}, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( ( x: number ): number => x, 1, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a number... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 1; - - sliceDimensionFrom( x, '5', s, false, false ); // $ExpectError - sliceDimensionFrom( x, false, s, false, false ); // $ExpectError - sliceDimensionFrom( x, true, s, false, false ); // $ExpectError - sliceDimensionFrom( x, null, s, false, false ); // $ExpectError - sliceDimensionFrom( x, undefined, s, false, false ); // $ExpectError - sliceDimensionFrom( x, [ '5' ], s, false, false ); // $ExpectError - sliceDimensionFrom( x, {}, s, false, false ); // $ExpectError - sliceDimensionFrom( x, ( x: number ): number => x, s, false, false ); // $ExpectError - - sliceDimensionFrom( x, '5', s, true, true ); // $ExpectError - sliceDimensionFrom( x, false, s, true, true ); // $ExpectError - sliceDimensionFrom( x, true, s, true, true ); // $ExpectError - sliceDimensionFrom( x, null, s, true, true ); // $ExpectError - sliceDimensionFrom( x, undefined, s, true, true ); // $ExpectError - sliceDimensionFrom( x, [ '5' ], s, true, true ); // $ExpectError - sliceDimensionFrom( x, {}, s, true, true ); // $ExpectError - sliceDimensionFrom( x, ( x: number ): number => x, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceDimensionFrom( x, 1, '5', false, false ); // $ExpectError - sliceDimensionFrom( x, 1, false, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, true, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, null, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, undefined, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, [ '5' ], false, false ); // $ExpectError - sliceDimensionFrom( x, 1, {}, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, ( x: number ): number => x, 1, false, false ); // $ExpectError - - sliceDimensionFrom( x, 1, '5', true, true ); // $ExpectError - sliceDimensionFrom( x, 1, false, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, true, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, null, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, undefined, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, [ '5' ], true, true ); // $ExpectError - sliceDimensionFrom( x, 1, {}, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, ( x: number ): number => x, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x, 1, s, '5', false ); // $ExpectError - sliceDimensionFrom( x, 1, s, 5, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, null, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, undefined, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, [ '5' ], false ); // $ExpectError - sliceDimensionFrom( x, 1, s, {}, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x, 1, s, false, '5' ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, 5 ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, null ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, undefined ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, [ '5' ] ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, {} ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x ); // $ExpectError - sliceDimensionFrom( x, 1 ); // $ExpectError - sliceDimensionFrom( x, 1, s ); // $ExpectError - sliceDimensionFrom( x, 1, s, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index b17162a..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 sliceDimensionFrom = 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 = sliceDimensionFrom( x, 1, 1, false, false ); -// 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 columns of each matrix: -var y2 = sliceDimensionFrom( x, 2, 1, false, false ); -// returns - -var a2 = ndarray2array( y2 ); -console.log( a2 ); -// => [ [ [ 1, 2 ], [ 4, 5 ], [ 7, 8 ] ], [ [ 10, 11 ], [ 13, 14 ], [ 16, 17 ] ], [ [ 19, 20 ], [ 22, 23 ], [ 25, 26 ] ] ] - -// Get the last two matrices: -var y3 = sliceDimensionFrom( x, 0, 1, false, false ); -// returns - -var a3 = ndarray2array( y3 ); -console.log( a3 ); -// => [ [ [ 9, 10, 11 ], [ 12, 13, 14 ], [ 15, 16, 17 ] ], [ [ 18, 19, 20 ], [ 21, 22, 23 ], [ 24, 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 22f5594..49b5959 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..06b4442 --- /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/slice-base-args2multislice@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-ctor@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndims@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-normalize-index@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-nulls@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function m(m,l,o,j,a){var p,h,v;if(0===(h=r(m)))throw new TypeError(d("1lDF7",h));if(-1===(v=i(l,h-1)))throw new RangeError(d("1lDF8",h,l));return(p=n(h))[v]=new e(o,null),t(m,s(p),j,a)}export{m as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..18102ad --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport Slice from '@stdlib/slice-ctor';\nimport ndims from '@stdlib/ndarray-base-ndims';\nimport slice from '@stdlib/ndarray-base-slice';\nimport normalizeIndex from '@stdlib/ndarray-base-normalize-index';\nimport nulls from '@stdlib/array-base-nulls';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns a shifted view of an input ndarray along a specified dimension.\n*\n* @param {ndarray} x - input array\n* @param {integer} dim - index of dimension to slice\n* @param {integer} start - starting index (inclusive)\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {TypeError} first argument must be an ndarray having one or more dimensions\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\n*\n* @example\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceDimensionFrom( x, 0, 1, false, false );\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 sliceDimensionFrom( x, dim, start, strict, writable ) {\n\tvar args;\n\tvar N;\n\tvar d;\n\n\t// Retrieve array meta data:\n\tN = ndims( x );\n\n\t// Check whether we were provided a zero-dimensional array...\n\tif ( N === 0 ) {\n\t\tthrow new TypeError( format( '1lDF7', N ) );\n\t}\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, N-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( '1lDF8', N, dim ) );\n\t}\n\t// Define a list of slice arguments:\n\targs = nulls( N );\n\targs[ d ] = new Slice( start, null );\n\n\t// Return a new array view:\n\treturn slice( x, args2multislice( args ), strict, writable );\n}\n\n\n// EXPORTS //\n\nexport default sliceDimensionFrom;\n"],"names":["sliceDimensionFrom","x","dim","start","strict","writable","args","N","d","ndims","TypeError","format","normalizeIndex","RangeError","nulls","Slice","slice","args2multislice"],"mappings":";;gpBAyEA,SAASA,EAAoBC,EAAGC,EAAKC,EAAOC,EAAQC,GACnD,IAAIC,EACAC,EACAC,EAMJ,GAAW,KAHXD,EAAIE,EAAOR,IAIV,MAAM,IAAIS,UAAWC,EAAQ,QAASJ,IAIvC,IAAY,KADZC,EAAII,EAAgBV,EAAKK,EAAE,IAE1B,MAAM,IAAIM,WAAYF,EAAQ,QAASJ,EAAGL,IAO3C,OAJAI,EAAOQ,EAAOP,IACRC,GAAM,IAAIO,EAAOZ,EAAO,MAGvBa,EAAOf,EAAGgB,EAAiBX,GAAQF,EAAQC,EACnD"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index b3f97b2..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 shifted view of an input ndarray along a specified dimension. -* -* @module @stdlib/ndarray-base-slice-dimension-from -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var sliceDimensionFrom = require( '@stdlib/ndarray-base-slice-dimension-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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // 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 50e4c67..0000000 --- a/lib/main.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var Slice = require( '@stdlib/slice-ctor' ); -var ndims = require( '@stdlib/ndarray-base-ndims' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' ); -var nulls = require( '@stdlib/array-base-nulls' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param {ndarray} x - input array -* @param {integer} dim - index of dimension to slice -* @param {integer} start - starting index (inclusive) -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @param {boolean} writable - boolean indicating whether a returned array should be writable -* @throws {TypeError} first argument must be an ndarray having one or more dimensions -* @throws {RangeError} dimension index exceeds the number of dimensions -* @throws {RangeError} slice 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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -function sliceDimensionFrom( x, dim, start, strict, writable ) { - var args; - var N; - var d; - - // Retrieve array meta data: - N = ndims( x ); - - // Check whether we were provided a zero-dimensional array... - if ( N === 0 ) { - throw new TypeError( format( '1lDF7', N ) ); - } - // Normalize the dimension index: - d = normalizeIndex( dim, N-1 ); - if ( d === -1 ) { - throw new RangeError( format( '1lDF8', N, dim ) ); - } - // Define a list of slice arguments: - args = nulls( N ); - args[ d ] = new Slice( start, null ); - - // Return a new array view: - return slice( x, args2multislice( args ), strict, writable ); -} - - -// EXPORTS // - -module.exports = sliceDimensionFrom; diff --git a/package.json b/package.json index 2e535c3..eb2ee55 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Return a shifted view of an input ndarray along a specific dimension.", "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,50 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-nulls": "github:stdlib-js/array-base-nulls#main", - "@stdlib/ndarray-base-ndims": "^0.2.2", - "@stdlib/ndarray-base-normalize-index": "^0.2.2", - "@stdlib/ndarray-base-slice": "^0.2.2", - "@stdlib/slice-base-args2multislice": "^0.2.2", - "@stdlib/slice-ctor": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/array-typed": "^0.3.0", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-base-empty": "^0.3.0", - "@stdlib/ndarray-base-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..8f38f04 --- /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 28703b5..0000000 --- a/test/test.js +++ /dev/null @@ -1,616 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 ndarray2array = require( '@stdlib/ndarray-to-array' ); -var baseCtor = require( '@stdlib/ndarray-base-ctor' ); -var ctor = require( '@stdlib/ndarray-ctor' ); -var sliceDimensionFrom = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sliceDimensionFrom, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a zero-dimensional array (strict=false)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error' ); - } - t.end(); - - function badValue( x ) { - return function badValue() { - sliceDimensionFrom( x, 0, 0, false, false ); - }; - } -}); - -tape( 'the function throws an error if provided a zero-dimensional array (strict=true)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error' ); - } - t.end(); - - function badValue( x ) { - return function badValue() { - sliceDimensionFrom( x, 0, 0, true, false ); - }; - } -}); - -tape( 'the function throws an error if the dimension index exceeds the number of dimensions (strict=false)', 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 ], 10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - t.throws( badValue( values[ i ], -10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - } - t.end(); - - function badValue( x, dim ) { - return function badValue() { - sliceDimensionFrom( x, dim, 0, false, false ); - }; - } -}); - -tape( 'the function throws an error if the dimension index exceeds the number of dimensions (strict=true)', 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 ], 10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - t.throws( badValue( values[ i ], -10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - } - t.end(); - - function badValue( x, dim ) { - return function badValue() { - sliceDimensionFrom( x, dim, 0, true, false ); - }; - } -}); - -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, - 20, - 20, - 20 - ]; - 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() { - sliceDimensionFrom( x, 0, s, true, false ); - }; - } -}); - -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, - 20, - 20, - 20, - 10 - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceDimensionFrom( values[ i ], 0, start[ i ], false, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), 0, 'returns expected value' ); - t.strictEqual( actual.dtype, values[ i ].dtype, 'returns expected value' ); - } - t.end(); -}); - -tape( 'in non-strict mode, the function returns an empty array when a starting index is the one more than the last index along a dimension', function test( t ) { - var actual; - var values; - var start; - var dim; - 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' } ) - ]; - - dim = [ - 0, - 1, - 0, - 1, - 4 - ]; - - start = [ - 1, - 1, - 1, - 1, - 1 - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceDimensionFrom( values[ i ], dim[ i ], start[ i ], false, false ); // eslint-disable-line max-len - 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 a shifted view of a provided input array (ndims=1)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 2, true, false ); - - 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 = sliceDimensionFrom( x, 0, -4, true, false ); - - 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)', 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 1, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 2, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, -2, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 1, 1, true, false ); - - 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 = sliceDimensionFrom( x, 1, -2, true, false ); - - 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' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=3)', 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 1, true, false ); - - 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 = sliceDimensionFrom( x, 1, 1, true, false ); - - 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 = sliceDimensionFrom( x, 2, 2, true, false ); - - 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 = sliceDimensionFrom( x, 2, -1, true, false ); - - 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' ); - t.end(); -}); - -tape( 'if a provided ndarray has a constructor supporting read-only instances, the function returns a read-only instance', function test( t ) { - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - x = new baseCtor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports returning writable views', function test( t ) { - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - x = new baseCtor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - t.end(); -}); From af0c3f364d710c1b33617413a75b8bbbf1c8db43 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Nov 2024 08:28:43 +0000 Subject: [PATCH 62/92] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 54bb1c2..50e4c67 100644 --- a/lib/main.js +++ b/lib/main.js @@ -26,7 +26,7 @@ var ndims = require( '@stdlib/ndarray-base-ndims' ); var slice = require( '@stdlib/ndarray-base-slice' ); var normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' ); var nulls = require( '@stdlib/array-base-nulls' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -81,12 +81,12 @@ function sliceDimensionFrom( x, dim, start, strict, writable ) { // Check whether we were provided a zero-dimensional array... if ( N === 0 ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.', N ) ); + throw new TypeError( format( '1lDF7', N ) ); } // Normalize the dimension index: d = normalizeIndex( dim, N-1 ); if ( d === -1 ) { - throw new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', N, dim ) ); + throw new RangeError( format( '1lDF8', N, dim ) ); } // Define a list of slice arguments: args = nulls( N ); diff --git a/package.json b/package.json index 524b4e6..2e535c3 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/ndarray-base-slice": "^0.2.2", "@stdlib/slice-base-args2multislice": "^0.2.2", "@stdlib/slice-ctor": "^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 2c7aba65025e817424c4496561884f29faff4ce1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Nov 2024 12:30:37 +0000 Subject: [PATCH 63/92] Remove files --- index.d.ts | 534 ------ index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5381 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 49b5959..0000000 --- a/index.d.ts +++ /dev/null @@ -1,534 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceDimensionFrom( x: float64ndarray, dim: number, start: number, strict: boolean, writable: boolean ): float64ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceDimensionFrom( x: float32ndarray, dim: number, start: number, strict: boolean, writable: boolean ): float32ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: int32ndarray, dim: number, start: number, strict: boolean, writable: boolean ): int32ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: int16ndarray, dim: number, start: number, strict: boolean, writable: boolean ): int16ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: int8ndarray, dim: number, start: number, strict: boolean, writable: boolean ): int8ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint32ndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint32ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint16ndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint16ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint8ndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint8ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint8cndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint8cndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceDimensionFrom( x: complex128ndarray, dim: number, start: number, strict: boolean, writable: boolean ): complex128ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceDimensionFrom( x: complex64ndarray, dim: number, start: number, strict: boolean, writable: boolean ): complex64ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: genericndarray, dim: number, start: number, strict: boolean, writable: boolean ): genericndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: typedndarray, dim: number, start: number, strict: boolean, writable: boolean ): typedndarray; - - -// EXPORTS // - -export = sliceDimensionFrom; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 06b4442..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/slice-base-args2multislice@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-ctor@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndims@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-normalize-index@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-nulls@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function m(m,l,o,j,a){var p,h,v;if(0===(h=r(m)))throw new TypeError(d("1lDF7",h));if(-1===(v=i(l,h-1)))throw new RangeError(d("1lDF8",h,l));return(p=n(h))[v]=new e(o,null),t(m,s(p),j,a)}export{m as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 18102ad..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport Slice from '@stdlib/slice-ctor';\nimport ndims from '@stdlib/ndarray-base-ndims';\nimport slice from '@stdlib/ndarray-base-slice';\nimport normalizeIndex from '@stdlib/ndarray-base-normalize-index';\nimport nulls from '@stdlib/array-base-nulls';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns a shifted view of an input ndarray along a specified dimension.\n*\n* @param {ndarray} x - input array\n* @param {integer} dim - index of dimension to slice\n* @param {integer} start - starting index (inclusive)\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {TypeError} first argument must be an ndarray having one or more dimensions\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\n*\n* @example\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceDimensionFrom( x, 0, 1, false, false );\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 sliceDimensionFrom( x, dim, start, strict, writable ) {\n\tvar args;\n\tvar N;\n\tvar d;\n\n\t// Retrieve array meta data:\n\tN = ndims( x );\n\n\t// Check whether we were provided a zero-dimensional array...\n\tif ( N === 0 ) {\n\t\tthrow new TypeError( format( '1lDF7', N ) );\n\t}\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, N-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( '1lDF8', N, dim ) );\n\t}\n\t// Define a list of slice arguments:\n\targs = nulls( N );\n\targs[ d ] = new Slice( start, null );\n\n\t// Return a new array view:\n\treturn slice( x, args2multislice( args ), strict, writable );\n}\n\n\n// EXPORTS //\n\nexport default sliceDimensionFrom;\n"],"names":["sliceDimensionFrom","x","dim","start","strict","writable","args","N","d","ndims","TypeError","format","normalizeIndex","RangeError","nulls","Slice","slice","args2multislice"],"mappings":";;gpBAyEA,SAASA,EAAoBC,EAAGC,EAAKC,EAAOC,EAAQC,GACnD,IAAIC,EACAC,EACAC,EAMJ,GAAW,KAHXD,EAAIE,EAAOR,IAIV,MAAM,IAAIS,UAAWC,EAAQ,QAASJ,IAIvC,IAAY,KADZC,EAAII,EAAgBV,EAAKK,EAAE,IAE1B,MAAM,IAAIM,WAAYF,EAAQ,QAASJ,EAAGL,IAO3C,OAJAI,EAAOQ,EAAOP,IACRC,GAAM,IAAIO,EAAOZ,EAAO,MAGvBa,EAAOf,EAAGgB,EAAiBX,GAAQF,EAAQC,EACnD"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 8f38f04..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 715ab47ddd21e657af34852a9f95dc9ac4d81812 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Nov 2024 12:31:06 +0000 Subject: [PATCH 64/92] 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 | 150 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 45 +- SECURITY.md | 5 - benchmark/benchmark.js | 681 --- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 49 - docs/types/test.ts | 164 - 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 | 102 - package.json | 71 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 616 --- 43 files changed, 4868 insertions(+), 5276 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 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 217387d..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-11-01T06:35:12.041Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 05d1840..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-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 ced95ae..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-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 60a2bb4..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: '38 14 * * 5' - - # 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 + + ```
@@ -202,7 +193,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]. diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 8a6b7a2..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,681 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 sliceDimensionFrom = require( './../lib' ); - - -// MAIN // - -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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2 ], { 'dtype': 'float64' } ), - empty( [ 2 ], { 'dtype': 'float32' } ), - empty( [ 2 ], { 'dtype': 'int32' } ), - empty( [ 2 ], { 'dtype': 'complex128' } ), - empty( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== '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 9543fcd..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-from" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-from -[production-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-slice-dimension-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 2ab577a..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import sliceDimensionFrom from '../docs/types/index'; -export = sliceDimensionFrom; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 2f5466d..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var v=function(i,r){return function(){return r||i((r={exports:{}}).exports,r),r.exports}};var o=v(function(p,u){"use strict";var l=require("@stdlib/slice-base-args2multislice"),c=require("@stdlib/slice-ctor"),q=require("@stdlib/ndarray-base-ndims"),f=require("@stdlib/ndarray-base-slice"),g=require("@stdlib/ndarray-base-normalize-index"),w=require("@stdlib/array-base-nulls"),s=require("@stdlib/string-format");function b(i,r,m,t,d){var n,e,a;if(e=q(i),e===0)throw new TypeError(s("invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.",e));if(a=g(r,e-1),a===-1)throw new RangeError(s("invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.",e,r));return n=w(e),n[a]=new c(m,null),f(i,l(n),t,d)}u.exports=b});var h=o();module.exports=h; -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 19dddde..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar args2multislice = require( '@stdlib/slice-base-args2multislice' );\nvar Slice = require( '@stdlib/slice-ctor' );\nvar ndims = require( '@stdlib/ndarray-base-ndims' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' );\nvar nulls = require( '@stdlib/array-base-nulls' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns a shifted view of an input ndarray along a specified dimension.\n*\n* @param {ndarray} x - input array\n* @param {integer} dim - index of dimension to slice\n* @param {integer} start - starting index (inclusive)\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {TypeError} first argument must be an ndarray having one or more dimensions\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceDimensionFrom( x, 0, 1, false, false );\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 sliceDimensionFrom( x, dim, start, strict, writable ) {\n\tvar args;\n\tvar N;\n\tvar d;\n\n\t// Retrieve array meta data:\n\tN = ndims( x );\n\n\t// Check whether we were provided a zero-dimensional array...\n\tif ( N === 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.', N ) );\n\t}\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, N-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', N, dim ) );\n\t}\n\t// Define a list of slice arguments:\n\targs = nulls( N );\n\targs[ d ] = new Slice( start, null );\n\n\t// Return a new array view:\n\treturn slice( x, args2multislice( args ), strict, writable );\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceDimensionFrom;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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 shifted view of an input ndarray along a specified dimension.\n*\n* @module @stdlib/ndarray-base-slice-dimension-from\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var sliceDimensionFrom = require( '@stdlib/ndarray-base-slice-dimension-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 = sliceDimensionFrom( x, 0, 1, false, false );\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,EAAkB,QAAS,oCAAqC,EAChEC,EAAQ,QAAS,oBAAqB,EACtCC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAiB,QAAS,sCAAuC,EACjEC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAS,QAAS,uBAAwB,EA6C9C,SAASC,EAAoBC,EAAGC,EAAKC,EAAOC,EAAQC,EAAW,CAC9D,IAAIC,EACAC,EACAC,EAMJ,GAHAD,EAAIZ,EAAOM,CAAE,EAGRM,IAAM,EACV,MAAM,IAAI,UAAWR,EAAQ,+GAAgHQ,CAAE,CAAE,EAIlJ,GADAC,EAAIX,EAAgBK,EAAKK,EAAE,CAAE,EACxBC,IAAM,GACV,MAAM,IAAI,WAAYT,EAAQ,6GAA8GQ,EAAGL,CAAI,CAAE,EAGtJ,OAAAI,EAAOR,EAAOS,CAAE,EAChBD,EAAME,CAAE,EAAI,IAAId,EAAOS,EAAO,IAAK,EAG5BP,EAAOK,EAAGR,EAAiBa,CAAK,EAAGF,EAAQC,CAAS,CAC5D,CAKAb,EAAO,QAAUQ,IC7CjB,IAAIS,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "args2multislice", "Slice", "ndims", "slice", "normalizeIndex", "nulls", "format", "sliceDimensionFrom", "x", "dim", "start", "strict", "writable", "args", "N", "d", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ffc1f03..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,49 +0,0 @@ - -{{alias}}( x, dim, start, strict, writable ) - Returns a shifted view of an input ndarray along a specified dimension. - - Parameters - ---------- - x: ndarray - Input array. - - dim: integer - Index of dimension to slice. If less than zero, the index is resolved - relative to the last dimension, with the last dimension corresponding to - the value `-1`. - - start: integer - Starting index (inclusive). If less than zero, the corresponding element - along the specified dimension is resolved relative to the last element - along that dimension. For negative integers, the last element - corresponds to the value `-1`. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - writable: boolean - Boolean indicating whether a returned ndarray should be writable. This - parameter only applies to ndarray constructors which support read-only - instances. - - Returns - ------- - out: ndarray - Output array view. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > x.shape - [ 2, 2 ] - > var y = {{alias}}( x, 1, 1, false, false ) - - > 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 9dfeaf3..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,164 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sliceDimensionFrom = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = 0; - - sliceDimensionFrom( empty( 'float64', sh, order ), 1, s, false, false ); // $ExpectType float64ndarray - sliceDimensionFrom( empty( 'float32', sh, order ), 1, s, false, false ); // $ExpectType float32ndarray - sliceDimensionFrom( empty( 'complex128', sh, order ), 1, s, false, false ); // $ExpectType complex128ndarray - sliceDimensionFrom( empty( 'complex64', sh, order ), 1, s, false, false ); // $ExpectType complex64ndarray - sliceDimensionFrom( empty( 'int32', sh, order ), 1, s, false, false ); // $ExpectType int32ndarray - sliceDimensionFrom( empty( 'int16', sh, order ), 1, s, false, false ); // $ExpectType int16ndarray - sliceDimensionFrom( empty( 'int8', sh, order ), 1, s, false, false ); // $ExpectType int8ndarray - sliceDimensionFrom( empty( 'uint32', sh, order ), 1, s, false, false ); // $ExpectType uint32ndarray - sliceDimensionFrom( empty( 'uint16', sh, order ), 1, s, false, false ); // $ExpectType uint16ndarray - sliceDimensionFrom( empty( 'uint8', sh, order ), 1, s, false, false ); // $ExpectType uint8ndarray - sliceDimensionFrom( empty( 'uint8c', sh, order ), 1, s, false, false ); // $ExpectType uint8cndarray - - sliceDimensionFrom( empty( 'float64', sh, order ), 1, s, true, true ); // $ExpectType float64ndarray - sliceDimensionFrom( empty( 'float32', sh, order ), 1, s, true, true ); // $ExpectType float32ndarray - sliceDimensionFrom( empty( 'complex128', sh, order ), 1, s, true, true ); // $ExpectType complex128ndarray - sliceDimensionFrom( empty( 'complex64', sh, order ), 1, s, true, true ); // $ExpectType complex64ndarray - sliceDimensionFrom( empty( 'int32', sh, order ), 1, s, true, true ); // $ExpectType int32ndarray - sliceDimensionFrom( empty( 'int16', sh, order ), 1, s, true, true ); // $ExpectType int16ndarray - sliceDimensionFrom( empty( 'int8', sh, order ), 1, s, true, true ); // $ExpectType int8ndarray - sliceDimensionFrom( empty( 'uint32', sh, order ), 1, s, true, true ); // $ExpectType uint32ndarray - sliceDimensionFrom( empty( 'uint16', sh, order ), 1, s, true, true ); // $ExpectType uint16ndarray - sliceDimensionFrom( empty( 'uint8', sh, order ), 1, s, true, true ); // $ExpectType uint8ndarray - sliceDimensionFrom( empty( 'uint8c', sh, order ), 1, s, true, true ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const s = 0; - - sliceDimensionFrom( '10', 1, s, false, false ); // $ExpectError - sliceDimensionFrom( 10, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( false, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( true, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( null, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( [], 1, s, false, false ); // $ExpectError - sliceDimensionFrom( {}, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( ( x: number ): number => x, 1, s, false, false ); // $ExpectError - - sliceDimensionFrom( '10', 1, s, true, true ); // $ExpectError - sliceDimensionFrom( 10, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( false, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( true, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( null, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( [], 1, s, true, true ); // $ExpectError - sliceDimensionFrom( {}, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( ( x: number ): number => x, 1, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a number... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 1; - - sliceDimensionFrom( x, '5', s, false, false ); // $ExpectError - sliceDimensionFrom( x, false, s, false, false ); // $ExpectError - sliceDimensionFrom( x, true, s, false, false ); // $ExpectError - sliceDimensionFrom( x, null, s, false, false ); // $ExpectError - sliceDimensionFrom( x, undefined, s, false, false ); // $ExpectError - sliceDimensionFrom( x, [ '5' ], s, false, false ); // $ExpectError - sliceDimensionFrom( x, {}, s, false, false ); // $ExpectError - sliceDimensionFrom( x, ( x: number ): number => x, s, false, false ); // $ExpectError - - sliceDimensionFrom( x, '5', s, true, true ); // $ExpectError - sliceDimensionFrom( x, false, s, true, true ); // $ExpectError - sliceDimensionFrom( x, true, s, true, true ); // $ExpectError - sliceDimensionFrom( x, null, s, true, true ); // $ExpectError - sliceDimensionFrom( x, undefined, s, true, true ); // $ExpectError - sliceDimensionFrom( x, [ '5' ], s, true, true ); // $ExpectError - sliceDimensionFrom( x, {}, s, true, true ); // $ExpectError - sliceDimensionFrom( x, ( x: number ): number => x, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceDimensionFrom( x, 1, '5', false, false ); // $ExpectError - sliceDimensionFrom( x, 1, false, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, true, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, null, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, undefined, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, [ '5' ], false, false ); // $ExpectError - sliceDimensionFrom( x, 1, {}, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, ( x: number ): number => x, 1, false, false ); // $ExpectError - - sliceDimensionFrom( x, 1, '5', true, true ); // $ExpectError - sliceDimensionFrom( x, 1, false, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, true, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, null, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, undefined, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, [ '5' ], true, true ); // $ExpectError - sliceDimensionFrom( x, 1, {}, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, ( x: number ): number => x, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x, 1, s, '5', false ); // $ExpectError - sliceDimensionFrom( x, 1, s, 5, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, null, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, undefined, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, [ '5' ], false ); // $ExpectError - sliceDimensionFrom( x, 1, s, {}, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x, 1, s, false, '5' ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, 5 ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, null ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, undefined ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, [ '5' ] ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, {} ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x ); // $ExpectError - sliceDimensionFrom( x, 1 ); // $ExpectError - sliceDimensionFrom( x, 1, s ); // $ExpectError - sliceDimensionFrom( x, 1, s, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index b17162a..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 sliceDimensionFrom = 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 = sliceDimensionFrom( x, 1, 1, false, false ); -// 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 columns of each matrix: -var y2 = sliceDimensionFrom( x, 2, 1, false, false ); -// returns - -var a2 = ndarray2array( y2 ); -console.log( a2 ); -// => [ [ [ 1, 2 ], [ 4, 5 ], [ 7, 8 ] ], [ [ 10, 11 ], [ 13, 14 ], [ 16, 17 ] ], [ [ 19, 20 ], [ 22, 23 ], [ 25, 26 ] ] ] - -// Get the last two matrices: -var y3 = sliceDimensionFrom( x, 0, 1, false, false ); -// returns - -var a3 = ndarray2array( y3 ); -console.log( a3 ); -// => [ [ [ 9, 10, 11 ], [ 12, 13, 14 ], [ 15, 16, 17 ] ], [ [ 18, 19, 20 ], [ 21, 22, 23 ], [ 24, 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 22f5594..49b5959 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..06b4442 --- /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/slice-base-args2multislice@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-ctor@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndims@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-normalize-index@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-nulls@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function m(m,l,o,j,a){var p,h,v;if(0===(h=r(m)))throw new TypeError(d("1lDF7",h));if(-1===(v=i(l,h-1)))throw new RangeError(d("1lDF8",h,l));return(p=n(h))[v]=new e(o,null),t(m,s(p),j,a)}export{m as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..18102ad --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport Slice from '@stdlib/slice-ctor';\nimport ndims from '@stdlib/ndarray-base-ndims';\nimport slice from '@stdlib/ndarray-base-slice';\nimport normalizeIndex from '@stdlib/ndarray-base-normalize-index';\nimport nulls from '@stdlib/array-base-nulls';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns a shifted view of an input ndarray along a specified dimension.\n*\n* @param {ndarray} x - input array\n* @param {integer} dim - index of dimension to slice\n* @param {integer} start - starting index (inclusive)\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {TypeError} first argument must be an ndarray having one or more dimensions\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\n*\n* @example\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceDimensionFrom( x, 0, 1, false, false );\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 sliceDimensionFrom( x, dim, start, strict, writable ) {\n\tvar args;\n\tvar N;\n\tvar d;\n\n\t// Retrieve array meta data:\n\tN = ndims( x );\n\n\t// Check whether we were provided a zero-dimensional array...\n\tif ( N === 0 ) {\n\t\tthrow new TypeError( format( '1lDF7', N ) );\n\t}\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, N-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( '1lDF8', N, dim ) );\n\t}\n\t// Define a list of slice arguments:\n\targs = nulls( N );\n\targs[ d ] = new Slice( start, null );\n\n\t// Return a new array view:\n\treturn slice( x, args2multislice( args ), strict, writable );\n}\n\n\n// EXPORTS //\n\nexport default sliceDimensionFrom;\n"],"names":["sliceDimensionFrom","x","dim","start","strict","writable","args","N","d","ndims","TypeError","format","normalizeIndex","RangeError","nulls","Slice","slice","args2multislice"],"mappings":";;gpBAyEA,SAASA,EAAoBC,EAAGC,EAAKC,EAAOC,EAAQC,GACnD,IAAIC,EACAC,EACAC,EAMJ,GAAW,KAHXD,EAAIE,EAAOR,IAIV,MAAM,IAAIS,UAAWC,EAAQ,QAASJ,IAIvC,IAAY,KADZC,EAAII,EAAgBV,EAAKK,EAAE,IAE1B,MAAM,IAAIM,WAAYF,EAAQ,QAASJ,EAAGL,IAO3C,OAJAI,EAAOQ,EAAOP,IACRC,GAAM,IAAIO,EAAOZ,EAAO,MAGvBa,EAAOf,EAAGgB,EAAiBX,GAAQF,EAAQC,EACnD"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index b3f97b2..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 shifted view of an input ndarray along a specified dimension. -* -* @module @stdlib/ndarray-base-slice-dimension-from -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var sliceDimensionFrom = require( '@stdlib/ndarray-base-slice-dimension-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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // 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 50e4c67..0000000 --- a/lib/main.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var Slice = require( '@stdlib/slice-ctor' ); -var ndims = require( '@stdlib/ndarray-base-ndims' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' ); -var nulls = require( '@stdlib/array-base-nulls' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param {ndarray} x - input array -* @param {integer} dim - index of dimension to slice -* @param {integer} start - starting index (inclusive) -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @param {boolean} writable - boolean indicating whether a returned array should be writable -* @throws {TypeError} first argument must be an ndarray having one or more dimensions -* @throws {RangeError} dimension index exceeds the number of dimensions -* @throws {RangeError} slice 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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -function sliceDimensionFrom( x, dim, start, strict, writable ) { - var args; - var N; - var d; - - // Retrieve array meta data: - N = ndims( x ); - - // Check whether we were provided a zero-dimensional array... - if ( N === 0 ) { - throw new TypeError( format( '1lDF7', N ) ); - } - // Normalize the dimension index: - d = normalizeIndex( dim, N-1 ); - if ( d === -1 ) { - throw new RangeError( format( '1lDF8', N, dim ) ); - } - // Define a list of slice arguments: - args = nulls( N ); - args[ d ] = new Slice( start, null ); - - // Return a new array view: - return slice( x, args2multislice( args ), strict, writable ); -} - - -// EXPORTS // - -module.exports = sliceDimensionFrom; diff --git a/package.json b/package.json index 2e535c3..eb2ee55 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Return a shifted view of an input ndarray along a specific dimension.", "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,50 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-nulls": "github:stdlib-js/array-base-nulls#main", - "@stdlib/ndarray-base-ndims": "^0.2.2", - "@stdlib/ndarray-base-normalize-index": "^0.2.2", - "@stdlib/ndarray-base-slice": "^0.2.2", - "@stdlib/slice-base-args2multislice": "^0.2.2", - "@stdlib/slice-ctor": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/array-typed": "^0.3.0", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-base-empty": "^0.3.0", - "@stdlib/ndarray-base-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..8f38f04 --- /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 28703b5..0000000 --- a/test/test.js +++ /dev/null @@ -1,616 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 ndarray2array = require( '@stdlib/ndarray-to-array' ); -var baseCtor = require( '@stdlib/ndarray-base-ctor' ); -var ctor = require( '@stdlib/ndarray-ctor' ); -var sliceDimensionFrom = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sliceDimensionFrom, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a zero-dimensional array (strict=false)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error' ); - } - t.end(); - - function badValue( x ) { - return function badValue() { - sliceDimensionFrom( x, 0, 0, false, false ); - }; - } -}); - -tape( 'the function throws an error if provided a zero-dimensional array (strict=true)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error' ); - } - t.end(); - - function badValue( x ) { - return function badValue() { - sliceDimensionFrom( x, 0, 0, true, false ); - }; - } -}); - -tape( 'the function throws an error if the dimension index exceeds the number of dimensions (strict=false)', 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 ], 10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - t.throws( badValue( values[ i ], -10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - } - t.end(); - - function badValue( x, dim ) { - return function badValue() { - sliceDimensionFrom( x, dim, 0, false, false ); - }; - } -}); - -tape( 'the function throws an error if the dimension index exceeds the number of dimensions (strict=true)', 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 ], 10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - t.throws( badValue( values[ i ], -10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - } - t.end(); - - function badValue( x, dim ) { - return function badValue() { - sliceDimensionFrom( x, dim, 0, true, false ); - }; - } -}); - -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, - 20, - 20, - 20 - ]; - 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() { - sliceDimensionFrom( x, 0, s, true, false ); - }; - } -}); - -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, - 20, - 20, - 20, - 10 - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceDimensionFrom( values[ i ], 0, start[ i ], false, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), 0, 'returns expected value' ); - t.strictEqual( actual.dtype, values[ i ].dtype, 'returns expected value' ); - } - t.end(); -}); - -tape( 'in non-strict mode, the function returns an empty array when a starting index is the one more than the last index along a dimension', function test( t ) { - var actual; - var values; - var start; - var dim; - 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' } ) - ]; - - dim = [ - 0, - 1, - 0, - 1, - 4 - ]; - - start = [ - 1, - 1, - 1, - 1, - 1 - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceDimensionFrom( values[ i ], dim[ i ], start[ i ], false, false ); // eslint-disable-line max-len - 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 a shifted view of a provided input array (ndims=1)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 2, true, false ); - - 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 = sliceDimensionFrom( x, 0, -4, true, false ); - - 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)', 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 1, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 2, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, -2, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 1, 1, true, false ); - - 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 = sliceDimensionFrom( x, 1, -2, true, false ); - - 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' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=3)', 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 1, true, false ); - - 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 = sliceDimensionFrom( x, 1, 1, true, false ); - - 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 = sliceDimensionFrom( x, 2, 2, true, false ); - - 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 = sliceDimensionFrom( x, 2, -1, true, false ); - - 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' ); - t.end(); -}); - -tape( 'if a provided ndarray has a constructor supporting read-only instances, the function returns a read-only instance', function test( t ) { - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - x = new baseCtor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports returning writable views', function test( t ) { - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - x = new baseCtor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - t.end(); -}); From 6de9a0d0e1ee800b9f876e807dbdfe477fc440b1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 23 Dec 2024 01:33:21 +0000 Subject: [PATCH 65/92] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 54bb1c2..50e4c67 100644 --- a/lib/main.js +++ b/lib/main.js @@ -26,7 +26,7 @@ var ndims = require( '@stdlib/ndarray-base-ndims' ); var slice = require( '@stdlib/ndarray-base-slice' ); var normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' ); var nulls = require( '@stdlib/array-base-nulls' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -81,12 +81,12 @@ function sliceDimensionFrom( x, dim, start, strict, writable ) { // Check whether we were provided a zero-dimensional array... if ( N === 0 ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.', N ) ); + throw new TypeError( format( '1lDF7', N ) ); } // Normalize the dimension index: d = normalizeIndex( dim, N-1 ); if ( d === -1 ) { - throw new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', N, dim ) ); + throw new RangeError( format( '1lDF8', N, dim ) ); } // Define a list of slice arguments: args = nulls( N ); diff --git a/package.json b/package.json index 2d85f05..c3c9e81 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/ndarray-base-slice": "^0.2.2", "@stdlib/slice-base-args2multislice": "^0.2.2", "@stdlib/slice-ctor": "^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 81e57022187c36caeff633b8d56b6e9f08cd732b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 23 Dec 2024 01:36:08 +0000 Subject: [PATCH 66/92] Remove files --- index.d.ts | 534 ------ index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5381 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 49b5959..0000000 --- a/index.d.ts +++ /dev/null @@ -1,534 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceDimensionFrom( x: float64ndarray, dim: number, start: number, strict: boolean, writable: boolean ): float64ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceDimensionFrom( x: float32ndarray, dim: number, start: number, strict: boolean, writable: boolean ): float32ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: int32ndarray, dim: number, start: number, strict: boolean, writable: boolean ): int32ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: int16ndarray, dim: number, start: number, strict: boolean, writable: boolean ): int16ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: int8ndarray, dim: number, start: number, strict: boolean, writable: boolean ): int8ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint32ndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint32ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint16ndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint16ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint8ndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint8ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint8cndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint8cndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceDimensionFrom( x: complex128ndarray, dim: number, start: number, strict: boolean, writable: boolean ): complex128ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceDimensionFrom( x: complex64ndarray, dim: number, start: number, strict: boolean, writable: boolean ): complex64ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: genericndarray, dim: number, start: number, strict: boolean, writable: boolean ): genericndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: typedndarray, dim: number, start: number, strict: boolean, writable: boolean ): typedndarray; - - -// EXPORTS // - -export = sliceDimensionFrom; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 06b4442..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/slice-base-args2multislice@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-ctor@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndims@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-normalize-index@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-nulls@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function m(m,l,o,j,a){var p,h,v;if(0===(h=r(m)))throw new TypeError(d("1lDF7",h));if(-1===(v=i(l,h-1)))throw new RangeError(d("1lDF8",h,l));return(p=n(h))[v]=new e(o,null),t(m,s(p),j,a)}export{m as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 18102ad..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport Slice from '@stdlib/slice-ctor';\nimport ndims from '@stdlib/ndarray-base-ndims';\nimport slice from '@stdlib/ndarray-base-slice';\nimport normalizeIndex from '@stdlib/ndarray-base-normalize-index';\nimport nulls from '@stdlib/array-base-nulls';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns a shifted view of an input ndarray along a specified dimension.\n*\n* @param {ndarray} x - input array\n* @param {integer} dim - index of dimension to slice\n* @param {integer} start - starting index (inclusive)\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {TypeError} first argument must be an ndarray having one or more dimensions\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\n*\n* @example\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceDimensionFrom( x, 0, 1, false, false );\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 sliceDimensionFrom( x, dim, start, strict, writable ) {\n\tvar args;\n\tvar N;\n\tvar d;\n\n\t// Retrieve array meta data:\n\tN = ndims( x );\n\n\t// Check whether we were provided a zero-dimensional array...\n\tif ( N === 0 ) {\n\t\tthrow new TypeError( format( '1lDF7', N ) );\n\t}\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, N-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( '1lDF8', N, dim ) );\n\t}\n\t// Define a list of slice arguments:\n\targs = nulls( N );\n\targs[ d ] = new Slice( start, null );\n\n\t// Return a new array view:\n\treturn slice( x, args2multislice( args ), strict, writable );\n}\n\n\n// EXPORTS //\n\nexport default sliceDimensionFrom;\n"],"names":["sliceDimensionFrom","x","dim","start","strict","writable","args","N","d","ndims","TypeError","format","normalizeIndex","RangeError","nulls","Slice","slice","args2multislice"],"mappings":";;gpBAyEA,SAASA,EAAoBC,EAAGC,EAAKC,EAAOC,EAAQC,GACnD,IAAIC,EACAC,EACAC,EAMJ,GAAW,KAHXD,EAAIE,EAAOR,IAIV,MAAM,IAAIS,UAAWC,EAAQ,QAASJ,IAIvC,IAAY,KADZC,EAAII,EAAgBV,EAAKK,EAAE,IAE1B,MAAM,IAAIM,WAAYF,EAAQ,QAASJ,EAAGL,IAO3C,OAJAI,EAAOQ,EAAOP,IACRC,GAAM,IAAIO,EAAOZ,EAAO,MAGvBa,EAAOf,EAAGgB,EAAiBX,GAAQF,EAAQC,EACnD"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 8f38f04..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 54ce0d667ecd1c762d50dadc54fc8605ab337238 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 23 Dec 2024 01:36:29 +0000 Subject: [PATCH 67/92] 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 | 150 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 45 +- SECURITY.md | 5 - benchmark/benchmark.js | 681 --- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 49 - docs/types/test.ts | 164 - 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 | 102 - package.json | 71 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 616 --- 44 files changed, 4868 insertions(+), 5381 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0779e8a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 3d0fb7f..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-12-23T01:32:04.478Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 05d1840..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-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 ced95ae..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-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 60a2bb4..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: '38 14 * * 5' - - # 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 + + ```
@@ -202,7 +193,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]. diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 8a6b7a2..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,681 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 sliceDimensionFrom = require( './../lib' ); - - -// MAIN // - -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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2 ], { 'dtype': 'float64' } ), - empty( [ 2 ], { 'dtype': 'float32' } ), - empty( [ 2 ], { 'dtype': 'int32' } ), - empty( [ 2 ], { 'dtype': 'complex128' } ), - empty( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== '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 9543fcd..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-from" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-from -[production-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-slice-dimension-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 2ab577a..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import sliceDimensionFrom from '../docs/types/index'; -export = sliceDimensionFrom; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 2f5466d..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var v=function(i,r){return function(){return r||i((r={exports:{}}).exports,r),r.exports}};var o=v(function(p,u){"use strict";var l=require("@stdlib/slice-base-args2multislice"),c=require("@stdlib/slice-ctor"),q=require("@stdlib/ndarray-base-ndims"),f=require("@stdlib/ndarray-base-slice"),g=require("@stdlib/ndarray-base-normalize-index"),w=require("@stdlib/array-base-nulls"),s=require("@stdlib/string-format");function b(i,r,m,t,d){var n,e,a;if(e=q(i),e===0)throw new TypeError(s("invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.",e));if(a=g(r,e-1),a===-1)throw new RangeError(s("invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.",e,r));return n=w(e),n[a]=new c(m,null),f(i,l(n),t,d)}u.exports=b});var h=o();module.exports=h; -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 19dddde..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar args2multislice = require( '@stdlib/slice-base-args2multislice' );\nvar Slice = require( '@stdlib/slice-ctor' );\nvar ndims = require( '@stdlib/ndarray-base-ndims' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' );\nvar nulls = require( '@stdlib/array-base-nulls' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns a shifted view of an input ndarray along a specified dimension.\n*\n* @param {ndarray} x - input array\n* @param {integer} dim - index of dimension to slice\n* @param {integer} start - starting index (inclusive)\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {TypeError} first argument must be an ndarray having one or more dimensions\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceDimensionFrom( x, 0, 1, false, false );\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 sliceDimensionFrom( x, dim, start, strict, writable ) {\n\tvar args;\n\tvar N;\n\tvar d;\n\n\t// Retrieve array meta data:\n\tN = ndims( x );\n\n\t// Check whether we were provided a zero-dimensional array...\n\tif ( N === 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.', N ) );\n\t}\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, N-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', N, dim ) );\n\t}\n\t// Define a list of slice arguments:\n\targs = nulls( N );\n\targs[ d ] = new Slice( start, null );\n\n\t// Return a new array view:\n\treturn slice( x, args2multislice( args ), strict, writable );\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceDimensionFrom;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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 shifted view of an input ndarray along a specified dimension.\n*\n* @module @stdlib/ndarray-base-slice-dimension-from\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var sliceDimensionFrom = require( '@stdlib/ndarray-base-slice-dimension-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 = sliceDimensionFrom( x, 0, 1, false, false );\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,EAAkB,QAAS,oCAAqC,EAChEC,EAAQ,QAAS,oBAAqB,EACtCC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAiB,QAAS,sCAAuC,EACjEC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAS,QAAS,uBAAwB,EA6C9C,SAASC,EAAoBC,EAAGC,EAAKC,EAAOC,EAAQC,EAAW,CAC9D,IAAIC,EACAC,EACAC,EAMJ,GAHAD,EAAIZ,EAAOM,CAAE,EAGRM,IAAM,EACV,MAAM,IAAI,UAAWR,EAAQ,+GAAgHQ,CAAE,CAAE,EAIlJ,GADAC,EAAIX,EAAgBK,EAAKK,EAAE,CAAE,EACxBC,IAAM,GACV,MAAM,IAAI,WAAYT,EAAQ,6GAA8GQ,EAAGL,CAAI,CAAE,EAGtJ,OAAAI,EAAOR,EAAOS,CAAE,EAChBD,EAAME,CAAE,EAAI,IAAId,EAAOS,EAAO,IAAK,EAG5BP,EAAOK,EAAGR,EAAiBa,CAAK,EAAGF,EAAQC,CAAS,CAC5D,CAKAb,EAAO,QAAUQ,IC7CjB,IAAIS,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "args2multislice", "Slice", "ndims", "slice", "normalizeIndex", "nulls", "format", "sliceDimensionFrom", "x", "dim", "start", "strict", "writable", "args", "N", "d", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ffc1f03..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,49 +0,0 @@ - -{{alias}}( x, dim, start, strict, writable ) - Returns a shifted view of an input ndarray along a specified dimension. - - Parameters - ---------- - x: ndarray - Input array. - - dim: integer - Index of dimension to slice. If less than zero, the index is resolved - relative to the last dimension, with the last dimension corresponding to - the value `-1`. - - start: integer - Starting index (inclusive). If less than zero, the corresponding element - along the specified dimension is resolved relative to the last element - along that dimension. For negative integers, the last element - corresponds to the value `-1`. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - writable: boolean - Boolean indicating whether a returned ndarray should be writable. This - parameter only applies to ndarray constructors which support read-only - instances. - - Returns - ------- - out: ndarray - Output array view. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > x.shape - [ 2, 2 ] - > var y = {{alias}}( x, 1, 1, false, false ) - - > 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 9dfeaf3..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,164 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sliceDimensionFrom = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = 0; - - sliceDimensionFrom( empty( 'float64', sh, order ), 1, s, false, false ); // $ExpectType float64ndarray - sliceDimensionFrom( empty( 'float32', sh, order ), 1, s, false, false ); // $ExpectType float32ndarray - sliceDimensionFrom( empty( 'complex128', sh, order ), 1, s, false, false ); // $ExpectType complex128ndarray - sliceDimensionFrom( empty( 'complex64', sh, order ), 1, s, false, false ); // $ExpectType complex64ndarray - sliceDimensionFrom( empty( 'int32', sh, order ), 1, s, false, false ); // $ExpectType int32ndarray - sliceDimensionFrom( empty( 'int16', sh, order ), 1, s, false, false ); // $ExpectType int16ndarray - sliceDimensionFrom( empty( 'int8', sh, order ), 1, s, false, false ); // $ExpectType int8ndarray - sliceDimensionFrom( empty( 'uint32', sh, order ), 1, s, false, false ); // $ExpectType uint32ndarray - sliceDimensionFrom( empty( 'uint16', sh, order ), 1, s, false, false ); // $ExpectType uint16ndarray - sliceDimensionFrom( empty( 'uint8', sh, order ), 1, s, false, false ); // $ExpectType uint8ndarray - sliceDimensionFrom( empty( 'uint8c', sh, order ), 1, s, false, false ); // $ExpectType uint8cndarray - - sliceDimensionFrom( empty( 'float64', sh, order ), 1, s, true, true ); // $ExpectType float64ndarray - sliceDimensionFrom( empty( 'float32', sh, order ), 1, s, true, true ); // $ExpectType float32ndarray - sliceDimensionFrom( empty( 'complex128', sh, order ), 1, s, true, true ); // $ExpectType complex128ndarray - sliceDimensionFrom( empty( 'complex64', sh, order ), 1, s, true, true ); // $ExpectType complex64ndarray - sliceDimensionFrom( empty( 'int32', sh, order ), 1, s, true, true ); // $ExpectType int32ndarray - sliceDimensionFrom( empty( 'int16', sh, order ), 1, s, true, true ); // $ExpectType int16ndarray - sliceDimensionFrom( empty( 'int8', sh, order ), 1, s, true, true ); // $ExpectType int8ndarray - sliceDimensionFrom( empty( 'uint32', sh, order ), 1, s, true, true ); // $ExpectType uint32ndarray - sliceDimensionFrom( empty( 'uint16', sh, order ), 1, s, true, true ); // $ExpectType uint16ndarray - sliceDimensionFrom( empty( 'uint8', sh, order ), 1, s, true, true ); // $ExpectType uint8ndarray - sliceDimensionFrom( empty( 'uint8c', sh, order ), 1, s, true, true ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const s = 0; - - sliceDimensionFrom( '10', 1, s, false, false ); // $ExpectError - sliceDimensionFrom( 10, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( false, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( true, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( null, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( [], 1, s, false, false ); // $ExpectError - sliceDimensionFrom( {}, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( ( x: number ): number => x, 1, s, false, false ); // $ExpectError - - sliceDimensionFrom( '10', 1, s, true, true ); // $ExpectError - sliceDimensionFrom( 10, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( false, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( true, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( null, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( [], 1, s, true, true ); // $ExpectError - sliceDimensionFrom( {}, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( ( x: number ): number => x, 1, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a number... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 1; - - sliceDimensionFrom( x, '5', s, false, false ); // $ExpectError - sliceDimensionFrom( x, false, s, false, false ); // $ExpectError - sliceDimensionFrom( x, true, s, false, false ); // $ExpectError - sliceDimensionFrom( x, null, s, false, false ); // $ExpectError - sliceDimensionFrom( x, undefined, s, false, false ); // $ExpectError - sliceDimensionFrom( x, [ '5' ], s, false, false ); // $ExpectError - sliceDimensionFrom( x, {}, s, false, false ); // $ExpectError - sliceDimensionFrom( x, ( x: number ): number => x, s, false, false ); // $ExpectError - - sliceDimensionFrom( x, '5', s, true, true ); // $ExpectError - sliceDimensionFrom( x, false, s, true, true ); // $ExpectError - sliceDimensionFrom( x, true, s, true, true ); // $ExpectError - sliceDimensionFrom( x, null, s, true, true ); // $ExpectError - sliceDimensionFrom( x, undefined, s, true, true ); // $ExpectError - sliceDimensionFrom( x, [ '5' ], s, true, true ); // $ExpectError - sliceDimensionFrom( x, {}, s, true, true ); // $ExpectError - sliceDimensionFrom( x, ( x: number ): number => x, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceDimensionFrom( x, 1, '5', false, false ); // $ExpectError - sliceDimensionFrom( x, 1, false, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, true, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, null, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, undefined, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, [ '5' ], false, false ); // $ExpectError - sliceDimensionFrom( x, 1, {}, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, ( x: number ): number => x, 1, false, false ); // $ExpectError - - sliceDimensionFrom( x, 1, '5', true, true ); // $ExpectError - sliceDimensionFrom( x, 1, false, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, true, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, null, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, undefined, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, [ '5' ], true, true ); // $ExpectError - sliceDimensionFrom( x, 1, {}, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, ( x: number ): number => x, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x, 1, s, '5', false ); // $ExpectError - sliceDimensionFrom( x, 1, s, 5, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, null, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, undefined, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, [ '5' ], false ); // $ExpectError - sliceDimensionFrom( x, 1, s, {}, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x, 1, s, false, '5' ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, 5 ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, null ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, undefined ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, [ '5' ] ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, {} ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x ); // $ExpectError - sliceDimensionFrom( x, 1 ); // $ExpectError - sliceDimensionFrom( x, 1, s ); // $ExpectError - sliceDimensionFrom( x, 1, s, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index b17162a..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 sliceDimensionFrom = 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 = sliceDimensionFrom( x, 1, 1, false, false ); -// 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 columns of each matrix: -var y2 = sliceDimensionFrom( x, 2, 1, false, false ); -// returns - -var a2 = ndarray2array( y2 ); -console.log( a2 ); -// => [ [ [ 1, 2 ], [ 4, 5 ], [ 7, 8 ] ], [ [ 10, 11 ], [ 13, 14 ], [ 16, 17 ] ], [ [ 19, 20 ], [ 22, 23 ], [ 25, 26 ] ] ] - -// Get the last two matrices: -var y3 = sliceDimensionFrom( x, 0, 1, false, false ); -// returns - -var a3 = ndarray2array( y3 ); -console.log( a3 ); -// => [ [ [ 9, 10, 11 ], [ 12, 13, 14 ], [ 15, 16, 17 ] ], [ [ 18, 19, 20 ], [ 21, 22, 23 ], [ 24, 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 22f5594..49b5959 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..06b4442 --- /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/slice-base-args2multislice@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-ctor@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndims@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-normalize-index@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-nulls@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function m(m,l,o,j,a){var p,h,v;if(0===(h=r(m)))throw new TypeError(d("1lDF7",h));if(-1===(v=i(l,h-1)))throw new RangeError(d("1lDF8",h,l));return(p=n(h))[v]=new e(o,null),t(m,s(p),j,a)}export{m as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..18102ad --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport Slice from '@stdlib/slice-ctor';\nimport ndims from '@stdlib/ndarray-base-ndims';\nimport slice from '@stdlib/ndarray-base-slice';\nimport normalizeIndex from '@stdlib/ndarray-base-normalize-index';\nimport nulls from '@stdlib/array-base-nulls';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns a shifted view of an input ndarray along a specified dimension.\n*\n* @param {ndarray} x - input array\n* @param {integer} dim - index of dimension to slice\n* @param {integer} start - starting index (inclusive)\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {TypeError} first argument must be an ndarray having one or more dimensions\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\n*\n* @example\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceDimensionFrom( x, 0, 1, false, false );\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 sliceDimensionFrom( x, dim, start, strict, writable ) {\n\tvar args;\n\tvar N;\n\tvar d;\n\n\t// Retrieve array meta data:\n\tN = ndims( x );\n\n\t// Check whether we were provided a zero-dimensional array...\n\tif ( N === 0 ) {\n\t\tthrow new TypeError( format( '1lDF7', N ) );\n\t}\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, N-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( '1lDF8', N, dim ) );\n\t}\n\t// Define a list of slice arguments:\n\targs = nulls( N );\n\targs[ d ] = new Slice( start, null );\n\n\t// Return a new array view:\n\treturn slice( x, args2multislice( args ), strict, writable );\n}\n\n\n// EXPORTS //\n\nexport default sliceDimensionFrom;\n"],"names":["sliceDimensionFrom","x","dim","start","strict","writable","args","N","d","ndims","TypeError","format","normalizeIndex","RangeError","nulls","Slice","slice","args2multislice"],"mappings":";;gpBAyEA,SAASA,EAAoBC,EAAGC,EAAKC,EAAOC,EAAQC,GACnD,IAAIC,EACAC,EACAC,EAMJ,GAAW,KAHXD,EAAIE,EAAOR,IAIV,MAAM,IAAIS,UAAWC,EAAQ,QAASJ,IAIvC,IAAY,KADZC,EAAII,EAAgBV,EAAKK,EAAE,IAE1B,MAAM,IAAIM,WAAYF,EAAQ,QAASJ,EAAGL,IAO3C,OAJAI,EAAOQ,EAAOP,IACRC,GAAM,IAAIO,EAAOZ,EAAO,MAGvBa,EAAOf,EAAGgB,EAAiBX,GAAQF,EAAQC,EACnD"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index b3f97b2..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 shifted view of an input ndarray along a specified dimension. -* -* @module @stdlib/ndarray-base-slice-dimension-from -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var sliceDimensionFrom = require( '@stdlib/ndarray-base-slice-dimension-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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // 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 50e4c67..0000000 --- a/lib/main.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var Slice = require( '@stdlib/slice-ctor' ); -var ndims = require( '@stdlib/ndarray-base-ndims' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' ); -var nulls = require( '@stdlib/array-base-nulls' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param {ndarray} x - input array -* @param {integer} dim - index of dimension to slice -* @param {integer} start - starting index (inclusive) -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @param {boolean} writable - boolean indicating whether a returned array should be writable -* @throws {TypeError} first argument must be an ndarray having one or more dimensions -* @throws {RangeError} dimension index exceeds the number of dimensions -* @throws {RangeError} slice 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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -function sliceDimensionFrom( x, dim, start, strict, writable ) { - var args; - var N; - var d; - - // Retrieve array meta data: - N = ndims( x ); - - // Check whether we were provided a zero-dimensional array... - if ( N === 0 ) { - throw new TypeError( format( '1lDF7', N ) ); - } - // Normalize the dimension index: - d = normalizeIndex( dim, N-1 ); - if ( d === -1 ) { - throw new RangeError( format( '1lDF8', N, dim ) ); - } - // Define a list of slice arguments: - args = nulls( N ); - args[ d ] = new Slice( start, null ); - - // Return a new array view: - return slice( x, args2multislice( args ), strict, writable ); -} - - -// EXPORTS // - -module.exports = sliceDimensionFrom; diff --git a/package.json b/package.json index c3c9e81..eb2ee55 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Return a shifted view of an input ndarray along a specific dimension.", "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,50 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-nulls": "github:stdlib-js/array-base-nulls#main", - "@stdlib/ndarray-base-ndims": "^0.2.2", - "@stdlib/ndarray-base-normalize-index": "^0.2.2", - "@stdlib/ndarray-base-slice": "^0.2.2", - "@stdlib/slice-base-args2multislice": "^0.2.2", - "@stdlib/slice-ctor": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/array-typed": "^0.3.0", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-base-empty": "^0.3.0", - "@stdlib/ndarray-base-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..8f38f04 --- /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 28703b5..0000000 --- a/test/test.js +++ /dev/null @@ -1,616 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 ndarray2array = require( '@stdlib/ndarray-to-array' ); -var baseCtor = require( '@stdlib/ndarray-base-ctor' ); -var ctor = require( '@stdlib/ndarray-ctor' ); -var sliceDimensionFrom = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sliceDimensionFrom, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a zero-dimensional array (strict=false)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error' ); - } - t.end(); - - function badValue( x ) { - return function badValue() { - sliceDimensionFrom( x, 0, 0, false, false ); - }; - } -}); - -tape( 'the function throws an error if provided a zero-dimensional array (strict=true)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error' ); - } - t.end(); - - function badValue( x ) { - return function badValue() { - sliceDimensionFrom( x, 0, 0, true, false ); - }; - } -}); - -tape( 'the function throws an error if the dimension index exceeds the number of dimensions (strict=false)', 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 ], 10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - t.throws( badValue( values[ i ], -10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - } - t.end(); - - function badValue( x, dim ) { - return function badValue() { - sliceDimensionFrom( x, dim, 0, false, false ); - }; - } -}); - -tape( 'the function throws an error if the dimension index exceeds the number of dimensions (strict=true)', 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 ], 10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - t.throws( badValue( values[ i ], -10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - } - t.end(); - - function badValue( x, dim ) { - return function badValue() { - sliceDimensionFrom( x, dim, 0, true, false ); - }; - } -}); - -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, - 20, - 20, - 20 - ]; - 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() { - sliceDimensionFrom( x, 0, s, true, false ); - }; - } -}); - -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, - 20, - 20, - 20, - 10 - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceDimensionFrom( values[ i ], 0, start[ i ], false, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), 0, 'returns expected value' ); - t.strictEqual( actual.dtype, values[ i ].dtype, 'returns expected value' ); - } - t.end(); -}); - -tape( 'in non-strict mode, the function returns an empty array when a starting index is the one more than the last index along a dimension', function test( t ) { - var actual; - var values; - var start; - var dim; - 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' } ) - ]; - - dim = [ - 0, - 1, - 0, - 1, - 4 - ]; - - start = [ - 1, - 1, - 1, - 1, - 1 - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceDimensionFrom( values[ i ], dim[ i ], start[ i ], false, false ); // eslint-disable-line max-len - 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 a shifted view of a provided input array (ndims=1)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 2, true, false ); - - 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 = sliceDimensionFrom( x, 0, -4, true, false ); - - 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)', 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 1, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 2, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, -2, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 1, 1, true, false ); - - 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 = sliceDimensionFrom( x, 1, -2, true, false ); - - 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' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=3)', 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 1, true, false ); - - 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 = sliceDimensionFrom( x, 1, 1, true, false ); - - 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 = sliceDimensionFrom( x, 2, 2, true, false ); - - 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 = sliceDimensionFrom( x, 2, -1, true, false ); - - 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' ); - t.end(); -}); - -tape( 'if a provided ndarray has a constructor supporting read-only instances, the function returns a read-only instance', function test( t ) { - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - x = new baseCtor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports returning writable views', function test( t ) { - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - x = new baseCtor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - t.end(); -}); From cba65d1640241cd27a14975d1d84a3910d8b6b2a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 20 Jan 2025 01:34:09 +0000 Subject: [PATCH 68/92] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 54bb1c2..50e4c67 100644 --- a/lib/main.js +++ b/lib/main.js @@ -26,7 +26,7 @@ var ndims = require( '@stdlib/ndarray-base-ndims' ); var slice = require( '@stdlib/ndarray-base-slice' ); var normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' ); var nulls = require( '@stdlib/array-base-nulls' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -81,12 +81,12 @@ function sliceDimensionFrom( x, dim, start, strict, writable ) { // Check whether we were provided a zero-dimensional array... if ( N === 0 ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.', N ) ); + throw new TypeError( format( '1lDF7', N ) ); } // Normalize the dimension index: d = normalizeIndex( dim, N-1 ); if ( d === -1 ) { - throw new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', N, dim ) ); + throw new RangeError( format( '1lDF8', N, dim ) ); } // Define a list of slice arguments: args = nulls( N ); diff --git a/package.json b/package.json index 2d85f05..c3c9e81 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/ndarray-base-slice": "^0.2.2", "@stdlib/slice-base-args2multislice": "^0.2.2", "@stdlib/slice-ctor": "^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 d687098f823dc24bd1ec6ea5509c2e93e69c0c74 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 20 Jan 2025 01:44:25 +0000 Subject: [PATCH 69/92] Remove files --- index.d.ts | 534 ------ index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5381 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 49b5959..0000000 --- a/index.d.ts +++ /dev/null @@ -1,534 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceDimensionFrom( x: float64ndarray, dim: number, start: number, strict: boolean, writable: boolean ): float64ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceDimensionFrom( x: float32ndarray, dim: number, start: number, strict: boolean, writable: boolean ): float32ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: int32ndarray, dim: number, start: number, strict: boolean, writable: boolean ): int32ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: int16ndarray, dim: number, start: number, strict: boolean, writable: boolean ): int16ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: int8ndarray, dim: number, start: number, strict: boolean, writable: boolean ): int8ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint32ndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint32ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint16ndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint16ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint8ndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint8ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint8cndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint8cndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceDimensionFrom( x: complex128ndarray, dim: number, start: number, strict: boolean, writable: boolean ): complex128ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceDimensionFrom( x: complex64ndarray, dim: number, start: number, strict: boolean, writable: boolean ): complex64ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: genericndarray, dim: number, start: number, strict: boolean, writable: boolean ): genericndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: typedndarray, dim: number, start: number, strict: boolean, writable: boolean ): typedndarray; - - -// EXPORTS // - -export = sliceDimensionFrom; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 06b4442..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/slice-base-args2multislice@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-ctor@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndims@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-normalize-index@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-nulls@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function m(m,l,o,j,a){var p,h,v;if(0===(h=r(m)))throw new TypeError(d("1lDF7",h));if(-1===(v=i(l,h-1)))throw new RangeError(d("1lDF8",h,l));return(p=n(h))[v]=new e(o,null),t(m,s(p),j,a)}export{m as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 18102ad..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport Slice from '@stdlib/slice-ctor';\nimport ndims from '@stdlib/ndarray-base-ndims';\nimport slice from '@stdlib/ndarray-base-slice';\nimport normalizeIndex from '@stdlib/ndarray-base-normalize-index';\nimport nulls from '@stdlib/array-base-nulls';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns a shifted view of an input ndarray along a specified dimension.\n*\n* @param {ndarray} x - input array\n* @param {integer} dim - index of dimension to slice\n* @param {integer} start - starting index (inclusive)\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {TypeError} first argument must be an ndarray having one or more dimensions\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\n*\n* @example\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceDimensionFrom( x, 0, 1, false, false );\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 sliceDimensionFrom( x, dim, start, strict, writable ) {\n\tvar args;\n\tvar N;\n\tvar d;\n\n\t// Retrieve array meta data:\n\tN = ndims( x );\n\n\t// Check whether we were provided a zero-dimensional array...\n\tif ( N === 0 ) {\n\t\tthrow new TypeError( format( '1lDF7', N ) );\n\t}\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, N-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( '1lDF8', N, dim ) );\n\t}\n\t// Define a list of slice arguments:\n\targs = nulls( N );\n\targs[ d ] = new Slice( start, null );\n\n\t// Return a new array view:\n\treturn slice( x, args2multislice( args ), strict, writable );\n}\n\n\n// EXPORTS //\n\nexport default sliceDimensionFrom;\n"],"names":["sliceDimensionFrom","x","dim","start","strict","writable","args","N","d","ndims","TypeError","format","normalizeIndex","RangeError","nulls","Slice","slice","args2multislice"],"mappings":";;gpBAyEA,SAASA,EAAoBC,EAAGC,EAAKC,EAAOC,EAAQC,GACnD,IAAIC,EACAC,EACAC,EAMJ,GAAW,KAHXD,EAAIE,EAAOR,IAIV,MAAM,IAAIS,UAAWC,EAAQ,QAASJ,IAIvC,IAAY,KADZC,EAAII,EAAgBV,EAAKK,EAAE,IAE1B,MAAM,IAAIM,WAAYF,EAAQ,QAASJ,EAAGL,IAO3C,OAJAI,EAAOQ,EAAOP,IACRC,GAAM,IAAIO,EAAOZ,EAAO,MAGvBa,EAAOf,EAAGgB,EAAiBX,GAAQF,EAAQC,EACnD"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 8f38f04..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From e4ca5c8332351f75cb4a8b2adff684d59b17df36 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 20 Jan 2025 01:44:42 +0000 Subject: [PATCH 70/92] Auto-generated commit --- .editorconfig | 180 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 150 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 45 +- SECURITY.md | 5 - benchmark/benchmark.js | 681 --- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 49 - docs/types/test.ts | 164 - 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 | 102 - package.json | 71 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 616 --- 44 files changed, 4868 insertions(+), 5380 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index dab5d2a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,180 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index e03ee5d..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-01-20T01:32:14.530Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 05d1840..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-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 ced95ae..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-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 60a2bb4..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: '38 14 * * 5' - - # 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 + + ```
@@ -202,7 +193,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]. diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 8a6b7a2..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,681 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 sliceDimensionFrom = require( './../lib' ); - - -// MAIN // - -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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2 ], { 'dtype': 'float64' } ), - empty( [ 2 ], { 'dtype': 'float32' } ), - empty( [ 2 ], { 'dtype': 'int32' } ), - empty( [ 2 ], { 'dtype': 'complex128' } ), - empty( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== '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 9543fcd..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-from" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-from -[production-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-slice-dimension-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 2ab577a..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import sliceDimensionFrom from '../docs/types/index'; -export = sliceDimensionFrom; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 2f5466d..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var v=function(i,r){return function(){return r||i((r={exports:{}}).exports,r),r.exports}};var o=v(function(p,u){"use strict";var l=require("@stdlib/slice-base-args2multislice"),c=require("@stdlib/slice-ctor"),q=require("@stdlib/ndarray-base-ndims"),f=require("@stdlib/ndarray-base-slice"),g=require("@stdlib/ndarray-base-normalize-index"),w=require("@stdlib/array-base-nulls"),s=require("@stdlib/string-format");function b(i,r,m,t,d){var n,e,a;if(e=q(i),e===0)throw new TypeError(s("invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.",e));if(a=g(r,e-1),a===-1)throw new RangeError(s("invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.",e,r));return n=w(e),n[a]=new c(m,null),f(i,l(n),t,d)}u.exports=b});var h=o();module.exports=h; -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 19dddde..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar args2multislice = require( '@stdlib/slice-base-args2multislice' );\nvar Slice = require( '@stdlib/slice-ctor' );\nvar ndims = require( '@stdlib/ndarray-base-ndims' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' );\nvar nulls = require( '@stdlib/array-base-nulls' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns a shifted view of an input ndarray along a specified dimension.\n*\n* @param {ndarray} x - input array\n* @param {integer} dim - index of dimension to slice\n* @param {integer} start - starting index (inclusive)\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {TypeError} first argument must be an ndarray having one or more dimensions\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceDimensionFrom( x, 0, 1, false, false );\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 sliceDimensionFrom( x, dim, start, strict, writable ) {\n\tvar args;\n\tvar N;\n\tvar d;\n\n\t// Retrieve array meta data:\n\tN = ndims( x );\n\n\t// Check whether we were provided a zero-dimensional array...\n\tif ( N === 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.', N ) );\n\t}\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, N-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', N, dim ) );\n\t}\n\t// Define a list of slice arguments:\n\targs = nulls( N );\n\targs[ d ] = new Slice( start, null );\n\n\t// Return a new array view:\n\treturn slice( x, args2multislice( args ), strict, writable );\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceDimensionFrom;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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 shifted view of an input ndarray along a specified dimension.\n*\n* @module @stdlib/ndarray-base-slice-dimension-from\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var sliceDimensionFrom = require( '@stdlib/ndarray-base-slice-dimension-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 = sliceDimensionFrom( x, 0, 1, false, false );\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,EAAkB,QAAS,oCAAqC,EAChEC,EAAQ,QAAS,oBAAqB,EACtCC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAiB,QAAS,sCAAuC,EACjEC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAS,QAAS,uBAAwB,EA6C9C,SAASC,EAAoBC,EAAGC,EAAKC,EAAOC,EAAQC,EAAW,CAC9D,IAAIC,EACAC,EACAC,EAMJ,GAHAD,EAAIZ,EAAOM,CAAE,EAGRM,IAAM,EACV,MAAM,IAAI,UAAWR,EAAQ,+GAAgHQ,CAAE,CAAE,EAIlJ,GADAC,EAAIX,EAAgBK,EAAKK,EAAE,CAAE,EACxBC,IAAM,GACV,MAAM,IAAI,WAAYT,EAAQ,6GAA8GQ,EAAGL,CAAI,CAAE,EAGtJ,OAAAI,EAAOR,EAAOS,CAAE,EAChBD,EAAME,CAAE,EAAI,IAAId,EAAOS,EAAO,IAAK,EAG5BP,EAAOK,EAAGR,EAAiBa,CAAK,EAAGF,EAAQC,CAAS,CAC5D,CAKAb,EAAO,QAAUQ,IC7CjB,IAAIS,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "args2multislice", "Slice", "ndims", "slice", "normalizeIndex", "nulls", "format", "sliceDimensionFrom", "x", "dim", "start", "strict", "writable", "args", "N", "d", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ffc1f03..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,49 +0,0 @@ - -{{alias}}( x, dim, start, strict, writable ) - Returns a shifted view of an input ndarray along a specified dimension. - - Parameters - ---------- - x: ndarray - Input array. - - dim: integer - Index of dimension to slice. If less than zero, the index is resolved - relative to the last dimension, with the last dimension corresponding to - the value `-1`. - - start: integer - Starting index (inclusive). If less than zero, the corresponding element - along the specified dimension is resolved relative to the last element - along that dimension. For negative integers, the last element - corresponds to the value `-1`. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - writable: boolean - Boolean indicating whether a returned ndarray should be writable. This - parameter only applies to ndarray constructors which support read-only - instances. - - Returns - ------- - out: ndarray - Output array view. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > x.shape - [ 2, 2 ] - > var y = {{alias}}( x, 1, 1, false, false ) - - > 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 9dfeaf3..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,164 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sliceDimensionFrom = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = 0; - - sliceDimensionFrom( empty( 'float64', sh, order ), 1, s, false, false ); // $ExpectType float64ndarray - sliceDimensionFrom( empty( 'float32', sh, order ), 1, s, false, false ); // $ExpectType float32ndarray - sliceDimensionFrom( empty( 'complex128', sh, order ), 1, s, false, false ); // $ExpectType complex128ndarray - sliceDimensionFrom( empty( 'complex64', sh, order ), 1, s, false, false ); // $ExpectType complex64ndarray - sliceDimensionFrom( empty( 'int32', sh, order ), 1, s, false, false ); // $ExpectType int32ndarray - sliceDimensionFrom( empty( 'int16', sh, order ), 1, s, false, false ); // $ExpectType int16ndarray - sliceDimensionFrom( empty( 'int8', sh, order ), 1, s, false, false ); // $ExpectType int8ndarray - sliceDimensionFrom( empty( 'uint32', sh, order ), 1, s, false, false ); // $ExpectType uint32ndarray - sliceDimensionFrom( empty( 'uint16', sh, order ), 1, s, false, false ); // $ExpectType uint16ndarray - sliceDimensionFrom( empty( 'uint8', sh, order ), 1, s, false, false ); // $ExpectType uint8ndarray - sliceDimensionFrom( empty( 'uint8c', sh, order ), 1, s, false, false ); // $ExpectType uint8cndarray - - sliceDimensionFrom( empty( 'float64', sh, order ), 1, s, true, true ); // $ExpectType float64ndarray - sliceDimensionFrom( empty( 'float32', sh, order ), 1, s, true, true ); // $ExpectType float32ndarray - sliceDimensionFrom( empty( 'complex128', sh, order ), 1, s, true, true ); // $ExpectType complex128ndarray - sliceDimensionFrom( empty( 'complex64', sh, order ), 1, s, true, true ); // $ExpectType complex64ndarray - sliceDimensionFrom( empty( 'int32', sh, order ), 1, s, true, true ); // $ExpectType int32ndarray - sliceDimensionFrom( empty( 'int16', sh, order ), 1, s, true, true ); // $ExpectType int16ndarray - sliceDimensionFrom( empty( 'int8', sh, order ), 1, s, true, true ); // $ExpectType int8ndarray - sliceDimensionFrom( empty( 'uint32', sh, order ), 1, s, true, true ); // $ExpectType uint32ndarray - sliceDimensionFrom( empty( 'uint16', sh, order ), 1, s, true, true ); // $ExpectType uint16ndarray - sliceDimensionFrom( empty( 'uint8', sh, order ), 1, s, true, true ); // $ExpectType uint8ndarray - sliceDimensionFrom( empty( 'uint8c', sh, order ), 1, s, true, true ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const s = 0; - - sliceDimensionFrom( '10', 1, s, false, false ); // $ExpectError - sliceDimensionFrom( 10, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( false, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( true, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( null, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( [], 1, s, false, false ); // $ExpectError - sliceDimensionFrom( {}, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( ( x: number ): number => x, 1, s, false, false ); // $ExpectError - - sliceDimensionFrom( '10', 1, s, true, true ); // $ExpectError - sliceDimensionFrom( 10, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( false, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( true, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( null, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( [], 1, s, true, true ); // $ExpectError - sliceDimensionFrom( {}, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( ( x: number ): number => x, 1, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a number... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 1; - - sliceDimensionFrom( x, '5', s, false, false ); // $ExpectError - sliceDimensionFrom( x, false, s, false, false ); // $ExpectError - sliceDimensionFrom( x, true, s, false, false ); // $ExpectError - sliceDimensionFrom( x, null, s, false, false ); // $ExpectError - sliceDimensionFrom( x, undefined, s, false, false ); // $ExpectError - sliceDimensionFrom( x, [ '5' ], s, false, false ); // $ExpectError - sliceDimensionFrom( x, {}, s, false, false ); // $ExpectError - sliceDimensionFrom( x, ( x: number ): number => x, s, false, false ); // $ExpectError - - sliceDimensionFrom( x, '5', s, true, true ); // $ExpectError - sliceDimensionFrom( x, false, s, true, true ); // $ExpectError - sliceDimensionFrom( x, true, s, true, true ); // $ExpectError - sliceDimensionFrom( x, null, s, true, true ); // $ExpectError - sliceDimensionFrom( x, undefined, s, true, true ); // $ExpectError - sliceDimensionFrom( x, [ '5' ], s, true, true ); // $ExpectError - sliceDimensionFrom( x, {}, s, true, true ); // $ExpectError - sliceDimensionFrom( x, ( x: number ): number => x, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceDimensionFrom( x, 1, '5', false, false ); // $ExpectError - sliceDimensionFrom( x, 1, false, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, true, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, null, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, undefined, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, [ '5' ], false, false ); // $ExpectError - sliceDimensionFrom( x, 1, {}, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, ( x: number ): number => x, 1, false, false ); // $ExpectError - - sliceDimensionFrom( x, 1, '5', true, true ); // $ExpectError - sliceDimensionFrom( x, 1, false, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, true, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, null, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, undefined, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, [ '5' ], true, true ); // $ExpectError - sliceDimensionFrom( x, 1, {}, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, ( x: number ): number => x, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x, 1, s, '5', false ); // $ExpectError - sliceDimensionFrom( x, 1, s, 5, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, null, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, undefined, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, [ '5' ], false ); // $ExpectError - sliceDimensionFrom( x, 1, s, {}, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x, 1, s, false, '5' ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, 5 ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, null ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, undefined ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, [ '5' ] ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, {} ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x ); // $ExpectError - sliceDimensionFrom( x, 1 ); // $ExpectError - sliceDimensionFrom( x, 1, s ); // $ExpectError - sliceDimensionFrom( x, 1, s, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index b17162a..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 sliceDimensionFrom = 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 = sliceDimensionFrom( x, 1, 1, false, false ); -// 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 columns of each matrix: -var y2 = sliceDimensionFrom( x, 2, 1, false, false ); -// returns - -var a2 = ndarray2array( y2 ); -console.log( a2 ); -// => [ [ [ 1, 2 ], [ 4, 5 ], [ 7, 8 ] ], [ [ 10, 11 ], [ 13, 14 ], [ 16, 17 ] ], [ [ 19, 20 ], [ 22, 23 ], [ 25, 26 ] ] ] - -// Get the last two matrices: -var y3 = sliceDimensionFrom( x, 0, 1, false, false ); -// returns - -var a3 = ndarray2array( y3 ); -console.log( a3 ); -// => [ [ [ 9, 10, 11 ], [ 12, 13, 14 ], [ 15, 16, 17 ] ], [ [ 18, 19, 20 ], [ 21, 22, 23 ], [ 24, 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 22f5594..49b5959 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..78600ee --- /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/slice-base-args2multislice@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-ctor@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndims@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-normalize-index@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-nulls@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function m(m,l,o,j,a){var p,h,v;if(0===(h=r(m)))throw new TypeError(d("1lDF7",h));if(-1===(v=i(l,h-1)))throw new RangeError(d("1lDF8",h,l));return(p=n(h))[v]=new e(o,null),t(m,s(p),j,a)}export{m as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..18102ad --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport Slice from '@stdlib/slice-ctor';\nimport ndims from '@stdlib/ndarray-base-ndims';\nimport slice from '@stdlib/ndarray-base-slice';\nimport normalizeIndex from '@stdlib/ndarray-base-normalize-index';\nimport nulls from '@stdlib/array-base-nulls';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns a shifted view of an input ndarray along a specified dimension.\n*\n* @param {ndarray} x - input array\n* @param {integer} dim - index of dimension to slice\n* @param {integer} start - starting index (inclusive)\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {TypeError} first argument must be an ndarray having one or more dimensions\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\n*\n* @example\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceDimensionFrom( x, 0, 1, false, false );\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 sliceDimensionFrom( x, dim, start, strict, writable ) {\n\tvar args;\n\tvar N;\n\tvar d;\n\n\t// Retrieve array meta data:\n\tN = ndims( x );\n\n\t// Check whether we were provided a zero-dimensional array...\n\tif ( N === 0 ) {\n\t\tthrow new TypeError( format( '1lDF7', N ) );\n\t}\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, N-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( '1lDF8', N, dim ) );\n\t}\n\t// Define a list of slice arguments:\n\targs = nulls( N );\n\targs[ d ] = new Slice( start, null );\n\n\t// Return a new array view:\n\treturn slice( x, args2multislice( args ), strict, writable );\n}\n\n\n// EXPORTS //\n\nexport default sliceDimensionFrom;\n"],"names":["sliceDimensionFrom","x","dim","start","strict","writable","args","N","d","ndims","TypeError","format","normalizeIndex","RangeError","nulls","Slice","slice","args2multislice"],"mappings":";;gpBAyEA,SAASA,EAAoBC,EAAGC,EAAKC,EAAOC,EAAQC,GACnD,IAAIC,EACAC,EACAC,EAMJ,GAAW,KAHXD,EAAIE,EAAOR,IAIV,MAAM,IAAIS,UAAWC,EAAQ,QAASJ,IAIvC,IAAY,KADZC,EAAII,EAAgBV,EAAKK,EAAE,IAE1B,MAAM,IAAIM,WAAYF,EAAQ,QAASJ,EAAGL,IAO3C,OAJAI,EAAOQ,EAAOP,IACRC,GAAM,IAAIO,EAAOZ,EAAO,MAGvBa,EAAOf,EAAGgB,EAAiBX,GAAQF,EAAQC,EACnD"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index b3f97b2..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 shifted view of an input ndarray along a specified dimension. -* -* @module @stdlib/ndarray-base-slice-dimension-from -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var sliceDimensionFrom = require( '@stdlib/ndarray-base-slice-dimension-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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // 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 50e4c67..0000000 --- a/lib/main.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var Slice = require( '@stdlib/slice-ctor' ); -var ndims = require( '@stdlib/ndarray-base-ndims' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' ); -var nulls = require( '@stdlib/array-base-nulls' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param {ndarray} x - input array -* @param {integer} dim - index of dimension to slice -* @param {integer} start - starting index (inclusive) -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @param {boolean} writable - boolean indicating whether a returned array should be writable -* @throws {TypeError} first argument must be an ndarray having one or more dimensions -* @throws {RangeError} dimension index exceeds the number of dimensions -* @throws {RangeError} slice 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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -function sliceDimensionFrom( x, dim, start, strict, writable ) { - var args; - var N; - var d; - - // Retrieve array meta data: - N = ndims( x ); - - // Check whether we were provided a zero-dimensional array... - if ( N === 0 ) { - throw new TypeError( format( '1lDF7', N ) ); - } - // Normalize the dimension index: - d = normalizeIndex( dim, N-1 ); - if ( d === -1 ) { - throw new RangeError( format( '1lDF8', N, dim ) ); - } - // Define a list of slice arguments: - args = nulls( N ); - args[ d ] = new Slice( start, null ); - - // Return a new array view: - return slice( x, args2multislice( args ), strict, writable ); -} - - -// EXPORTS // - -module.exports = sliceDimensionFrom; diff --git a/package.json b/package.json index c3c9e81..eb2ee55 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Return a shifted view of an input ndarray along a specific dimension.", "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,50 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-nulls": "github:stdlib-js/array-base-nulls#main", - "@stdlib/ndarray-base-ndims": "^0.2.2", - "@stdlib/ndarray-base-normalize-index": "^0.2.2", - "@stdlib/ndarray-base-slice": "^0.2.2", - "@stdlib/slice-base-args2multislice": "^0.2.2", - "@stdlib/slice-ctor": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/array-typed": "^0.3.0", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-base-empty": "^0.3.0", - "@stdlib/ndarray-base-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..8f38f04 --- /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 28703b5..0000000 --- a/test/test.js +++ /dev/null @@ -1,616 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 ndarray2array = require( '@stdlib/ndarray-to-array' ); -var baseCtor = require( '@stdlib/ndarray-base-ctor' ); -var ctor = require( '@stdlib/ndarray-ctor' ); -var sliceDimensionFrom = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sliceDimensionFrom, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a zero-dimensional array (strict=false)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error' ); - } - t.end(); - - function badValue( x ) { - return function badValue() { - sliceDimensionFrom( x, 0, 0, false, false ); - }; - } -}); - -tape( 'the function throws an error if provided a zero-dimensional array (strict=true)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error' ); - } - t.end(); - - function badValue( x ) { - return function badValue() { - sliceDimensionFrom( x, 0, 0, true, false ); - }; - } -}); - -tape( 'the function throws an error if the dimension index exceeds the number of dimensions (strict=false)', 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 ], 10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - t.throws( badValue( values[ i ], -10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - } - t.end(); - - function badValue( x, dim ) { - return function badValue() { - sliceDimensionFrom( x, dim, 0, false, false ); - }; - } -}); - -tape( 'the function throws an error if the dimension index exceeds the number of dimensions (strict=true)', 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 ], 10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - t.throws( badValue( values[ i ], -10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - } - t.end(); - - function badValue( x, dim ) { - return function badValue() { - sliceDimensionFrom( x, dim, 0, true, false ); - }; - } -}); - -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, - 20, - 20, - 20 - ]; - 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() { - sliceDimensionFrom( x, 0, s, true, false ); - }; - } -}); - -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, - 20, - 20, - 20, - 10 - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceDimensionFrom( values[ i ], 0, start[ i ], false, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), 0, 'returns expected value' ); - t.strictEqual( actual.dtype, values[ i ].dtype, 'returns expected value' ); - } - t.end(); -}); - -tape( 'in non-strict mode, the function returns an empty array when a starting index is the one more than the last index along a dimension', function test( t ) { - var actual; - var values; - var start; - var dim; - 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' } ) - ]; - - dim = [ - 0, - 1, - 0, - 1, - 4 - ]; - - start = [ - 1, - 1, - 1, - 1, - 1 - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceDimensionFrom( values[ i ], dim[ i ], start[ i ], false, false ); // eslint-disable-line max-len - 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 a shifted view of a provided input array (ndims=1)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 2, true, false ); - - 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 = sliceDimensionFrom( x, 0, -4, true, false ); - - 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)', 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 1, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 2, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, -2, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 1, 1, true, false ); - - 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 = sliceDimensionFrom( x, 1, -2, true, false ); - - 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' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=3)', 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 1, true, false ); - - 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 = sliceDimensionFrom( x, 1, 1, true, false ); - - 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 = sliceDimensionFrom( x, 2, 2, true, false ); - - 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 = sliceDimensionFrom( x, 2, -1, true, false ); - - 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' ); - t.end(); -}); - -tape( 'if a provided ndarray has a constructor supporting read-only instances, the function returns a read-only instance', function test( t ) { - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - x = new baseCtor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports returning writable views', function test( t ) { - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - x = new baseCtor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - t.end(); -}); From 293d734a8b79452f8f7b2478dd8a0f39d77bdb3c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 10 Mar 2025 00:53:49 +0000 Subject: [PATCH 71/92] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 54bb1c2..50e4c67 100644 --- a/lib/main.js +++ b/lib/main.js @@ -26,7 +26,7 @@ var ndims = require( '@stdlib/ndarray-base-ndims' ); var slice = require( '@stdlib/ndarray-base-slice' ); var normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' ); var nulls = require( '@stdlib/array-base-nulls' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -81,12 +81,12 @@ function sliceDimensionFrom( x, dim, start, strict, writable ) { // Check whether we were provided a zero-dimensional array... if ( N === 0 ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.', N ) ); + throw new TypeError( format( '1lDF7', N ) ); } // Normalize the dimension index: d = normalizeIndex( dim, N-1 ); if ( d === -1 ) { - throw new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', N, dim ) ); + throw new RangeError( format( '1lDF8', N, dim ) ); } // Define a list of slice arguments: args = nulls( N ); diff --git a/package.json b/package.json index 2d85f05..c3c9e81 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/ndarray-base-slice": "^0.2.2", "@stdlib/slice-base-args2multislice": "^0.2.2", "@stdlib/slice-ctor": "^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 3afb8831e2413decaac9853b5ef7513045ad4e32 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 10 Mar 2025 01:12:20 +0000 Subject: [PATCH 72/92] Remove files --- index.d.ts | 534 ------ index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5381 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 49b5959..0000000 --- a/index.d.ts +++ /dev/null @@ -1,534 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceDimensionFrom( x: float64ndarray, dim: number, start: number, strict: boolean, writable: boolean ): float64ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceDimensionFrom( x: float32ndarray, dim: number, start: number, strict: boolean, writable: boolean ): float32ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: int32ndarray, dim: number, start: number, strict: boolean, writable: boolean ): int32ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: int16ndarray, dim: number, start: number, strict: boolean, writable: boolean ): int16ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: int8ndarray, dim: number, start: number, strict: boolean, writable: boolean ): int8ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint32ndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint32ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint16ndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint16ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint8ndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint8ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint8cndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint8cndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceDimensionFrom( x: complex128ndarray, dim: number, start: number, strict: boolean, writable: boolean ): complex128ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceDimensionFrom( x: complex64ndarray, dim: number, start: number, strict: boolean, writable: boolean ): complex64ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: genericndarray, dim: number, start: number, strict: boolean, writable: boolean ): genericndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: typedndarray, dim: number, start: number, strict: boolean, writable: boolean ): typedndarray; - - -// EXPORTS // - -export = sliceDimensionFrom; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 78600ee..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/slice-base-args2multislice@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-ctor@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndims@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-normalize-index@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-nulls@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function m(m,l,o,j,a){var p,h,v;if(0===(h=r(m)))throw new TypeError(d("1lDF7",h));if(-1===(v=i(l,h-1)))throw new RangeError(d("1lDF8",h,l));return(p=n(h))[v]=new e(o,null),t(m,s(p),j,a)}export{m as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 18102ad..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport Slice from '@stdlib/slice-ctor';\nimport ndims from '@stdlib/ndarray-base-ndims';\nimport slice from '@stdlib/ndarray-base-slice';\nimport normalizeIndex from '@stdlib/ndarray-base-normalize-index';\nimport nulls from '@stdlib/array-base-nulls';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns a shifted view of an input ndarray along a specified dimension.\n*\n* @param {ndarray} x - input array\n* @param {integer} dim - index of dimension to slice\n* @param {integer} start - starting index (inclusive)\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {TypeError} first argument must be an ndarray having one or more dimensions\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\n*\n* @example\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceDimensionFrom( x, 0, 1, false, false );\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 sliceDimensionFrom( x, dim, start, strict, writable ) {\n\tvar args;\n\tvar N;\n\tvar d;\n\n\t// Retrieve array meta data:\n\tN = ndims( x );\n\n\t// Check whether we were provided a zero-dimensional array...\n\tif ( N === 0 ) {\n\t\tthrow new TypeError( format( '1lDF7', N ) );\n\t}\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, N-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( '1lDF8', N, dim ) );\n\t}\n\t// Define a list of slice arguments:\n\targs = nulls( N );\n\targs[ d ] = new Slice( start, null );\n\n\t// Return a new array view:\n\treturn slice( x, args2multislice( args ), strict, writable );\n}\n\n\n// EXPORTS //\n\nexport default sliceDimensionFrom;\n"],"names":["sliceDimensionFrom","x","dim","start","strict","writable","args","N","d","ndims","TypeError","format","normalizeIndex","RangeError","nulls","Slice","slice","args2multislice"],"mappings":";;gpBAyEA,SAASA,EAAoBC,EAAGC,EAAKC,EAAOC,EAAQC,GACnD,IAAIC,EACAC,EACAC,EAMJ,GAAW,KAHXD,EAAIE,EAAOR,IAIV,MAAM,IAAIS,UAAWC,EAAQ,QAASJ,IAIvC,IAAY,KADZC,EAAII,EAAgBV,EAAKK,EAAE,IAE1B,MAAM,IAAIM,WAAYF,EAAQ,QAASJ,EAAGL,IAO3C,OAJAI,EAAOQ,EAAOP,IACRC,GAAM,IAAIO,EAAOZ,EAAO,MAGvBa,EAAOf,EAAGgB,EAAiBX,GAAQF,EAAQC,EACnD"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 8f38f04..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From f079ed11df378ef6582e8fa3faa6bd125a1a0604 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 10 Mar 2025 01:12:58 +0000 Subject: [PATCH 73/92] 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 | 150 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 45 +- SECURITY.md | 5 - benchmark/benchmark.js | 681 --- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 49 - docs/types/test.ts | 164 - 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 | 102 - package.json | 71 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 616 --- 44 files changed, 4868 insertions(+), 5384 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index dab5d2a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,180 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index a3ce375..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-03-10T00:47:38.385Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index a53efc0..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-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 ced95ae..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-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 60a2bb4..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: '38 14 * * 5' - - # 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 + + ```
@@ -202,7 +193,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]. diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 8a6b7a2..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,681 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 sliceDimensionFrom = require( './../lib' ); - - -// MAIN // - -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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2 ], { 'dtype': 'float64' } ), - empty( [ 2 ], { 'dtype': 'float32' } ), - empty( [ 2 ], { 'dtype': 'int32' } ), - empty( [ 2 ], { 'dtype': 'complex128' } ), - empty( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== '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 9543fcd..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-from" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-from -[production-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-slice-dimension-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 2ab577a..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import sliceDimensionFrom from '../docs/types/index'; -export = sliceDimensionFrom; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 2f5466d..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var v=function(i,r){return function(){return r||i((r={exports:{}}).exports,r),r.exports}};var o=v(function(p,u){"use strict";var l=require("@stdlib/slice-base-args2multislice"),c=require("@stdlib/slice-ctor"),q=require("@stdlib/ndarray-base-ndims"),f=require("@stdlib/ndarray-base-slice"),g=require("@stdlib/ndarray-base-normalize-index"),w=require("@stdlib/array-base-nulls"),s=require("@stdlib/string-format");function b(i,r,m,t,d){var n,e,a;if(e=q(i),e===0)throw new TypeError(s("invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.",e));if(a=g(r,e-1),a===-1)throw new RangeError(s("invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.",e,r));return n=w(e),n[a]=new c(m,null),f(i,l(n),t,d)}u.exports=b});var h=o();module.exports=h; -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 19dddde..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar args2multislice = require( '@stdlib/slice-base-args2multislice' );\nvar Slice = require( '@stdlib/slice-ctor' );\nvar ndims = require( '@stdlib/ndarray-base-ndims' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' );\nvar nulls = require( '@stdlib/array-base-nulls' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns a shifted view of an input ndarray along a specified dimension.\n*\n* @param {ndarray} x - input array\n* @param {integer} dim - index of dimension to slice\n* @param {integer} start - starting index (inclusive)\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {TypeError} first argument must be an ndarray having one or more dimensions\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceDimensionFrom( x, 0, 1, false, false );\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 sliceDimensionFrom( x, dim, start, strict, writable ) {\n\tvar args;\n\tvar N;\n\tvar d;\n\n\t// Retrieve array meta data:\n\tN = ndims( x );\n\n\t// Check whether we were provided a zero-dimensional array...\n\tif ( N === 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.', N ) );\n\t}\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, N-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', N, dim ) );\n\t}\n\t// Define a list of slice arguments:\n\targs = nulls( N );\n\targs[ d ] = new Slice( start, null );\n\n\t// Return a new array view:\n\treturn slice( x, args2multislice( args ), strict, writable );\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceDimensionFrom;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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 shifted view of an input ndarray along a specified dimension.\n*\n* @module @stdlib/ndarray-base-slice-dimension-from\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var sliceDimensionFrom = require( '@stdlib/ndarray-base-slice-dimension-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 = sliceDimensionFrom( x, 0, 1, false, false );\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,EAAkB,QAAS,oCAAqC,EAChEC,EAAQ,QAAS,oBAAqB,EACtCC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAiB,QAAS,sCAAuC,EACjEC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAS,QAAS,uBAAwB,EA6C9C,SAASC,EAAoBC,EAAGC,EAAKC,EAAOC,EAAQC,EAAW,CAC9D,IAAIC,EACAC,EACAC,EAMJ,GAHAD,EAAIZ,EAAOM,CAAE,EAGRM,IAAM,EACV,MAAM,IAAI,UAAWR,EAAQ,+GAAgHQ,CAAE,CAAE,EAIlJ,GADAC,EAAIX,EAAgBK,EAAKK,EAAE,CAAE,EACxBC,IAAM,GACV,MAAM,IAAI,WAAYT,EAAQ,6GAA8GQ,EAAGL,CAAI,CAAE,EAGtJ,OAAAI,EAAOR,EAAOS,CAAE,EAChBD,EAAME,CAAE,EAAI,IAAId,EAAOS,EAAO,IAAK,EAG5BP,EAAOK,EAAGR,EAAiBa,CAAK,EAAGF,EAAQC,CAAS,CAC5D,CAKAb,EAAO,QAAUQ,IC7CjB,IAAIS,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "args2multislice", "Slice", "ndims", "slice", "normalizeIndex", "nulls", "format", "sliceDimensionFrom", "x", "dim", "start", "strict", "writable", "args", "N", "d", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ffc1f03..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,49 +0,0 @@ - -{{alias}}( x, dim, start, strict, writable ) - Returns a shifted view of an input ndarray along a specified dimension. - - Parameters - ---------- - x: ndarray - Input array. - - dim: integer - Index of dimension to slice. If less than zero, the index is resolved - relative to the last dimension, with the last dimension corresponding to - the value `-1`. - - start: integer - Starting index (inclusive). If less than zero, the corresponding element - along the specified dimension is resolved relative to the last element - along that dimension. For negative integers, the last element - corresponds to the value `-1`. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - writable: boolean - Boolean indicating whether a returned ndarray should be writable. This - parameter only applies to ndarray constructors which support read-only - instances. - - Returns - ------- - out: ndarray - Output array view. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > x.shape - [ 2, 2 ] - > var y = {{alias}}( x, 1, 1, false, false ) - - > 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 9dfeaf3..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,164 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sliceDimensionFrom = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = 0; - - sliceDimensionFrom( empty( 'float64', sh, order ), 1, s, false, false ); // $ExpectType float64ndarray - sliceDimensionFrom( empty( 'float32', sh, order ), 1, s, false, false ); // $ExpectType float32ndarray - sliceDimensionFrom( empty( 'complex128', sh, order ), 1, s, false, false ); // $ExpectType complex128ndarray - sliceDimensionFrom( empty( 'complex64', sh, order ), 1, s, false, false ); // $ExpectType complex64ndarray - sliceDimensionFrom( empty( 'int32', sh, order ), 1, s, false, false ); // $ExpectType int32ndarray - sliceDimensionFrom( empty( 'int16', sh, order ), 1, s, false, false ); // $ExpectType int16ndarray - sliceDimensionFrom( empty( 'int8', sh, order ), 1, s, false, false ); // $ExpectType int8ndarray - sliceDimensionFrom( empty( 'uint32', sh, order ), 1, s, false, false ); // $ExpectType uint32ndarray - sliceDimensionFrom( empty( 'uint16', sh, order ), 1, s, false, false ); // $ExpectType uint16ndarray - sliceDimensionFrom( empty( 'uint8', sh, order ), 1, s, false, false ); // $ExpectType uint8ndarray - sliceDimensionFrom( empty( 'uint8c', sh, order ), 1, s, false, false ); // $ExpectType uint8cndarray - - sliceDimensionFrom( empty( 'float64', sh, order ), 1, s, true, true ); // $ExpectType float64ndarray - sliceDimensionFrom( empty( 'float32', sh, order ), 1, s, true, true ); // $ExpectType float32ndarray - sliceDimensionFrom( empty( 'complex128', sh, order ), 1, s, true, true ); // $ExpectType complex128ndarray - sliceDimensionFrom( empty( 'complex64', sh, order ), 1, s, true, true ); // $ExpectType complex64ndarray - sliceDimensionFrom( empty( 'int32', sh, order ), 1, s, true, true ); // $ExpectType int32ndarray - sliceDimensionFrom( empty( 'int16', sh, order ), 1, s, true, true ); // $ExpectType int16ndarray - sliceDimensionFrom( empty( 'int8', sh, order ), 1, s, true, true ); // $ExpectType int8ndarray - sliceDimensionFrom( empty( 'uint32', sh, order ), 1, s, true, true ); // $ExpectType uint32ndarray - sliceDimensionFrom( empty( 'uint16', sh, order ), 1, s, true, true ); // $ExpectType uint16ndarray - sliceDimensionFrom( empty( 'uint8', sh, order ), 1, s, true, true ); // $ExpectType uint8ndarray - sliceDimensionFrom( empty( 'uint8c', sh, order ), 1, s, true, true ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const s = 0; - - sliceDimensionFrom( '10', 1, s, false, false ); // $ExpectError - sliceDimensionFrom( 10, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( false, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( true, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( null, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( [], 1, s, false, false ); // $ExpectError - sliceDimensionFrom( {}, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( ( x: number ): number => x, 1, s, false, false ); // $ExpectError - - sliceDimensionFrom( '10', 1, s, true, true ); // $ExpectError - sliceDimensionFrom( 10, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( false, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( true, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( null, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( [], 1, s, true, true ); // $ExpectError - sliceDimensionFrom( {}, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( ( x: number ): number => x, 1, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a number... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 1; - - sliceDimensionFrom( x, '5', s, false, false ); // $ExpectError - sliceDimensionFrom( x, false, s, false, false ); // $ExpectError - sliceDimensionFrom( x, true, s, false, false ); // $ExpectError - sliceDimensionFrom( x, null, s, false, false ); // $ExpectError - sliceDimensionFrom( x, undefined, s, false, false ); // $ExpectError - sliceDimensionFrom( x, [ '5' ], s, false, false ); // $ExpectError - sliceDimensionFrom( x, {}, s, false, false ); // $ExpectError - sliceDimensionFrom( x, ( x: number ): number => x, s, false, false ); // $ExpectError - - sliceDimensionFrom( x, '5', s, true, true ); // $ExpectError - sliceDimensionFrom( x, false, s, true, true ); // $ExpectError - sliceDimensionFrom( x, true, s, true, true ); // $ExpectError - sliceDimensionFrom( x, null, s, true, true ); // $ExpectError - sliceDimensionFrom( x, undefined, s, true, true ); // $ExpectError - sliceDimensionFrom( x, [ '5' ], s, true, true ); // $ExpectError - sliceDimensionFrom( x, {}, s, true, true ); // $ExpectError - sliceDimensionFrom( x, ( x: number ): number => x, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceDimensionFrom( x, 1, '5', false, false ); // $ExpectError - sliceDimensionFrom( x, 1, false, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, true, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, null, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, undefined, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, [ '5' ], false, false ); // $ExpectError - sliceDimensionFrom( x, 1, {}, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, ( x: number ): number => x, 1, false, false ); // $ExpectError - - sliceDimensionFrom( x, 1, '5', true, true ); // $ExpectError - sliceDimensionFrom( x, 1, false, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, true, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, null, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, undefined, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, [ '5' ], true, true ); // $ExpectError - sliceDimensionFrom( x, 1, {}, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, ( x: number ): number => x, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x, 1, s, '5', false ); // $ExpectError - sliceDimensionFrom( x, 1, s, 5, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, null, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, undefined, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, [ '5' ], false ); // $ExpectError - sliceDimensionFrom( x, 1, s, {}, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x, 1, s, false, '5' ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, 5 ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, null ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, undefined ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, [ '5' ] ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, {} ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x ); // $ExpectError - sliceDimensionFrom( x, 1 ); // $ExpectError - sliceDimensionFrom( x, 1, s ); // $ExpectError - sliceDimensionFrom( x, 1, s, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index b17162a..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 sliceDimensionFrom = 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 = sliceDimensionFrom( x, 1, 1, false, false ); -// 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 columns of each matrix: -var y2 = sliceDimensionFrom( x, 2, 1, false, false ); -// returns - -var a2 = ndarray2array( y2 ); -console.log( a2 ); -// => [ [ [ 1, 2 ], [ 4, 5 ], [ 7, 8 ] ], [ [ 10, 11 ], [ 13, 14 ], [ 16, 17 ] ], [ [ 19, 20 ], [ 22, 23 ], [ 25, 26 ] ] ] - -// Get the last two matrices: -var y3 = sliceDimensionFrom( x, 0, 1, false, false ); -// returns - -var a3 = ndarray2array( y3 ); -console.log( a3 ); -// => [ [ [ 9, 10, 11 ], [ 12, 13, 14 ], [ 15, 16, 17 ] ], [ [ 18, 19, 20 ], [ 21, 22, 23 ], [ 24, 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 22f5594..49b5959 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..78600ee --- /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/slice-base-args2multislice@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-ctor@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndims@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-normalize-index@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-nulls@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function m(m,l,o,j,a){var p,h,v;if(0===(h=r(m)))throw new TypeError(d("1lDF7",h));if(-1===(v=i(l,h-1)))throw new RangeError(d("1lDF8",h,l));return(p=n(h))[v]=new e(o,null),t(m,s(p),j,a)}export{m as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..18102ad --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport Slice from '@stdlib/slice-ctor';\nimport ndims from '@stdlib/ndarray-base-ndims';\nimport slice from '@stdlib/ndarray-base-slice';\nimport normalizeIndex from '@stdlib/ndarray-base-normalize-index';\nimport nulls from '@stdlib/array-base-nulls';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns a shifted view of an input ndarray along a specified dimension.\n*\n* @param {ndarray} x - input array\n* @param {integer} dim - index of dimension to slice\n* @param {integer} start - starting index (inclusive)\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {TypeError} first argument must be an ndarray having one or more dimensions\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\n*\n* @example\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceDimensionFrom( x, 0, 1, false, false );\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 sliceDimensionFrom( x, dim, start, strict, writable ) {\n\tvar args;\n\tvar N;\n\tvar d;\n\n\t// Retrieve array meta data:\n\tN = ndims( x );\n\n\t// Check whether we were provided a zero-dimensional array...\n\tif ( N === 0 ) {\n\t\tthrow new TypeError( format( '1lDF7', N ) );\n\t}\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, N-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( '1lDF8', N, dim ) );\n\t}\n\t// Define a list of slice arguments:\n\targs = nulls( N );\n\targs[ d ] = new Slice( start, null );\n\n\t// Return a new array view:\n\treturn slice( x, args2multislice( args ), strict, writable );\n}\n\n\n// EXPORTS //\n\nexport default sliceDimensionFrom;\n"],"names":["sliceDimensionFrom","x","dim","start","strict","writable","args","N","d","ndims","TypeError","format","normalizeIndex","RangeError","nulls","Slice","slice","args2multislice"],"mappings":";;gpBAyEA,SAASA,EAAoBC,EAAGC,EAAKC,EAAOC,EAAQC,GACnD,IAAIC,EACAC,EACAC,EAMJ,GAAW,KAHXD,EAAIE,EAAOR,IAIV,MAAM,IAAIS,UAAWC,EAAQ,QAASJ,IAIvC,IAAY,KADZC,EAAII,EAAgBV,EAAKK,EAAE,IAE1B,MAAM,IAAIM,WAAYF,EAAQ,QAASJ,EAAGL,IAO3C,OAJAI,EAAOQ,EAAOP,IACRC,GAAM,IAAIO,EAAOZ,EAAO,MAGvBa,EAAOf,EAAGgB,EAAiBX,GAAQF,EAAQC,EACnD"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index b3f97b2..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 shifted view of an input ndarray along a specified dimension. -* -* @module @stdlib/ndarray-base-slice-dimension-from -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var sliceDimensionFrom = require( '@stdlib/ndarray-base-slice-dimension-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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // 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 50e4c67..0000000 --- a/lib/main.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var Slice = require( '@stdlib/slice-ctor' ); -var ndims = require( '@stdlib/ndarray-base-ndims' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' ); -var nulls = require( '@stdlib/array-base-nulls' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param {ndarray} x - input array -* @param {integer} dim - index of dimension to slice -* @param {integer} start - starting index (inclusive) -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @param {boolean} writable - boolean indicating whether a returned array should be writable -* @throws {TypeError} first argument must be an ndarray having one or more dimensions -* @throws {RangeError} dimension index exceeds the number of dimensions -* @throws {RangeError} slice 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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -function sliceDimensionFrom( x, dim, start, strict, writable ) { - var args; - var N; - var d; - - // Retrieve array meta data: - N = ndims( x ); - - // Check whether we were provided a zero-dimensional array... - if ( N === 0 ) { - throw new TypeError( format( '1lDF7', N ) ); - } - // Normalize the dimension index: - d = normalizeIndex( dim, N-1 ); - if ( d === -1 ) { - throw new RangeError( format( '1lDF8', N, dim ) ); - } - // Define a list of slice arguments: - args = nulls( N ); - args[ d ] = new Slice( start, null ); - - // Return a new array view: - return slice( x, args2multislice( args ), strict, writable ); -} - - -// EXPORTS // - -module.exports = sliceDimensionFrom; diff --git a/package.json b/package.json index c3c9e81..eb2ee55 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Return a shifted view of an input ndarray along a specific dimension.", "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,50 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-nulls": "github:stdlib-js/array-base-nulls#main", - "@stdlib/ndarray-base-ndims": "^0.2.2", - "@stdlib/ndarray-base-normalize-index": "^0.2.2", - "@stdlib/ndarray-base-slice": "^0.2.2", - "@stdlib/slice-base-args2multislice": "^0.2.2", - "@stdlib/slice-ctor": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/array-typed": "^0.3.0", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-base-empty": "^0.3.0", - "@stdlib/ndarray-base-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..8f38f04 --- /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 28703b5..0000000 --- a/test/test.js +++ /dev/null @@ -1,616 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 ndarray2array = require( '@stdlib/ndarray-to-array' ); -var baseCtor = require( '@stdlib/ndarray-base-ctor' ); -var ctor = require( '@stdlib/ndarray-ctor' ); -var sliceDimensionFrom = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sliceDimensionFrom, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a zero-dimensional array (strict=false)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error' ); - } - t.end(); - - function badValue( x ) { - return function badValue() { - sliceDimensionFrom( x, 0, 0, false, false ); - }; - } -}); - -tape( 'the function throws an error if provided a zero-dimensional array (strict=true)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error' ); - } - t.end(); - - function badValue( x ) { - return function badValue() { - sliceDimensionFrom( x, 0, 0, true, false ); - }; - } -}); - -tape( 'the function throws an error if the dimension index exceeds the number of dimensions (strict=false)', 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 ], 10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - t.throws( badValue( values[ i ], -10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - } - t.end(); - - function badValue( x, dim ) { - return function badValue() { - sliceDimensionFrom( x, dim, 0, false, false ); - }; - } -}); - -tape( 'the function throws an error if the dimension index exceeds the number of dimensions (strict=true)', 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 ], 10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - t.throws( badValue( values[ i ], -10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - } - t.end(); - - function badValue( x, dim ) { - return function badValue() { - sliceDimensionFrom( x, dim, 0, true, false ); - }; - } -}); - -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, - 20, - 20, - 20 - ]; - 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() { - sliceDimensionFrom( x, 0, s, true, false ); - }; - } -}); - -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, - 20, - 20, - 20, - 10 - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceDimensionFrom( values[ i ], 0, start[ i ], false, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), 0, 'returns expected value' ); - t.strictEqual( actual.dtype, values[ i ].dtype, 'returns expected value' ); - } - t.end(); -}); - -tape( 'in non-strict mode, the function returns an empty array when a starting index is the one more than the last index along a dimension', function test( t ) { - var actual; - var values; - var start; - var dim; - 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' } ) - ]; - - dim = [ - 0, - 1, - 0, - 1, - 4 - ]; - - start = [ - 1, - 1, - 1, - 1, - 1 - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceDimensionFrom( values[ i ], dim[ i ], start[ i ], false, false ); // eslint-disable-line max-len - 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 a shifted view of a provided input array (ndims=1)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 2, true, false ); - - 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 = sliceDimensionFrom( x, 0, -4, true, false ); - - 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)', 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 1, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 2, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, -2, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 1, 1, true, false ); - - 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 = sliceDimensionFrom( x, 1, -2, true, false ); - - 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' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=3)', 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 1, true, false ); - - 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 = sliceDimensionFrom( x, 1, 1, true, false ); - - 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 = sliceDimensionFrom( x, 2, 2, true, false ); - - 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 = sliceDimensionFrom( x, 2, -1, true, false ); - - 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' ); - t.end(); -}); - -tape( 'if a provided ndarray has a constructor supporting read-only instances, the function returns a read-only instance', function test( t ) { - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - x = new baseCtor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports returning writable views', function test( t ) { - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - x = new baseCtor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - t.end(); -}); From c517ef9d2c70c564f2ba87c55f870e35ac32c15a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 3 Oct 2025 18:08:31 +0000 Subject: [PATCH 74/92] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 54bb1c2..50e4c67 100644 --- a/lib/main.js +++ b/lib/main.js @@ -26,7 +26,7 @@ var ndims = require( '@stdlib/ndarray-base-ndims' ); var slice = require( '@stdlib/ndarray-base-slice' ); var normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' ); var nulls = require( '@stdlib/array-base-nulls' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -81,12 +81,12 @@ function sliceDimensionFrom( x, dim, start, strict, writable ) { // Check whether we were provided a zero-dimensional array... if ( N === 0 ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.', N ) ); + throw new TypeError( format( '1lDF7', N ) ); } // Normalize the dimension index: d = normalizeIndex( dim, N-1 ); if ( d === -1 ) { - throw new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', N, dim ) ); + throw new RangeError( format( '1lDF8', N, dim ) ); } // Define a list of slice arguments: args = nulls( N ); diff --git a/package.json b/package.json index 2d85f05..c3c9e81 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/ndarray-base-slice": "^0.2.2", "@stdlib/slice-base-args2multislice": "^0.2.2", "@stdlib/slice-ctor": "^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 f2703926b20473394a9311aa1820537fd6ced2f0 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 3 Oct 2025 18:08:50 +0000 Subject: [PATCH 75/92] Remove files --- index.d.ts | 534 ------ index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5381 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 49b5959..0000000 --- a/index.d.ts +++ /dev/null @@ -1,534 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceDimensionFrom( x: float64ndarray, dim: number, start: number, strict: boolean, writable: boolean ): float64ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceDimensionFrom( x: float32ndarray, dim: number, start: number, strict: boolean, writable: boolean ): float32ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: int32ndarray, dim: number, start: number, strict: boolean, writable: boolean ): int32ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: int16ndarray, dim: number, start: number, strict: boolean, writable: boolean ): int16ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: int8ndarray, dim: number, start: number, strict: boolean, writable: boolean ): int8ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint32ndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint32ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint16ndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint16ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint8ndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint8ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint8cndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint8cndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceDimensionFrom( x: complex128ndarray, dim: number, start: number, strict: boolean, writable: boolean ): complex128ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceDimensionFrom( x: complex64ndarray, dim: number, start: number, strict: boolean, writable: boolean ): complex64ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: genericndarray, dim: number, start: number, strict: boolean, writable: boolean ): genericndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: typedndarray, dim: number, start: number, strict: boolean, writable: boolean ): typedndarray; - - -// EXPORTS // - -export = sliceDimensionFrom; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 78600ee..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/slice-base-args2multislice@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-ctor@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndims@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-normalize-index@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-nulls@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function m(m,l,o,j,a){var p,h,v;if(0===(h=r(m)))throw new TypeError(d("1lDF7",h));if(-1===(v=i(l,h-1)))throw new RangeError(d("1lDF8",h,l));return(p=n(h))[v]=new e(o,null),t(m,s(p),j,a)}export{m as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 18102ad..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport Slice from '@stdlib/slice-ctor';\nimport ndims from '@stdlib/ndarray-base-ndims';\nimport slice from '@stdlib/ndarray-base-slice';\nimport normalizeIndex from '@stdlib/ndarray-base-normalize-index';\nimport nulls from '@stdlib/array-base-nulls';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns a shifted view of an input ndarray along a specified dimension.\n*\n* @param {ndarray} x - input array\n* @param {integer} dim - index of dimension to slice\n* @param {integer} start - starting index (inclusive)\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {TypeError} first argument must be an ndarray having one or more dimensions\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\n*\n* @example\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceDimensionFrom( x, 0, 1, false, false );\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 sliceDimensionFrom( x, dim, start, strict, writable ) {\n\tvar args;\n\tvar N;\n\tvar d;\n\n\t// Retrieve array meta data:\n\tN = ndims( x );\n\n\t// Check whether we were provided a zero-dimensional array...\n\tif ( N === 0 ) {\n\t\tthrow new TypeError( format( '1lDF7', N ) );\n\t}\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, N-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( '1lDF8', N, dim ) );\n\t}\n\t// Define a list of slice arguments:\n\targs = nulls( N );\n\targs[ d ] = new Slice( start, null );\n\n\t// Return a new array view:\n\treturn slice( x, args2multislice( args ), strict, writable );\n}\n\n\n// EXPORTS //\n\nexport default sliceDimensionFrom;\n"],"names":["sliceDimensionFrom","x","dim","start","strict","writable","args","N","d","ndims","TypeError","format","normalizeIndex","RangeError","nulls","Slice","slice","args2multislice"],"mappings":";;gpBAyEA,SAASA,EAAoBC,EAAGC,EAAKC,EAAOC,EAAQC,GACnD,IAAIC,EACAC,EACAC,EAMJ,GAAW,KAHXD,EAAIE,EAAOR,IAIV,MAAM,IAAIS,UAAWC,EAAQ,QAASJ,IAIvC,IAAY,KADZC,EAAII,EAAgBV,EAAKK,EAAE,IAE1B,MAAM,IAAIM,WAAYF,EAAQ,QAASJ,EAAGL,IAO3C,OAJAI,EAAOQ,EAAOP,IACRC,GAAM,IAAIO,EAAOZ,EAAO,MAGvBa,EAAOf,EAAGgB,EAAiBX,GAAQF,EAAQC,EACnD"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 8f38f04..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 0317c4385d6df40e7182cfd21dd01be424f1d5a9 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 3 Oct 2025 18:09:55 +0000 Subject: [PATCH 76/92] Auto-generated commit --- .editorconfig | 180 - .eslintrc.js | 1 - .gitattributes | 66 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 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 | 199 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 164 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 45 +- SECURITY.md | 5 - benchmark/benchmark.js | 681 --- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 49 - docs/types/test.ts | 164 - 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 | 102 - package.json | 71 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 621 --- 43 files changed, 4868 insertions(+), 5407 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/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/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index a53efc0..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-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 ced95ae..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-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 60a2bb4..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: '38 14 * * 5' - - # 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 + + ```
@@ -202,7 +193,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]. diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 8a6b7a2..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,681 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 sliceDimensionFrom = require( './../lib' ); - - -// MAIN // - -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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2 ], { 'dtype': 'float64' } ), - empty( [ 2 ], { 'dtype': 'float32' } ), - empty( [ 2 ], { 'dtype': 'int32' } ), - empty( [ 2 ], { 'dtype': 'complex128' } ), - empty( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== '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 9543fcd..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-from" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-from -[production-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-slice-dimension-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 2ab577a..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import sliceDimensionFrom from '../docs/types/index'; -export = sliceDimensionFrom; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 2f5466d..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var v=function(i,r){return function(){return r||i((r={exports:{}}).exports,r),r.exports}};var o=v(function(p,u){"use strict";var l=require("@stdlib/slice-base-args2multislice"),c=require("@stdlib/slice-ctor"),q=require("@stdlib/ndarray-base-ndims"),f=require("@stdlib/ndarray-base-slice"),g=require("@stdlib/ndarray-base-normalize-index"),w=require("@stdlib/array-base-nulls"),s=require("@stdlib/string-format");function b(i,r,m,t,d){var n,e,a;if(e=q(i),e===0)throw new TypeError(s("invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.",e));if(a=g(r,e-1),a===-1)throw new RangeError(s("invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.",e,r));return n=w(e),n[a]=new c(m,null),f(i,l(n),t,d)}u.exports=b});var h=o();module.exports=h; -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 19dddde..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar args2multislice = require( '@stdlib/slice-base-args2multislice' );\nvar Slice = require( '@stdlib/slice-ctor' );\nvar ndims = require( '@stdlib/ndarray-base-ndims' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' );\nvar nulls = require( '@stdlib/array-base-nulls' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns a shifted view of an input ndarray along a specified dimension.\n*\n* @param {ndarray} x - input array\n* @param {integer} dim - index of dimension to slice\n* @param {integer} start - starting index (inclusive)\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {TypeError} first argument must be an ndarray having one or more dimensions\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceDimensionFrom( x, 0, 1, false, false );\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 sliceDimensionFrom( x, dim, start, strict, writable ) {\n\tvar args;\n\tvar N;\n\tvar d;\n\n\t// Retrieve array meta data:\n\tN = ndims( x );\n\n\t// Check whether we were provided a zero-dimensional array...\n\tif ( N === 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.', N ) );\n\t}\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, N-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', N, dim ) );\n\t}\n\t// Define a list of slice arguments:\n\targs = nulls( N );\n\targs[ d ] = new Slice( start, null );\n\n\t// Return a new array view:\n\treturn slice( x, args2multislice( args ), strict, writable );\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceDimensionFrom;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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 shifted view of an input ndarray along a specified dimension.\n*\n* @module @stdlib/ndarray-base-slice-dimension-from\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var sliceDimensionFrom = require( '@stdlib/ndarray-base-slice-dimension-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 = sliceDimensionFrom( x, 0, 1, false, false );\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,EAAkB,QAAS,oCAAqC,EAChEC,EAAQ,QAAS,oBAAqB,EACtCC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAiB,QAAS,sCAAuC,EACjEC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAS,QAAS,uBAAwB,EA6C9C,SAASC,EAAoBC,EAAGC,EAAKC,EAAOC,EAAQC,EAAW,CAC9D,IAAIC,EACAC,EACAC,EAMJ,GAHAD,EAAIZ,EAAOM,CAAE,EAGRM,IAAM,EACV,MAAM,IAAI,UAAWR,EAAQ,+GAAgHQ,CAAE,CAAE,EAIlJ,GADAC,EAAIX,EAAgBK,EAAKK,EAAE,CAAE,EACxBC,IAAM,GACV,MAAM,IAAI,WAAYT,EAAQ,6GAA8GQ,EAAGL,CAAI,CAAE,EAGtJ,OAAAI,EAAOR,EAAOS,CAAE,EAChBD,EAAME,CAAE,EAAI,IAAId,EAAOS,EAAO,IAAK,EAG5BP,EAAOK,EAAGR,EAAiBa,CAAK,EAAGF,EAAQC,CAAS,CAC5D,CAKAb,EAAO,QAAUQ,IC7CjB,IAAIS,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "args2multislice", "Slice", "ndims", "slice", "normalizeIndex", "nulls", "format", "sliceDimensionFrom", "x", "dim", "start", "strict", "writable", "args", "N", "d", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ffc1f03..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,49 +0,0 @@ - -{{alias}}( x, dim, start, strict, writable ) - Returns a shifted view of an input ndarray along a specified dimension. - - Parameters - ---------- - x: ndarray - Input array. - - dim: integer - Index of dimension to slice. If less than zero, the index is resolved - relative to the last dimension, with the last dimension corresponding to - the value `-1`. - - start: integer - Starting index (inclusive). If less than zero, the corresponding element - along the specified dimension is resolved relative to the last element - along that dimension. For negative integers, the last element - corresponds to the value `-1`. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - writable: boolean - Boolean indicating whether a returned ndarray should be writable. This - parameter only applies to ndarray constructors which support read-only - instances. - - Returns - ------- - out: ndarray - Output array view. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > x.shape - [ 2, 2 ] - > var y = {{alias}}( x, 1, 1, false, false ) - - > 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 9dfeaf3..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,164 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sliceDimensionFrom = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = 0; - - sliceDimensionFrom( empty( 'float64', sh, order ), 1, s, false, false ); // $ExpectType float64ndarray - sliceDimensionFrom( empty( 'float32', sh, order ), 1, s, false, false ); // $ExpectType float32ndarray - sliceDimensionFrom( empty( 'complex128', sh, order ), 1, s, false, false ); // $ExpectType complex128ndarray - sliceDimensionFrom( empty( 'complex64', sh, order ), 1, s, false, false ); // $ExpectType complex64ndarray - sliceDimensionFrom( empty( 'int32', sh, order ), 1, s, false, false ); // $ExpectType int32ndarray - sliceDimensionFrom( empty( 'int16', sh, order ), 1, s, false, false ); // $ExpectType int16ndarray - sliceDimensionFrom( empty( 'int8', sh, order ), 1, s, false, false ); // $ExpectType int8ndarray - sliceDimensionFrom( empty( 'uint32', sh, order ), 1, s, false, false ); // $ExpectType uint32ndarray - sliceDimensionFrom( empty( 'uint16', sh, order ), 1, s, false, false ); // $ExpectType uint16ndarray - sliceDimensionFrom( empty( 'uint8', sh, order ), 1, s, false, false ); // $ExpectType uint8ndarray - sliceDimensionFrom( empty( 'uint8c', sh, order ), 1, s, false, false ); // $ExpectType uint8cndarray - - sliceDimensionFrom( empty( 'float64', sh, order ), 1, s, true, true ); // $ExpectType float64ndarray - sliceDimensionFrom( empty( 'float32', sh, order ), 1, s, true, true ); // $ExpectType float32ndarray - sliceDimensionFrom( empty( 'complex128', sh, order ), 1, s, true, true ); // $ExpectType complex128ndarray - sliceDimensionFrom( empty( 'complex64', sh, order ), 1, s, true, true ); // $ExpectType complex64ndarray - sliceDimensionFrom( empty( 'int32', sh, order ), 1, s, true, true ); // $ExpectType int32ndarray - sliceDimensionFrom( empty( 'int16', sh, order ), 1, s, true, true ); // $ExpectType int16ndarray - sliceDimensionFrom( empty( 'int8', sh, order ), 1, s, true, true ); // $ExpectType int8ndarray - sliceDimensionFrom( empty( 'uint32', sh, order ), 1, s, true, true ); // $ExpectType uint32ndarray - sliceDimensionFrom( empty( 'uint16', sh, order ), 1, s, true, true ); // $ExpectType uint16ndarray - sliceDimensionFrom( empty( 'uint8', sh, order ), 1, s, true, true ); // $ExpectType uint8ndarray - sliceDimensionFrom( empty( 'uint8c', sh, order ), 1, s, true, true ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const s = 0; - - sliceDimensionFrom( '10', 1, s, false, false ); // $ExpectError - sliceDimensionFrom( 10, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( false, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( true, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( null, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( [], 1, s, false, false ); // $ExpectError - sliceDimensionFrom( {}, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( ( x: number ): number => x, 1, s, false, false ); // $ExpectError - - sliceDimensionFrom( '10', 1, s, true, true ); // $ExpectError - sliceDimensionFrom( 10, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( false, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( true, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( null, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( [], 1, s, true, true ); // $ExpectError - sliceDimensionFrom( {}, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( ( x: number ): number => x, 1, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a number... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 1; - - sliceDimensionFrom( x, '5', s, false, false ); // $ExpectError - sliceDimensionFrom( x, false, s, false, false ); // $ExpectError - sliceDimensionFrom( x, true, s, false, false ); // $ExpectError - sliceDimensionFrom( x, null, s, false, false ); // $ExpectError - sliceDimensionFrom( x, undefined, s, false, false ); // $ExpectError - sliceDimensionFrom( x, [ '5' ], s, false, false ); // $ExpectError - sliceDimensionFrom( x, {}, s, false, false ); // $ExpectError - sliceDimensionFrom( x, ( x: number ): number => x, s, false, false ); // $ExpectError - - sliceDimensionFrom( x, '5', s, true, true ); // $ExpectError - sliceDimensionFrom( x, false, s, true, true ); // $ExpectError - sliceDimensionFrom( x, true, s, true, true ); // $ExpectError - sliceDimensionFrom( x, null, s, true, true ); // $ExpectError - sliceDimensionFrom( x, undefined, s, true, true ); // $ExpectError - sliceDimensionFrom( x, [ '5' ], s, true, true ); // $ExpectError - sliceDimensionFrom( x, {}, s, true, true ); // $ExpectError - sliceDimensionFrom( x, ( x: number ): number => x, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceDimensionFrom( x, 1, '5', false, false ); // $ExpectError - sliceDimensionFrom( x, 1, false, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, true, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, null, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, undefined, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, [ '5' ], false, false ); // $ExpectError - sliceDimensionFrom( x, 1, {}, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, ( x: number ): number => x, 1, false, false ); // $ExpectError - - sliceDimensionFrom( x, 1, '5', true, true ); // $ExpectError - sliceDimensionFrom( x, 1, false, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, true, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, null, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, undefined, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, [ '5' ], true, true ); // $ExpectError - sliceDimensionFrom( x, 1, {}, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, ( x: number ): number => x, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x, 1, s, '5', false ); // $ExpectError - sliceDimensionFrom( x, 1, s, 5, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, null, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, undefined, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, [ '5' ], false ); // $ExpectError - sliceDimensionFrom( x, 1, s, {}, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x, 1, s, false, '5' ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, 5 ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, null ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, undefined ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, [ '5' ] ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, {} ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x ); // $ExpectError - sliceDimensionFrom( x, 1 ); // $ExpectError - sliceDimensionFrom( x, 1, s ); // $ExpectError - sliceDimensionFrom( x, 1, s, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index b17162a..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 sliceDimensionFrom = 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 = sliceDimensionFrom( x, 1, 1, false, false ); -// 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 columns of each matrix: -var y2 = sliceDimensionFrom( x, 2, 1, false, false ); -// returns - -var a2 = ndarray2array( y2 ); -console.log( a2 ); -// => [ [ [ 1, 2 ], [ 4, 5 ], [ 7, 8 ] ], [ [ 10, 11 ], [ 13, 14 ], [ 16, 17 ] ], [ [ 19, 20 ], [ 22, 23 ], [ 25, 26 ] ] ] - -// Get the last two matrices: -var y3 = sliceDimensionFrom( x, 0, 1, false, false ); -// returns - -var a3 = ndarray2array( y3 ); -console.log( a3 ); -// => [ [ [ 9, 10, 11 ], [ 12, 13, 14 ], [ 15, 16, 17 ] ], [ [ 18, 19, 20 ], [ 21, 22, 23 ], [ 24, 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 22f5594..49b5959 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..78600ee --- /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/slice-base-args2multislice@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-ctor@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndims@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-normalize-index@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-nulls@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function m(m,l,o,j,a){var p,h,v;if(0===(h=r(m)))throw new TypeError(d("1lDF7",h));if(-1===(v=i(l,h-1)))throw new RangeError(d("1lDF8",h,l));return(p=n(h))[v]=new e(o,null),t(m,s(p),j,a)}export{m as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..18102ad --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport Slice from '@stdlib/slice-ctor';\nimport ndims from '@stdlib/ndarray-base-ndims';\nimport slice from '@stdlib/ndarray-base-slice';\nimport normalizeIndex from '@stdlib/ndarray-base-normalize-index';\nimport nulls from '@stdlib/array-base-nulls';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns a shifted view of an input ndarray along a specified dimension.\n*\n* @param {ndarray} x - input array\n* @param {integer} dim - index of dimension to slice\n* @param {integer} start - starting index (inclusive)\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {TypeError} first argument must be an ndarray having one or more dimensions\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\n*\n* @example\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceDimensionFrom( x, 0, 1, false, false );\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 sliceDimensionFrom( x, dim, start, strict, writable ) {\n\tvar args;\n\tvar N;\n\tvar d;\n\n\t// Retrieve array meta data:\n\tN = ndims( x );\n\n\t// Check whether we were provided a zero-dimensional array...\n\tif ( N === 0 ) {\n\t\tthrow new TypeError( format( '1lDF7', N ) );\n\t}\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, N-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( '1lDF8', N, dim ) );\n\t}\n\t// Define a list of slice arguments:\n\targs = nulls( N );\n\targs[ d ] = new Slice( start, null );\n\n\t// Return a new array view:\n\treturn slice( x, args2multislice( args ), strict, writable );\n}\n\n\n// EXPORTS //\n\nexport default sliceDimensionFrom;\n"],"names":["sliceDimensionFrom","x","dim","start","strict","writable","args","N","d","ndims","TypeError","format","normalizeIndex","RangeError","nulls","Slice","slice","args2multislice"],"mappings":";;gpBAyEA,SAASA,EAAoBC,EAAGC,EAAKC,EAAOC,EAAQC,GACnD,IAAIC,EACAC,EACAC,EAMJ,GAAW,KAHXD,EAAIE,EAAOR,IAIV,MAAM,IAAIS,UAAWC,EAAQ,QAASJ,IAIvC,IAAY,KADZC,EAAII,EAAgBV,EAAKK,EAAE,IAE1B,MAAM,IAAIM,WAAYF,EAAQ,QAASJ,EAAGL,IAO3C,OAJAI,EAAOQ,EAAOP,IACRC,GAAM,IAAIO,EAAOZ,EAAO,MAGvBa,EAAOf,EAAGgB,EAAiBX,GAAQF,EAAQC,EACnD"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index b3f97b2..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 shifted view of an input ndarray along a specified dimension. -* -* @module @stdlib/ndarray-base-slice-dimension-from -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var sliceDimensionFrom = require( '@stdlib/ndarray-base-slice-dimension-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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // 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 50e4c67..0000000 --- a/lib/main.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var Slice = require( '@stdlib/slice-ctor' ); -var ndims = require( '@stdlib/ndarray-base-ndims' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' ); -var nulls = require( '@stdlib/array-base-nulls' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param {ndarray} x - input array -* @param {integer} dim - index of dimension to slice -* @param {integer} start - starting index (inclusive) -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @param {boolean} writable - boolean indicating whether a returned array should be writable -* @throws {TypeError} first argument must be an ndarray having one or more dimensions -* @throws {RangeError} dimension index exceeds the number of dimensions -* @throws {RangeError} slice 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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -function sliceDimensionFrom( x, dim, start, strict, writable ) { - var args; - var N; - var d; - - // Retrieve array meta data: - N = ndims( x ); - - // Check whether we were provided a zero-dimensional array... - if ( N === 0 ) { - throw new TypeError( format( '1lDF7', N ) ); - } - // Normalize the dimension index: - d = normalizeIndex( dim, N-1 ); - if ( d === -1 ) { - throw new RangeError( format( '1lDF8', N, dim ) ); - } - // Define a list of slice arguments: - args = nulls( N ); - args[ d ] = new Slice( start, null ); - - // Return a new array view: - return slice( x, args2multislice( args ), strict, writable ); -} - - -// EXPORTS // - -module.exports = sliceDimensionFrom; diff --git a/package.json b/package.json index c3c9e81..eb2ee55 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Return a shifted view of an input ndarray along a specific dimension.", "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,50 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-nulls": "github:stdlib-js/array-base-nulls#main", - "@stdlib/ndarray-base-ndims": "^0.2.2", - "@stdlib/ndarray-base-normalize-index": "^0.2.2", - "@stdlib/ndarray-base-slice": "^0.2.2", - "@stdlib/slice-base-args2multislice": "^0.2.2", - "@stdlib/slice-ctor": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/array-typed": "^0.3.0", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-base-empty": "^0.3.0", - "@stdlib/ndarray-base-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..8f38f04 --- /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 dd19802..0000000 --- a/test/test.js +++ /dev/null @@ -1,621 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 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 ndarray2array = require( '@stdlib/ndarray-to-array' ); -var baseCtor = require( '@stdlib/ndarray-base-ctor' ); -var ctor = require( '@stdlib/ndarray-ctor' ); -var sliceDimensionFrom = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sliceDimensionFrom, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a zero-dimensional array (strict=false)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error' ); - } - t.end(); - - function badValue( x ) { - return function badValue() { - sliceDimensionFrom( x, 0, 0, false, false ); - }; - } -}); - -tape( 'the function throws an error if provided a zero-dimensional array (strict=true)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error' ); - } - t.end(); - - function badValue( x ) { - return function badValue() { - sliceDimensionFrom( x, 0, 0, true, false ); - }; - } -}); - -tape( 'the function throws an error if the dimension index exceeds the number of dimensions (strict=false)', 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 ], 10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - t.throws( badValue( values[ i ], -10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - } - t.end(); - - function badValue( x, dim ) { - return function badValue() { - sliceDimensionFrom( x, dim, 0, false, false ); - }; - } -}); - -tape( 'the function throws an error if the dimension index exceeds the number of dimensions (strict=true)', 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 ], 10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - t.throws( badValue( values[ i ], -10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - } - t.end(); - - function badValue( x, dim ) { - return function badValue() { - sliceDimensionFrom( x, dim, 0, true, false ); - }; - } -}); - -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, - 20, - 20, - 20 - ]; - 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() { - sliceDimensionFrom( x, 0, s, true, false ); - }; - } -}); - -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; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - 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' } ) - ]; - - /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - start = [ - 10, - 20, - 20, - 20, - 10 - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceDimensionFrom( values[ i ], 0, start[ i ], false, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), 0, 'returns expected value' ); - t.strictEqual( actual.dtype, values[ i ].dtype, 'returns expected value' ); - } - t.end(); -}); - -tape( 'in non-strict mode, the function returns an empty array when a starting index is the one more than the last index along a dimension', function test( t ) { - var actual; - var values; - var start; - var dim; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - 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' } ) - ]; - - /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - dim = [ - 0, - 1, - 0, - 1, - 4 - ]; - - start = [ - 1, - 1, - 1, - 1, - 1 - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceDimensionFrom( values[ i ], dim[ i ], start[ i ], false, false ); // eslint-disable-line max-len - 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 a shifted view of a provided input array (ndims=1)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 2, true, false ); - - 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 = sliceDimensionFrom( x, 0, -4, true, false ); - - 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)', 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 1, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 2, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, -2, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 1, 1, true, false ); - - 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 = sliceDimensionFrom( x, 1, -2, true, false ); - - 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' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=3)', 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 1, true, false ); - - 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 = sliceDimensionFrom( x, 1, 1, true, false ); - - 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 = sliceDimensionFrom( x, 2, 2, true, false ); - - 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 = sliceDimensionFrom( x, 2, -1, true, false ); - - 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' ); - t.end(); -}); - -tape( 'if a provided ndarray has a constructor supporting read-only instances, the function returns a read-only instance', function test( t ) { - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - x = new baseCtor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports returning writable views', function test( t ) { - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - x = new baseCtor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - t.end(); -}); From a0ca94c487d6030c1ebf814146b03e0e01fc574c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 31 Jan 2026 06:54:12 +0000 Subject: [PATCH 77/92] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 54bb1c2..50e4c67 100644 --- a/lib/main.js +++ b/lib/main.js @@ -26,7 +26,7 @@ var ndims = require( '@stdlib/ndarray-base-ndims' ); var slice = require( '@stdlib/ndarray-base-slice' ); var normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' ); var nulls = require( '@stdlib/array-base-nulls' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -81,12 +81,12 @@ function sliceDimensionFrom( x, dim, start, strict, writable ) { // Check whether we were provided a zero-dimensional array... if ( N === 0 ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.', N ) ); + throw new TypeError( format( '1lDF7', N ) ); } // Normalize the dimension index: d = normalizeIndex( dim, N-1 ); if ( d === -1 ) { - throw new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', N, dim ) ); + throw new RangeError( format( '1lDF8', N, dim ) ); } // Define a list of slice arguments: args = nulls( N ); diff --git a/package.json b/package.json index 0602554..39e96b1 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/ndarray-base-slice": "^0.2.2", "@stdlib/slice-base-args2multislice": "^0.2.2", "@stdlib/slice-ctor": "^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 6d7f6e3a8c5a43e204060e2a6399dd58e6af2610 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 31 Jan 2026 07:56:04 +0000 Subject: [PATCH 78/92] Remove files --- index.d.ts | 534 ------ index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5381 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 49b5959..0000000 --- a/index.d.ts +++ /dev/null @@ -1,534 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceDimensionFrom( x: float64ndarray, dim: number, start: number, strict: boolean, writable: boolean ): float64ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceDimensionFrom( x: float32ndarray, dim: number, start: number, strict: boolean, writable: boolean ): float32ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: int32ndarray, dim: number, start: number, strict: boolean, writable: boolean ): int32ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: int16ndarray, dim: number, start: number, strict: boolean, writable: boolean ): int16ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: int8ndarray, dim: number, start: number, strict: boolean, writable: boolean ): int8ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint32ndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint32ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint16ndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint16ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint8ndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint8ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint8cndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint8cndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceDimensionFrom( x: complex128ndarray, dim: number, start: number, strict: boolean, writable: boolean ): complex128ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceDimensionFrom( x: complex64ndarray, dim: number, start: number, strict: boolean, writable: boolean ): complex64ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: genericndarray, dim: number, start: number, strict: boolean, writable: boolean ): genericndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: typedndarray, dim: number, start: number, strict: boolean, writable: boolean ): typedndarray; - - -// EXPORTS // - -export = sliceDimensionFrom; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 78600ee..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/slice-base-args2multislice@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-ctor@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndims@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-normalize-index@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-nulls@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function m(m,l,o,j,a){var p,h,v;if(0===(h=r(m)))throw new TypeError(d("1lDF7",h));if(-1===(v=i(l,h-1)))throw new RangeError(d("1lDF8",h,l));return(p=n(h))[v]=new e(o,null),t(m,s(p),j,a)}export{m as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 18102ad..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport Slice from '@stdlib/slice-ctor';\nimport ndims from '@stdlib/ndarray-base-ndims';\nimport slice from '@stdlib/ndarray-base-slice';\nimport normalizeIndex from '@stdlib/ndarray-base-normalize-index';\nimport nulls from '@stdlib/array-base-nulls';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns a shifted view of an input ndarray along a specified dimension.\n*\n* @param {ndarray} x - input array\n* @param {integer} dim - index of dimension to slice\n* @param {integer} start - starting index (inclusive)\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {TypeError} first argument must be an ndarray having one or more dimensions\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\n*\n* @example\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceDimensionFrom( x, 0, 1, false, false );\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 sliceDimensionFrom( x, dim, start, strict, writable ) {\n\tvar args;\n\tvar N;\n\tvar d;\n\n\t// Retrieve array meta data:\n\tN = ndims( x );\n\n\t// Check whether we were provided a zero-dimensional array...\n\tif ( N === 0 ) {\n\t\tthrow new TypeError( format( '1lDF7', N ) );\n\t}\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, N-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( '1lDF8', N, dim ) );\n\t}\n\t// Define a list of slice arguments:\n\targs = nulls( N );\n\targs[ d ] = new Slice( start, null );\n\n\t// Return a new array view:\n\treturn slice( x, args2multislice( args ), strict, writable );\n}\n\n\n// EXPORTS //\n\nexport default sliceDimensionFrom;\n"],"names":["sliceDimensionFrom","x","dim","start","strict","writable","args","N","d","ndims","TypeError","format","normalizeIndex","RangeError","nulls","Slice","slice","args2multislice"],"mappings":";;gpBAyEA,SAASA,EAAoBC,EAAGC,EAAKC,EAAOC,EAAQC,GACnD,IAAIC,EACAC,EACAC,EAMJ,GAAW,KAHXD,EAAIE,EAAOR,IAIV,MAAM,IAAIS,UAAWC,EAAQ,QAASJ,IAIvC,IAAY,KADZC,EAAII,EAAgBV,EAAKK,EAAE,IAE1B,MAAM,IAAIM,WAAYF,EAAQ,QAASJ,EAAGL,IAO3C,OAJAI,EAAOQ,EAAOP,IACRC,GAAM,IAAIO,EAAOZ,EAAO,MAGvBa,EAAOf,EAAGgB,EAAiBX,GAAQF,EAAQC,EACnD"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 8f38f04..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 389d0b3a4d63fd7dd098b49266a5f0e6f11e0e1b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 31 Jan 2026 07:56:24 +0000 Subject: [PATCH 79/92] Auto-generated commit --- .editorconfig | 180 - .eslintrc.js | 1 - .gitattributes | 66 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 821 --- .github/workflows/publish.yml | 261 - .github/workflows/test.yml | 108 - .github/workflows/test_bundles.yml | 213 - .github/workflows/test_coverage.yml | 142 - .github/workflows/test_install.yml | 94 - .github/workflows/test_published_package.yml | 115 - .gitignore | 199 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 164 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 45 +- SECURITY.md | 5 - benchmark/benchmark.js | 681 --- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 49 - docs/types/test.ts | 164 - 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 | 102 - package.json | 71 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 621 --- 43 files changed, 4868 insertions(+), 5507 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/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/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index a53efc0..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-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 ced95ae..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-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 60a2bb4..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: '38 14 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 83d50c4..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,821 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send notification to Zulip if job fails: - - name: 'Send notification to Zulip in case of failure' - # Pin action to full length commit SHA - uses: zulip/github-actions-zulip/send-message@e4c8f27c732ba9bd98ac6be0583096dea82feea5 # v1.0.2 - if: failure() - with: - api-key: ${{ secrets.ZULIP_API_KEY }} - email: 'github-actions-bot@stdlib.zulipchat.com' - organization-url: 'https://stdlib.zulipchat.com' - to: 'workflows-standalone' - type: 'stream' - topic: ${{ github.event.repository.name }} - content: | - :cross_mark: **${{ github.workflow }}** workflow failed - - **Repository:** [${{ github.repository }}](${{ github.server_url }}/${{ github.repository }}) - **Run:** [View workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -202,7 +193,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]. diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 8a6b7a2..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,681 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 sliceDimensionFrom = require( './../lib' ); - - -// MAIN // - -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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2 ], { 'dtype': 'float64' } ), - empty( [ 2 ], { 'dtype': 'float32' } ), - empty( [ 2 ], { 'dtype': 'int32' } ), - empty( [ 2 ], { 'dtype': 'complex128' } ), - empty( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== '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 9543fcd..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-from" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-from -[production-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-slice-dimension-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 2ab577a..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import sliceDimensionFrom from '../docs/types/index'; -export = sliceDimensionFrom; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 2f5466d..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var v=function(i,r){return function(){return r||i((r={exports:{}}).exports,r),r.exports}};var o=v(function(p,u){"use strict";var l=require("@stdlib/slice-base-args2multislice"),c=require("@stdlib/slice-ctor"),q=require("@stdlib/ndarray-base-ndims"),f=require("@stdlib/ndarray-base-slice"),g=require("@stdlib/ndarray-base-normalize-index"),w=require("@stdlib/array-base-nulls"),s=require("@stdlib/string-format");function b(i,r,m,t,d){var n,e,a;if(e=q(i),e===0)throw new TypeError(s("invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.",e));if(a=g(r,e-1),a===-1)throw new RangeError(s("invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.",e,r));return n=w(e),n[a]=new c(m,null),f(i,l(n),t,d)}u.exports=b});var h=o();module.exports=h; -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 19dddde..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar args2multislice = require( '@stdlib/slice-base-args2multislice' );\nvar Slice = require( '@stdlib/slice-ctor' );\nvar ndims = require( '@stdlib/ndarray-base-ndims' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' );\nvar nulls = require( '@stdlib/array-base-nulls' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns a shifted view of an input ndarray along a specified dimension.\n*\n* @param {ndarray} x - input array\n* @param {integer} dim - index of dimension to slice\n* @param {integer} start - starting index (inclusive)\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {TypeError} first argument must be an ndarray having one or more dimensions\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceDimensionFrom( x, 0, 1, false, false );\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 sliceDimensionFrom( x, dim, start, strict, writable ) {\n\tvar args;\n\tvar N;\n\tvar d;\n\n\t// Retrieve array meta data:\n\tN = ndims( x );\n\n\t// Check whether we were provided a zero-dimensional array...\n\tif ( N === 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.', N ) );\n\t}\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, N-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', N, dim ) );\n\t}\n\t// Define a list of slice arguments:\n\targs = nulls( N );\n\targs[ d ] = new Slice( start, null );\n\n\t// Return a new array view:\n\treturn slice( x, args2multislice( args ), strict, writable );\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceDimensionFrom;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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 shifted view of an input ndarray along a specified dimension.\n*\n* @module @stdlib/ndarray-base-slice-dimension-from\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var sliceDimensionFrom = require( '@stdlib/ndarray-base-slice-dimension-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 = sliceDimensionFrom( x, 0, 1, false, false );\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,EAAkB,QAAS,oCAAqC,EAChEC,EAAQ,QAAS,oBAAqB,EACtCC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAiB,QAAS,sCAAuC,EACjEC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAS,QAAS,uBAAwB,EA6C9C,SAASC,EAAoBC,EAAGC,EAAKC,EAAOC,EAAQC,EAAW,CAC9D,IAAIC,EACAC,EACAC,EAMJ,GAHAD,EAAIZ,EAAOM,CAAE,EAGRM,IAAM,EACV,MAAM,IAAI,UAAWR,EAAQ,+GAAgHQ,CAAE,CAAE,EAIlJ,GADAC,EAAIX,EAAgBK,EAAKK,EAAE,CAAE,EACxBC,IAAM,GACV,MAAM,IAAI,WAAYT,EAAQ,6GAA8GQ,EAAGL,CAAI,CAAE,EAGtJ,OAAAI,EAAOR,EAAOS,CAAE,EAChBD,EAAME,CAAE,EAAI,IAAId,EAAOS,EAAO,IAAK,EAG5BP,EAAOK,EAAGR,EAAiBa,CAAK,EAAGF,EAAQC,CAAS,CAC5D,CAKAb,EAAO,QAAUQ,IC7CjB,IAAIS,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "args2multislice", "Slice", "ndims", "slice", "normalizeIndex", "nulls", "format", "sliceDimensionFrom", "x", "dim", "start", "strict", "writable", "args", "N", "d", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ffc1f03..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,49 +0,0 @@ - -{{alias}}( x, dim, start, strict, writable ) - Returns a shifted view of an input ndarray along a specified dimension. - - Parameters - ---------- - x: ndarray - Input array. - - dim: integer - Index of dimension to slice. If less than zero, the index is resolved - relative to the last dimension, with the last dimension corresponding to - the value `-1`. - - start: integer - Starting index (inclusive). If less than zero, the corresponding element - along the specified dimension is resolved relative to the last element - along that dimension. For negative integers, the last element - corresponds to the value `-1`. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - writable: boolean - Boolean indicating whether a returned ndarray should be writable. This - parameter only applies to ndarray constructors which support read-only - instances. - - Returns - ------- - out: ndarray - Output array view. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > x.shape - [ 2, 2 ] - > var y = {{alias}}( x, 1, 1, false, false ) - - > 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 9dfeaf3..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,164 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sliceDimensionFrom = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = 0; - - sliceDimensionFrom( empty( 'float64', sh, order ), 1, s, false, false ); // $ExpectType float64ndarray - sliceDimensionFrom( empty( 'float32', sh, order ), 1, s, false, false ); // $ExpectType float32ndarray - sliceDimensionFrom( empty( 'complex128', sh, order ), 1, s, false, false ); // $ExpectType complex128ndarray - sliceDimensionFrom( empty( 'complex64', sh, order ), 1, s, false, false ); // $ExpectType complex64ndarray - sliceDimensionFrom( empty( 'int32', sh, order ), 1, s, false, false ); // $ExpectType int32ndarray - sliceDimensionFrom( empty( 'int16', sh, order ), 1, s, false, false ); // $ExpectType int16ndarray - sliceDimensionFrom( empty( 'int8', sh, order ), 1, s, false, false ); // $ExpectType int8ndarray - sliceDimensionFrom( empty( 'uint32', sh, order ), 1, s, false, false ); // $ExpectType uint32ndarray - sliceDimensionFrom( empty( 'uint16', sh, order ), 1, s, false, false ); // $ExpectType uint16ndarray - sliceDimensionFrom( empty( 'uint8', sh, order ), 1, s, false, false ); // $ExpectType uint8ndarray - sliceDimensionFrom( empty( 'uint8c', sh, order ), 1, s, false, false ); // $ExpectType uint8cndarray - - sliceDimensionFrom( empty( 'float64', sh, order ), 1, s, true, true ); // $ExpectType float64ndarray - sliceDimensionFrom( empty( 'float32', sh, order ), 1, s, true, true ); // $ExpectType float32ndarray - sliceDimensionFrom( empty( 'complex128', sh, order ), 1, s, true, true ); // $ExpectType complex128ndarray - sliceDimensionFrom( empty( 'complex64', sh, order ), 1, s, true, true ); // $ExpectType complex64ndarray - sliceDimensionFrom( empty( 'int32', sh, order ), 1, s, true, true ); // $ExpectType int32ndarray - sliceDimensionFrom( empty( 'int16', sh, order ), 1, s, true, true ); // $ExpectType int16ndarray - sliceDimensionFrom( empty( 'int8', sh, order ), 1, s, true, true ); // $ExpectType int8ndarray - sliceDimensionFrom( empty( 'uint32', sh, order ), 1, s, true, true ); // $ExpectType uint32ndarray - sliceDimensionFrom( empty( 'uint16', sh, order ), 1, s, true, true ); // $ExpectType uint16ndarray - sliceDimensionFrom( empty( 'uint8', sh, order ), 1, s, true, true ); // $ExpectType uint8ndarray - sliceDimensionFrom( empty( 'uint8c', sh, order ), 1, s, true, true ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const s = 0; - - sliceDimensionFrom( '10', 1, s, false, false ); // $ExpectError - sliceDimensionFrom( 10, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( false, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( true, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( null, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( [], 1, s, false, false ); // $ExpectError - sliceDimensionFrom( {}, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( ( x: number ): number => x, 1, s, false, false ); // $ExpectError - - sliceDimensionFrom( '10', 1, s, true, true ); // $ExpectError - sliceDimensionFrom( 10, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( false, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( true, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( null, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( [], 1, s, true, true ); // $ExpectError - sliceDimensionFrom( {}, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( ( x: number ): number => x, 1, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a number... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 1; - - sliceDimensionFrom( x, '5', s, false, false ); // $ExpectError - sliceDimensionFrom( x, false, s, false, false ); // $ExpectError - sliceDimensionFrom( x, true, s, false, false ); // $ExpectError - sliceDimensionFrom( x, null, s, false, false ); // $ExpectError - sliceDimensionFrom( x, undefined, s, false, false ); // $ExpectError - sliceDimensionFrom( x, [ '5' ], s, false, false ); // $ExpectError - sliceDimensionFrom( x, {}, s, false, false ); // $ExpectError - sliceDimensionFrom( x, ( x: number ): number => x, s, false, false ); // $ExpectError - - sliceDimensionFrom( x, '5', s, true, true ); // $ExpectError - sliceDimensionFrom( x, false, s, true, true ); // $ExpectError - sliceDimensionFrom( x, true, s, true, true ); // $ExpectError - sliceDimensionFrom( x, null, s, true, true ); // $ExpectError - sliceDimensionFrom( x, undefined, s, true, true ); // $ExpectError - sliceDimensionFrom( x, [ '5' ], s, true, true ); // $ExpectError - sliceDimensionFrom( x, {}, s, true, true ); // $ExpectError - sliceDimensionFrom( x, ( x: number ): number => x, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceDimensionFrom( x, 1, '5', false, false ); // $ExpectError - sliceDimensionFrom( x, 1, false, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, true, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, null, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, undefined, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, [ '5' ], false, false ); // $ExpectError - sliceDimensionFrom( x, 1, {}, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, ( x: number ): number => x, 1, false, false ); // $ExpectError - - sliceDimensionFrom( x, 1, '5', true, true ); // $ExpectError - sliceDimensionFrom( x, 1, false, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, true, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, null, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, undefined, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, [ '5' ], true, true ); // $ExpectError - sliceDimensionFrom( x, 1, {}, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, ( x: number ): number => x, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x, 1, s, '5', false ); // $ExpectError - sliceDimensionFrom( x, 1, s, 5, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, null, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, undefined, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, [ '5' ], false ); // $ExpectError - sliceDimensionFrom( x, 1, s, {}, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x, 1, s, false, '5' ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, 5 ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, null ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, undefined ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, [ '5' ] ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, {} ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x ); // $ExpectError - sliceDimensionFrom( x, 1 ); // $ExpectError - sliceDimensionFrom( x, 1, s ); // $ExpectError - sliceDimensionFrom( x, 1, s, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index b17162a..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 sliceDimensionFrom = 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 = sliceDimensionFrom( x, 1, 1, false, false ); -// 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 columns of each matrix: -var y2 = sliceDimensionFrom( x, 2, 1, false, false ); -// returns - -var a2 = ndarray2array( y2 ); -console.log( a2 ); -// => [ [ [ 1, 2 ], [ 4, 5 ], [ 7, 8 ] ], [ [ 10, 11 ], [ 13, 14 ], [ 16, 17 ] ], [ [ 19, 20 ], [ 22, 23 ], [ 25, 26 ] ] ] - -// Get the last two matrices: -var y3 = sliceDimensionFrom( x, 0, 1, false, false ); -// returns - -var a3 = ndarray2array( y3 ); -console.log( a3 ); -// => [ [ [ 9, 10, 11 ], [ 12, 13, 14 ], [ 15, 16, 17 ] ], [ [ 18, 19, 20 ], [ 21, 22, 23 ], [ 24, 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 22f5594..49b5959 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..b371b47 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-ctor@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndims@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-normalize-index@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-nulls@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function m(m,l,o,j,a){var p,h,v;if(0===(h=r(m)))throw new TypeError(d("1lDF7",h));if(-1===(v=i(l,h-1)))throw new RangeError(d("1lDF8",h,l));return(p=n(h))[v]=new e(o,null),t(m,s(p),j,a)}export{m as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..425f555 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport Slice from '@stdlib/slice-ctor';\nimport ndims from '@stdlib/ndarray-base-ndims';\nimport slice from '@stdlib/ndarray-base-slice';\nimport normalizeIndex from '@stdlib/ndarray-base-normalize-index';\nimport nulls from '@stdlib/array-base-nulls';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns a shifted view of an input ndarray along a specified dimension.\n*\n* @param {ndarray} x - input array\n* @param {integer} dim - index of dimension to slice\n* @param {integer} start - starting index (inclusive)\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {TypeError} first argument must be an ndarray having one or more dimensions\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\n*\n* @example\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceDimensionFrom( x, 0, 1, false, false );\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 sliceDimensionFrom( x, dim, start, strict, writable ) {\n\tvar args;\n\tvar N;\n\tvar d;\n\n\t// Retrieve array meta data:\n\tN = ndims( x );\n\n\t// Check whether we were provided a zero-dimensional array...\n\tif ( N === 0 ) {\n\t\tthrow new TypeError( format( '1lDF7', N ) );\n\t}\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, N-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( '1lDF8', N, dim ) );\n\t}\n\t// Define a list of slice arguments:\n\targs = nulls( N );\n\targs[ d ] = new Slice( start, null );\n\n\t// Return a new array view:\n\treturn slice( x, args2multislice( args ), strict, writable );\n}\n\n\n// EXPORTS //\n\nexport default sliceDimensionFrom;\n"],"names":["sliceDimensionFrom","x","dim","start","strict","writable","args","N","d","ndims","TypeError","format","normalizeIndex","RangeError","nulls","Slice","slice","args2multislice"],"mappings":";;upBAyEA,SAASA,EAAoBC,EAAGC,EAAKC,EAAOC,EAAQC,GACnD,IAAIC,EACAC,EACAC,EAMJ,GAAW,KAHXD,EAAIE,EAAOR,IAIV,MAAM,IAAIS,UAAWC,EAAQ,QAASJ,IAIvC,IAAY,KADZC,EAAII,EAAgBV,EAAKK,EAAE,IAE1B,MAAM,IAAIM,WAAYF,EAAQ,QAASJ,EAAGL,IAO3C,OAJAI,EAAOQ,EAAOP,IACRC,GAAM,IAAIO,EAAOZ,EAAO,MAGvBa,EAAOf,EAAGgB,EAAiBX,GAAQF,EAAQC,EACnD"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index b3f97b2..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 shifted view of an input ndarray along a specified dimension. -* -* @module @stdlib/ndarray-base-slice-dimension-from -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var sliceDimensionFrom = require( '@stdlib/ndarray-base-slice-dimension-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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // 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 50e4c67..0000000 --- a/lib/main.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var Slice = require( '@stdlib/slice-ctor' ); -var ndims = require( '@stdlib/ndarray-base-ndims' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' ); -var nulls = require( '@stdlib/array-base-nulls' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param {ndarray} x - input array -* @param {integer} dim - index of dimension to slice -* @param {integer} start - starting index (inclusive) -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @param {boolean} writable - boolean indicating whether a returned array should be writable -* @throws {TypeError} first argument must be an ndarray having one or more dimensions -* @throws {RangeError} dimension index exceeds the number of dimensions -* @throws {RangeError} slice 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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -function sliceDimensionFrom( x, dim, start, strict, writable ) { - var args; - var N; - var d; - - // Retrieve array meta data: - N = ndims( x ); - - // Check whether we were provided a zero-dimensional array... - if ( N === 0 ) { - throw new TypeError( format( '1lDF7', N ) ); - } - // Normalize the dimension index: - d = normalizeIndex( dim, N-1 ); - if ( d === -1 ) { - throw new RangeError( format( '1lDF8', N, dim ) ); - } - // Define a list of slice arguments: - args = nulls( N ); - args[ d ] = new Slice( start, null ); - - // Return a new array view: - return slice( x, args2multislice( args ), strict, writable ); -} - - -// EXPORTS // - -module.exports = sliceDimensionFrom; diff --git a/package.json b/package.json index 39e96b1..707794f 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.3", "description": "Return a shifted view of an input ndarray along a specific dimension.", "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,50 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-nulls": "^0.1.0", - "@stdlib/ndarray-base-ndims": "^0.2.2", - "@stdlib/ndarray-base-normalize-index": "^0.2.2", - "@stdlib/ndarray-base-slice": "^0.2.2", - "@stdlib/slice-base-args2multislice": "^0.2.2", - "@stdlib/slice-ctor": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/array-typed": "^0.3.1", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-base-empty": "^0.3.0", - "@stdlib/ndarray-base-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..7fa0764 --- /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 dd19802..0000000 --- a/test/test.js +++ /dev/null @@ -1,621 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 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 ndarray2array = require( '@stdlib/ndarray-to-array' ); -var baseCtor = require( '@stdlib/ndarray-base-ctor' ); -var ctor = require( '@stdlib/ndarray-ctor' ); -var sliceDimensionFrom = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sliceDimensionFrom, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a zero-dimensional array (strict=false)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error' ); - } - t.end(); - - function badValue( x ) { - return function badValue() { - sliceDimensionFrom( x, 0, 0, false, false ); - }; - } -}); - -tape( 'the function throws an error if provided a zero-dimensional array (strict=true)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error' ); - } - t.end(); - - function badValue( x ) { - return function badValue() { - sliceDimensionFrom( x, 0, 0, true, false ); - }; - } -}); - -tape( 'the function throws an error if the dimension index exceeds the number of dimensions (strict=false)', 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 ], 10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - t.throws( badValue( values[ i ], -10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - } - t.end(); - - function badValue( x, dim ) { - return function badValue() { - sliceDimensionFrom( x, dim, 0, false, false ); - }; - } -}); - -tape( 'the function throws an error if the dimension index exceeds the number of dimensions (strict=true)', 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 ], 10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - t.throws( badValue( values[ i ], -10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - } - t.end(); - - function badValue( x, dim ) { - return function badValue() { - sliceDimensionFrom( x, dim, 0, true, false ); - }; - } -}); - -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, - 20, - 20, - 20 - ]; - 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() { - sliceDimensionFrom( x, 0, s, true, false ); - }; - } -}); - -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; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - 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' } ) - ]; - - /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - start = [ - 10, - 20, - 20, - 20, - 10 - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceDimensionFrom( values[ i ], 0, start[ i ], false, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), 0, 'returns expected value' ); - t.strictEqual( actual.dtype, values[ i ].dtype, 'returns expected value' ); - } - t.end(); -}); - -tape( 'in non-strict mode, the function returns an empty array when a starting index is the one more than the last index along a dimension', function test( t ) { - var actual; - var values; - var start; - var dim; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - 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' } ) - ]; - - /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - dim = [ - 0, - 1, - 0, - 1, - 4 - ]; - - start = [ - 1, - 1, - 1, - 1, - 1 - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceDimensionFrom( values[ i ], dim[ i ], start[ i ], false, false ); // eslint-disable-line max-len - 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 a shifted view of a provided input array (ndims=1)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 2, true, false ); - - 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 = sliceDimensionFrom( x, 0, -4, true, false ); - - 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)', 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 1, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 2, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, -2, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 1, 1, true, false ); - - 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 = sliceDimensionFrom( x, 1, -2, true, false ); - - 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' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=3)', 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 1, true, false ); - - 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 = sliceDimensionFrom( x, 1, 1, true, false ); - - 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 = sliceDimensionFrom( x, 2, 2, true, false ); - - 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 = sliceDimensionFrom( x, 2, -1, true, false ); - - 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' ); - t.end(); -}); - -tape( 'if a provided ndarray has a constructor supporting read-only instances, the function returns a read-only instance', function test( t ) { - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - x = new baseCtor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports returning writable views', function test( t ) { - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - x = new baseCtor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - t.end(); -}); From 706201af2fb5b4c08f844b513fa654dca1d19df9 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 31 Jan 2026 08:25:38 +0000 Subject: [PATCH 80/92] Update README.md for ESM bundle v0.2.3 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7d5c2d7..97d02e8 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import sliceDimensionFrom from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-dimension-from@esm/index.mjs'; +import sliceDimensionFrom from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-dimension-from@v0.2.3-esm/index.mjs'; ``` #### sliceDimensionFrom( x, dim, start, strict, writable ) @@ -128,7 +128,7 @@ The function accepts the following arguments: 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 sliceDimensionFrom from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-dimension-from@esm/index.mjs'; +import sliceDimensionFrom from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-dimension-from@v0.2.3-esm/index.mjs'; // Create a linear ndarray buffer: var buf = zeroTo( 27 ); From de4f0b36fe8181c3746fd3ebadf9d64164b62a83 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 31 Jan 2026 08:25:39 +0000 Subject: [PATCH 81/92] Auto-generated commit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 97d02e8..e40b94e 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,11 @@ limitations under the License. ## Usage +```javascript +import sliceDimensionFrom from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-dimension-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-base-slice-dimension-from/tags). For example, + ```javascript import sliceDimensionFrom from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-dimension-from@v0.2.3-esm/index.mjs'; ``` @@ -128,7 +133,7 @@ The function accepts the following arguments: 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 sliceDimensionFrom from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-dimension-from@v0.2.3-esm/index.mjs'; +import sliceDimensionFrom from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-dimension-from@esm/index.mjs'; // Create a linear ndarray buffer: var buf = zeroTo( 27 ); From 9ef393e1c6fb7e186b9d440a446e49e59d700b43 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 8 Feb 2026 23:25:03 +0000 Subject: [PATCH 82/92] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 54bb1c2..50e4c67 100644 --- a/lib/main.js +++ b/lib/main.js @@ -26,7 +26,7 @@ var ndims = require( '@stdlib/ndarray-base-ndims' ); var slice = require( '@stdlib/ndarray-base-slice' ); var normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' ); var nulls = require( '@stdlib/array-base-nulls' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -81,12 +81,12 @@ function sliceDimensionFrom( x, dim, start, strict, writable ) { // Check whether we were provided a zero-dimensional array... if ( N === 0 ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.', N ) ); + throw new TypeError( format( '1lDF7', N ) ); } // Normalize the dimension index: d = normalizeIndex( dim, N-1 ); if ( d === -1 ) { - throw new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', N, dim ) ); + throw new RangeError( format( '1lDF8', N, dim ) ); } // Define a list of slice arguments: args = nulls( N ); diff --git a/package.json b/package.json index 44a0815..1f4882f 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/ndarray-base-slice": "^0.2.3", "@stdlib/slice-base-args2multislice": "^0.2.3", "@stdlib/slice-ctor": "^0.2.3", - "@stdlib/string-format": "^0.2.3", + "@stdlib/error-tools-fmtprodmsg": "^0.2.3", "@stdlib/types": "^0.4.3", "@stdlib/error-tools-fmtprodmsg": "^0.2.3" }, From c990c0f2de209ac9ba5e376162f4cd28ad517de6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 9 Feb 2026 00:18:08 +0000 Subject: [PATCH 83/92] Remove files --- index.d.ts | 534 ------ index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5381 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 49b5959..0000000 --- a/index.d.ts +++ /dev/null @@ -1,534 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceDimensionFrom( x: float64ndarray, dim: number, start: number, strict: boolean, writable: boolean ): float64ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceDimensionFrom( x: float32ndarray, dim: number, start: number, strict: boolean, writable: boolean ): float32ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: int32ndarray, dim: number, start: number, strict: boolean, writable: boolean ): int32ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: int16ndarray, dim: number, start: number, strict: boolean, writable: boolean ): int16ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: int8ndarray, dim: number, start: number, strict: boolean, writable: boolean ): int8ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint32ndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint32ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint16ndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint16ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint8ndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint8ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint8cndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint8cndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceDimensionFrom( x: complex128ndarray, dim: number, start: number, strict: boolean, writable: boolean ): complex128ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceDimensionFrom( x: complex64ndarray, dim: number, start: number, strict: boolean, writable: boolean ): complex64ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: genericndarray, dim: number, start: number, strict: boolean, writable: boolean ): genericndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: typedndarray, dim: number, start: number, strict: boolean, writable: boolean ): typedndarray; - - -// EXPORTS // - -export = sliceDimensionFrom; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index b371b47..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-ctor@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndims@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-normalize-index@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-nulls@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function m(m,l,o,j,a){var p,h,v;if(0===(h=r(m)))throw new TypeError(d("1lDF7",h));if(-1===(v=i(l,h-1)))throw new RangeError(d("1lDF8",h,l));return(p=n(h))[v]=new e(o,null),t(m,s(p),j,a)}export{m as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 425f555..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport Slice from '@stdlib/slice-ctor';\nimport ndims from '@stdlib/ndarray-base-ndims';\nimport slice from '@stdlib/ndarray-base-slice';\nimport normalizeIndex from '@stdlib/ndarray-base-normalize-index';\nimport nulls from '@stdlib/array-base-nulls';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns a shifted view of an input ndarray along a specified dimension.\n*\n* @param {ndarray} x - input array\n* @param {integer} dim - index of dimension to slice\n* @param {integer} start - starting index (inclusive)\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {TypeError} first argument must be an ndarray having one or more dimensions\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\n*\n* @example\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceDimensionFrom( x, 0, 1, false, false );\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 sliceDimensionFrom( x, dim, start, strict, writable ) {\n\tvar args;\n\tvar N;\n\tvar d;\n\n\t// Retrieve array meta data:\n\tN = ndims( x );\n\n\t// Check whether we were provided a zero-dimensional array...\n\tif ( N === 0 ) {\n\t\tthrow new TypeError( format( '1lDF7', N ) );\n\t}\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, N-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( '1lDF8', N, dim ) );\n\t}\n\t// Define a list of slice arguments:\n\targs = nulls( N );\n\targs[ d ] = new Slice( start, null );\n\n\t// Return a new array view:\n\treturn slice( x, args2multislice( args ), strict, writable );\n}\n\n\n// EXPORTS //\n\nexport default sliceDimensionFrom;\n"],"names":["sliceDimensionFrom","x","dim","start","strict","writable","args","N","d","ndims","TypeError","format","normalizeIndex","RangeError","nulls","Slice","slice","args2multislice"],"mappings":";;upBAyEA,SAASA,EAAoBC,EAAGC,EAAKC,EAAOC,EAAQC,GACnD,IAAIC,EACAC,EACAC,EAMJ,GAAW,KAHXD,EAAIE,EAAOR,IAIV,MAAM,IAAIS,UAAWC,EAAQ,QAASJ,IAIvC,IAAY,KADZC,EAAII,EAAgBV,EAAKK,EAAE,IAE1B,MAAM,IAAIM,WAAYF,EAAQ,QAASJ,EAAGL,IAO3C,OAJAI,EAAOQ,EAAOP,IACRC,GAAM,IAAIO,EAAOZ,EAAO,MAGvBa,EAAOf,EAAGgB,EAAiBX,GAAQF,EAAQC,EACnD"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 7fa0764..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From f6331e88bdc13838a6abdb58f703c3df4a0975e1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 9 Feb 2026 00:18:32 +0000 Subject: [PATCH 84/92] Auto-generated commit --- .editorconfig | 180 - .eslintrc.js | 1 - .gitattributes | 66 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 821 --- .github/workflows/publish.yml | 261 - .github/workflows/test.yml | 101 - .github/workflows/test_bundles.yml | 213 - .github/workflows/test_coverage.yml | 142 - .github/workflows/test_install.yml | 94 - .github/workflows/test_published_package.yml | 115 - .gitignore | 199 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 174 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 45 +- SECURITY.md | 5 - benchmark/benchmark.js | 681 --- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 49 - docs/types/test.ts | 164 - 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 | 102 - package.json | 71 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 621 --- 43 files changed, 4868 insertions(+), 5510 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/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/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index a53efc0..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-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 ced95ae..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-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 60a2bb4..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: '38 14 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 83d50c4..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,821 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send notification to Zulip if job fails: - - name: 'Send notification to Zulip in case of failure' - # Pin action to full length commit SHA - uses: zulip/github-actions-zulip/send-message@e4c8f27c732ba9bd98ac6be0583096dea82feea5 # v1.0.2 - if: failure() - with: - api-key: ${{ secrets.ZULIP_API_KEY }} - email: 'github-actions-bot@stdlib.zulipchat.com' - organization-url: 'https://stdlib.zulipchat.com' - to: 'workflows-standalone' - type: 'stream' - topic: ${{ github.event.repository.name }} - content: | - :cross_mark: **${{ github.workflow }}** workflow failed - - **Repository:** [${{ github.repository }}](${{ github.server_url }}/${{ github.repository }}) - **Run:** [View workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -202,7 +193,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]. diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 8a6b7a2..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,681 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 sliceDimensionFrom = require( './../lib' ); - - -// MAIN // - -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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2 ], { 'dtype': 'float64' } ), - empty( [ 2 ], { 'dtype': 'float32' } ), - empty( [ 2 ], { 'dtype': 'int32' } ), - empty( [ 2 ], { 'dtype': 'complex128' } ), - empty( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== '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 9543fcd..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-from" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-from -[production-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-slice-dimension-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 2ab577a..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import sliceDimensionFrom from '../docs/types/index'; -export = sliceDimensionFrom; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 2f5466d..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var v=function(i,r){return function(){return r||i((r={exports:{}}).exports,r),r.exports}};var o=v(function(p,u){"use strict";var l=require("@stdlib/slice-base-args2multislice"),c=require("@stdlib/slice-ctor"),q=require("@stdlib/ndarray-base-ndims"),f=require("@stdlib/ndarray-base-slice"),g=require("@stdlib/ndarray-base-normalize-index"),w=require("@stdlib/array-base-nulls"),s=require("@stdlib/string-format");function b(i,r,m,t,d){var n,e,a;if(e=q(i),e===0)throw new TypeError(s("invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.",e));if(a=g(r,e-1),a===-1)throw new RangeError(s("invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.",e,r));return n=w(e),n[a]=new c(m,null),f(i,l(n),t,d)}u.exports=b});var h=o();module.exports=h; -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 19dddde..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar args2multislice = require( '@stdlib/slice-base-args2multislice' );\nvar Slice = require( '@stdlib/slice-ctor' );\nvar ndims = require( '@stdlib/ndarray-base-ndims' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' );\nvar nulls = require( '@stdlib/array-base-nulls' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns a shifted view of an input ndarray along a specified dimension.\n*\n* @param {ndarray} x - input array\n* @param {integer} dim - index of dimension to slice\n* @param {integer} start - starting index (inclusive)\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {TypeError} first argument must be an ndarray having one or more dimensions\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceDimensionFrom( x, 0, 1, false, false );\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 sliceDimensionFrom( x, dim, start, strict, writable ) {\n\tvar args;\n\tvar N;\n\tvar d;\n\n\t// Retrieve array meta data:\n\tN = ndims( x );\n\n\t// Check whether we were provided a zero-dimensional array...\n\tif ( N === 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.', N ) );\n\t}\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, N-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', N, dim ) );\n\t}\n\t// Define a list of slice arguments:\n\targs = nulls( N );\n\targs[ d ] = new Slice( start, null );\n\n\t// Return a new array view:\n\treturn slice( x, args2multislice( args ), strict, writable );\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceDimensionFrom;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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 shifted view of an input ndarray along a specified dimension.\n*\n* @module @stdlib/ndarray-base-slice-dimension-from\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var sliceDimensionFrom = require( '@stdlib/ndarray-base-slice-dimension-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 = sliceDimensionFrom( x, 0, 1, false, false );\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,EAAkB,QAAS,oCAAqC,EAChEC,EAAQ,QAAS,oBAAqB,EACtCC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAiB,QAAS,sCAAuC,EACjEC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAS,QAAS,uBAAwB,EA6C9C,SAASC,EAAoBC,EAAGC,EAAKC,EAAOC,EAAQC,EAAW,CAC9D,IAAIC,EACAC,EACAC,EAMJ,GAHAD,EAAIZ,EAAOM,CAAE,EAGRM,IAAM,EACV,MAAM,IAAI,UAAWR,EAAQ,+GAAgHQ,CAAE,CAAE,EAIlJ,GADAC,EAAIX,EAAgBK,EAAKK,EAAE,CAAE,EACxBC,IAAM,GACV,MAAM,IAAI,WAAYT,EAAQ,6GAA8GQ,EAAGL,CAAI,CAAE,EAGtJ,OAAAI,EAAOR,EAAOS,CAAE,EAChBD,EAAME,CAAE,EAAI,IAAId,EAAOS,EAAO,IAAK,EAG5BP,EAAOK,EAAGR,EAAiBa,CAAK,EAAGF,EAAQC,CAAS,CAC5D,CAKAb,EAAO,QAAUQ,IC7CjB,IAAIS,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "args2multislice", "Slice", "ndims", "slice", "normalizeIndex", "nulls", "format", "sliceDimensionFrom", "x", "dim", "start", "strict", "writable", "args", "N", "d", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ffc1f03..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,49 +0,0 @@ - -{{alias}}( x, dim, start, strict, writable ) - Returns a shifted view of an input ndarray along a specified dimension. - - Parameters - ---------- - x: ndarray - Input array. - - dim: integer - Index of dimension to slice. If less than zero, the index is resolved - relative to the last dimension, with the last dimension corresponding to - the value `-1`. - - start: integer - Starting index (inclusive). If less than zero, the corresponding element - along the specified dimension is resolved relative to the last element - along that dimension. For negative integers, the last element - corresponds to the value `-1`. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - writable: boolean - Boolean indicating whether a returned ndarray should be writable. This - parameter only applies to ndarray constructors which support read-only - instances. - - Returns - ------- - out: ndarray - Output array view. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > x.shape - [ 2, 2 ] - > var y = {{alias}}( x, 1, 1, false, false ) - - > 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 9dfeaf3..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,164 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sliceDimensionFrom = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = 0; - - sliceDimensionFrom( empty( 'float64', sh, order ), 1, s, false, false ); // $ExpectType float64ndarray - sliceDimensionFrom( empty( 'float32', sh, order ), 1, s, false, false ); // $ExpectType float32ndarray - sliceDimensionFrom( empty( 'complex128', sh, order ), 1, s, false, false ); // $ExpectType complex128ndarray - sliceDimensionFrom( empty( 'complex64', sh, order ), 1, s, false, false ); // $ExpectType complex64ndarray - sliceDimensionFrom( empty( 'int32', sh, order ), 1, s, false, false ); // $ExpectType int32ndarray - sliceDimensionFrom( empty( 'int16', sh, order ), 1, s, false, false ); // $ExpectType int16ndarray - sliceDimensionFrom( empty( 'int8', sh, order ), 1, s, false, false ); // $ExpectType int8ndarray - sliceDimensionFrom( empty( 'uint32', sh, order ), 1, s, false, false ); // $ExpectType uint32ndarray - sliceDimensionFrom( empty( 'uint16', sh, order ), 1, s, false, false ); // $ExpectType uint16ndarray - sliceDimensionFrom( empty( 'uint8', sh, order ), 1, s, false, false ); // $ExpectType uint8ndarray - sliceDimensionFrom( empty( 'uint8c', sh, order ), 1, s, false, false ); // $ExpectType uint8cndarray - - sliceDimensionFrom( empty( 'float64', sh, order ), 1, s, true, true ); // $ExpectType float64ndarray - sliceDimensionFrom( empty( 'float32', sh, order ), 1, s, true, true ); // $ExpectType float32ndarray - sliceDimensionFrom( empty( 'complex128', sh, order ), 1, s, true, true ); // $ExpectType complex128ndarray - sliceDimensionFrom( empty( 'complex64', sh, order ), 1, s, true, true ); // $ExpectType complex64ndarray - sliceDimensionFrom( empty( 'int32', sh, order ), 1, s, true, true ); // $ExpectType int32ndarray - sliceDimensionFrom( empty( 'int16', sh, order ), 1, s, true, true ); // $ExpectType int16ndarray - sliceDimensionFrom( empty( 'int8', sh, order ), 1, s, true, true ); // $ExpectType int8ndarray - sliceDimensionFrom( empty( 'uint32', sh, order ), 1, s, true, true ); // $ExpectType uint32ndarray - sliceDimensionFrom( empty( 'uint16', sh, order ), 1, s, true, true ); // $ExpectType uint16ndarray - sliceDimensionFrom( empty( 'uint8', sh, order ), 1, s, true, true ); // $ExpectType uint8ndarray - sliceDimensionFrom( empty( 'uint8c', sh, order ), 1, s, true, true ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const s = 0; - - sliceDimensionFrom( '10', 1, s, false, false ); // $ExpectError - sliceDimensionFrom( 10, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( false, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( true, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( null, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( [], 1, s, false, false ); // $ExpectError - sliceDimensionFrom( {}, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( ( x: number ): number => x, 1, s, false, false ); // $ExpectError - - sliceDimensionFrom( '10', 1, s, true, true ); // $ExpectError - sliceDimensionFrom( 10, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( false, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( true, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( null, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( [], 1, s, true, true ); // $ExpectError - sliceDimensionFrom( {}, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( ( x: number ): number => x, 1, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a number... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 1; - - sliceDimensionFrom( x, '5', s, false, false ); // $ExpectError - sliceDimensionFrom( x, false, s, false, false ); // $ExpectError - sliceDimensionFrom( x, true, s, false, false ); // $ExpectError - sliceDimensionFrom( x, null, s, false, false ); // $ExpectError - sliceDimensionFrom( x, undefined, s, false, false ); // $ExpectError - sliceDimensionFrom( x, [ '5' ], s, false, false ); // $ExpectError - sliceDimensionFrom( x, {}, s, false, false ); // $ExpectError - sliceDimensionFrom( x, ( x: number ): number => x, s, false, false ); // $ExpectError - - sliceDimensionFrom( x, '5', s, true, true ); // $ExpectError - sliceDimensionFrom( x, false, s, true, true ); // $ExpectError - sliceDimensionFrom( x, true, s, true, true ); // $ExpectError - sliceDimensionFrom( x, null, s, true, true ); // $ExpectError - sliceDimensionFrom( x, undefined, s, true, true ); // $ExpectError - sliceDimensionFrom( x, [ '5' ], s, true, true ); // $ExpectError - sliceDimensionFrom( x, {}, s, true, true ); // $ExpectError - sliceDimensionFrom( x, ( x: number ): number => x, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceDimensionFrom( x, 1, '5', false, false ); // $ExpectError - sliceDimensionFrom( x, 1, false, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, true, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, null, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, undefined, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, [ '5' ], false, false ); // $ExpectError - sliceDimensionFrom( x, 1, {}, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, ( x: number ): number => x, 1, false, false ); // $ExpectError - - sliceDimensionFrom( x, 1, '5', true, true ); // $ExpectError - sliceDimensionFrom( x, 1, false, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, true, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, null, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, undefined, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, [ '5' ], true, true ); // $ExpectError - sliceDimensionFrom( x, 1, {}, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, ( x: number ): number => x, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x, 1, s, '5', false ); // $ExpectError - sliceDimensionFrom( x, 1, s, 5, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, null, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, undefined, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, [ '5' ], false ); // $ExpectError - sliceDimensionFrom( x, 1, s, {}, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x, 1, s, false, '5' ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, 5 ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, null ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, undefined ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, [ '5' ] ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, {} ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x ); // $ExpectError - sliceDimensionFrom( x, 1 ); // $ExpectError - sliceDimensionFrom( x, 1, s ); // $ExpectError - sliceDimensionFrom( x, 1, s, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index b17162a..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 sliceDimensionFrom = 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 = sliceDimensionFrom( x, 1, 1, false, false ); -// 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 columns of each matrix: -var y2 = sliceDimensionFrom( x, 2, 1, false, false ); -// returns - -var a2 = ndarray2array( y2 ); -console.log( a2 ); -// => [ [ [ 1, 2 ], [ 4, 5 ], [ 7, 8 ] ], [ [ 10, 11 ], [ 13, 14 ], [ 16, 17 ] ], [ [ 19, 20 ], [ 22, 23 ], [ 25, 26 ] ] ] - -// Get the last two matrices: -var y3 = sliceDimensionFrom( x, 0, 1, false, false ); -// returns - -var a3 = ndarray2array( y3 ); -console.log( a3 ); -// => [ [ [ 9, 10, 11 ], [ 12, 13, 14 ], [ 15, 16, 17 ] ], [ [ 18, 19, 20 ], [ 21, 22, 23 ], [ 24, 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 22f5594..49b5959 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..96fd5ba --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.3-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-ctor@v0.2.3-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndims@v0.2.3-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-normalize-index@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-nulls@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";function m(m,l,o,j,a){var p,h,v;if(0===(h=r(m)))throw new TypeError(d("1lDF7",h));if(-1===(v=i(l,h-1)))throw new RangeError(d("1lDF8",h,l));return(p=n(h))[v]=new e(o,null),t(m,s(p),j,a)}export{m as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..425f555 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport Slice from '@stdlib/slice-ctor';\nimport ndims from '@stdlib/ndarray-base-ndims';\nimport slice from '@stdlib/ndarray-base-slice';\nimport normalizeIndex from '@stdlib/ndarray-base-normalize-index';\nimport nulls from '@stdlib/array-base-nulls';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns a shifted view of an input ndarray along a specified dimension.\n*\n* @param {ndarray} x - input array\n* @param {integer} dim - index of dimension to slice\n* @param {integer} start - starting index (inclusive)\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {TypeError} first argument must be an ndarray having one or more dimensions\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\n*\n* @example\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceDimensionFrom( x, 0, 1, false, false );\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 sliceDimensionFrom( x, dim, start, strict, writable ) {\n\tvar args;\n\tvar N;\n\tvar d;\n\n\t// Retrieve array meta data:\n\tN = ndims( x );\n\n\t// Check whether we were provided a zero-dimensional array...\n\tif ( N === 0 ) {\n\t\tthrow new TypeError( format( '1lDF7', N ) );\n\t}\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, N-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( '1lDF8', N, dim ) );\n\t}\n\t// Define a list of slice arguments:\n\targs = nulls( N );\n\targs[ d ] = new Slice( start, null );\n\n\t// Return a new array view:\n\treturn slice( x, args2multislice( args ), strict, writable );\n}\n\n\n// EXPORTS //\n\nexport default sliceDimensionFrom;\n"],"names":["sliceDimensionFrom","x","dim","start","strict","writable","args","N","d","ndims","TypeError","format","normalizeIndex","RangeError","nulls","Slice","slice","args2multislice"],"mappings":";;upBAyEA,SAASA,EAAoBC,EAAGC,EAAKC,EAAOC,EAAQC,GACnD,IAAIC,EACAC,EACAC,EAMJ,GAAW,KAHXD,EAAIE,EAAOR,IAIV,MAAM,IAAIS,UAAWC,EAAQ,QAASJ,IAIvC,IAAY,KADZC,EAAII,EAAgBV,EAAKK,EAAE,IAE1B,MAAM,IAAIM,WAAYF,EAAQ,QAASJ,EAAGL,IAO3C,OAJAI,EAAOQ,EAAOP,IACRC,GAAM,IAAIO,EAAOZ,EAAO,MAGvBa,EAAOf,EAAGgB,EAAiBX,GAAQF,EAAQC,EACnD"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index b3f97b2..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 shifted view of an input ndarray along a specified dimension. -* -* @module @stdlib/ndarray-base-slice-dimension-from -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var sliceDimensionFrom = require( '@stdlib/ndarray-base-slice-dimension-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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // 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 50e4c67..0000000 --- a/lib/main.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var Slice = require( '@stdlib/slice-ctor' ); -var ndims = require( '@stdlib/ndarray-base-ndims' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' ); -var nulls = require( '@stdlib/array-base-nulls' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param {ndarray} x - input array -* @param {integer} dim - index of dimension to slice -* @param {integer} start - starting index (inclusive) -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @param {boolean} writable - boolean indicating whether a returned array should be writable -* @throws {TypeError} first argument must be an ndarray having one or more dimensions -* @throws {RangeError} dimension index exceeds the number of dimensions -* @throws {RangeError} slice 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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -function sliceDimensionFrom( x, dim, start, strict, writable ) { - var args; - var N; - var d; - - // Retrieve array meta data: - N = ndims( x ); - - // Check whether we were provided a zero-dimensional array... - if ( N === 0 ) { - throw new TypeError( format( '1lDF7', N ) ); - } - // Normalize the dimension index: - d = normalizeIndex( dim, N-1 ); - if ( d === -1 ) { - throw new RangeError( format( '1lDF8', N, dim ) ); - } - // Define a list of slice arguments: - args = nulls( N ); - args[ d ] = new Slice( start, null ); - - // Return a new array view: - return slice( x, args2multislice( args ), strict, writable ); -} - - -// EXPORTS // - -module.exports = sliceDimensionFrom; diff --git a/package.json b/package.json index 1f4882f..608cd81 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.4", "description": "Return a shifted view of an input ndarray along a specific dimension.", "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,50 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-nulls": "^0.1.1", - "@stdlib/ndarray-base-ndims": "^0.2.3", - "@stdlib/ndarray-base-normalize-index": "^0.2.3", - "@stdlib/ndarray-base-slice": "^0.2.3", - "@stdlib/slice-base-args2multislice": "^0.2.3", - "@stdlib/slice-ctor": "^0.2.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.2", - "@stdlib/array-typed": "^0.3.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.2", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.3", - "@stdlib/ndarray-base-ctor": "^0.3.1", - "@stdlib/ndarray-base-empty": "^0.3.2", - "@stdlib/ndarray-base-numel": "^0.2.3", - "@stdlib/ndarray-ctor": "^0.3.1", - "@stdlib/ndarray-empty": "^0.3.1", - "@stdlib/ndarray-to-array": "^0.2.1", - "@stdlib/ndarray-zeros": "^0.3.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.3" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..0a5311b --- /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 dd19802..0000000 --- a/test/test.js +++ /dev/null @@ -1,621 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 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 ndarray2array = require( '@stdlib/ndarray-to-array' ); -var baseCtor = require( '@stdlib/ndarray-base-ctor' ); -var ctor = require( '@stdlib/ndarray-ctor' ); -var sliceDimensionFrom = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sliceDimensionFrom, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a zero-dimensional array (strict=false)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error' ); - } - t.end(); - - function badValue( x ) { - return function badValue() { - sliceDimensionFrom( x, 0, 0, false, false ); - }; - } -}); - -tape( 'the function throws an error if provided a zero-dimensional array (strict=true)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error' ); - } - t.end(); - - function badValue( x ) { - return function badValue() { - sliceDimensionFrom( x, 0, 0, true, false ); - }; - } -}); - -tape( 'the function throws an error if the dimension index exceeds the number of dimensions (strict=false)', 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 ], 10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - t.throws( badValue( values[ i ], -10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - } - t.end(); - - function badValue( x, dim ) { - return function badValue() { - sliceDimensionFrom( x, dim, 0, false, false ); - }; - } -}); - -tape( 'the function throws an error if the dimension index exceeds the number of dimensions (strict=true)', 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 ], 10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - t.throws( badValue( values[ i ], -10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - } - t.end(); - - function badValue( x, dim ) { - return function badValue() { - sliceDimensionFrom( x, dim, 0, true, false ); - }; - } -}); - -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, - 20, - 20, - 20 - ]; - 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() { - sliceDimensionFrom( x, 0, s, true, false ); - }; - } -}); - -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; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - 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' } ) - ]; - - /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - start = [ - 10, - 20, - 20, - 20, - 10 - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceDimensionFrom( values[ i ], 0, start[ i ], false, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), 0, 'returns expected value' ); - t.strictEqual( actual.dtype, values[ i ].dtype, 'returns expected value' ); - } - t.end(); -}); - -tape( 'in non-strict mode, the function returns an empty array when a starting index is the one more than the last index along a dimension', function test( t ) { - var actual; - var values; - var start; - var dim; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - 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' } ) - ]; - - /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - dim = [ - 0, - 1, - 0, - 1, - 4 - ]; - - start = [ - 1, - 1, - 1, - 1, - 1 - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceDimensionFrom( values[ i ], dim[ i ], start[ i ], false, false ); // eslint-disable-line max-len - 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 a shifted view of a provided input array (ndims=1)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 2, true, false ); - - 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 = sliceDimensionFrom( x, 0, -4, true, false ); - - 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)', 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 1, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 2, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, -2, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 1, 1, true, false ); - - 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 = sliceDimensionFrom( x, 1, -2, true, false ); - - 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' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=3)', 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 1, true, false ); - - 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 = sliceDimensionFrom( x, 1, 1, true, false ); - - 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 = sliceDimensionFrom( x, 2, 2, true, false ); - - 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 = sliceDimensionFrom( x, 2, -1, true, false ); - - 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' ); - t.end(); -}); - -tape( 'if a provided ndarray has a constructor supporting read-only instances, the function returns a read-only instance', function test( t ) { - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - x = new baseCtor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports returning writable views', function test( t ) { - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - x = new baseCtor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - t.end(); -}); From 53a61f650429f856488d07d655476cc9f7d5ca59 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 9 Feb 2026 00:45:45 +0000 Subject: [PATCH 85/92] Update README.md for ESM bundle v0.2.4 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 815917f..296d065 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import sliceDimensionFrom from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-dimension-from@esm/index.mjs'; +import sliceDimensionFrom from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-dimension-from@v0.2.4-esm/index.mjs'; ``` #### sliceDimensionFrom( x, dim, start, strict, writable ) @@ -128,7 +128,7 @@ The function accepts the following arguments: 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 sliceDimensionFrom from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-dimension-from@esm/index.mjs'; +import sliceDimensionFrom from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-dimension-from@v0.2.4-esm/index.mjs'; // Create a linear ndarray buffer: var buf = zeroTo( 27 ); From 33d2bc91c72fa898eb75d8303e29de259f9154e4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 9 Feb 2026 00:45:45 +0000 Subject: [PATCH 86/92] Auto-generated commit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 296d065..e65f59d 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,11 @@ limitations under the License. ## Usage +```javascript +import sliceDimensionFrom from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-dimension-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-base-slice-dimension-from/tags). For example, + ```javascript import sliceDimensionFrom from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-dimension-from@v0.2.4-esm/index.mjs'; ``` @@ -128,7 +133,7 @@ The function accepts the following arguments: 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 sliceDimensionFrom from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-dimension-from@v0.2.4-esm/index.mjs'; +import sliceDimensionFrom from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-dimension-from@esm/index.mjs'; // Create a linear ndarray buffer: var buf = zeroTo( 27 ); From 31357091c9f9d01aa85663a93e16a08eef9a93d6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 9 Mar 2026 01:24:21 +0000 Subject: [PATCH 87/92] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 54bb1c2..50e4c67 100644 --- a/lib/main.js +++ b/lib/main.js @@ -26,7 +26,7 @@ var ndims = require( '@stdlib/ndarray-base-ndims' ); var slice = require( '@stdlib/ndarray-base-slice' ); var normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' ); var nulls = require( '@stdlib/array-base-nulls' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -81,12 +81,12 @@ function sliceDimensionFrom( x, dim, start, strict, writable ) { // Check whether we were provided a zero-dimensional array... if ( N === 0 ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.', N ) ); + throw new TypeError( format( '1lDF7', N ) ); } // Normalize the dimension index: d = normalizeIndex( dim, N-1 ); if ( d === -1 ) { - throw new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', N, dim ) ); + throw new RangeError( format( '1lDF8', N, dim ) ); } // Define a list of slice arguments: args = nulls( N ); diff --git a/package.json b/package.json index b6747ca..c03740a 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/ndarray-base-slice": "^0.2.3", "@stdlib/slice-base-args2multislice": "^0.2.3", "@stdlib/slice-ctor": "^0.2.3", - "@stdlib/string-format": "^0.2.3", + "@stdlib/error-tools-fmtprodmsg": "^0.2.3", "@stdlib/types": "^0.4.3", "@stdlib/error-tools-fmtprodmsg": "^0.2.3" }, From fcce2fab3781763bcd35506c4d1d5f63769fee0d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 9 Mar 2026 01:47:29 +0000 Subject: [PATCH 88/92] Remove files --- index.d.ts | 534 ------ index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5381 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 49b5959..0000000 --- a/index.d.ts +++ /dev/null @@ -1,534 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceDimensionFrom( x: float64ndarray, dim: number, start: number, strict: boolean, writable: boolean ): float64ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceDimensionFrom( x: float32ndarray, dim: number, start: number, strict: boolean, writable: boolean ): float32ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: int32ndarray, dim: number, start: number, strict: boolean, writable: boolean ): int32ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: int16ndarray, dim: number, start: number, strict: boolean, writable: boolean ): int16ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: int8ndarray, dim: number, start: number, strict: boolean, writable: boolean ): int8ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint32ndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint32ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint16ndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint16ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint8ndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint8ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint8cndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint8cndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceDimensionFrom( x: complex128ndarray, dim: number, start: number, strict: boolean, writable: boolean ): complex128ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceDimensionFrom( x: complex64ndarray, dim: number, start: number, strict: boolean, writable: boolean ): complex64ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: genericndarray, dim: number, start: number, strict: boolean, writable: boolean ): genericndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: typedndarray, dim: number, start: number, strict: boolean, writable: boolean ): typedndarray; - - -// EXPORTS // - -export = sliceDimensionFrom; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 96fd5ba..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.3-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-ctor@v0.2.3-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndims@v0.2.3-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-normalize-index@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-nulls@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";function m(m,l,o,j,a){var p,h,v;if(0===(h=r(m)))throw new TypeError(d("1lDF7",h));if(-1===(v=i(l,h-1)))throw new RangeError(d("1lDF8",h,l));return(p=n(h))[v]=new e(o,null),t(m,s(p),j,a)}export{m as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 425f555..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport Slice from '@stdlib/slice-ctor';\nimport ndims from '@stdlib/ndarray-base-ndims';\nimport slice from '@stdlib/ndarray-base-slice';\nimport normalizeIndex from '@stdlib/ndarray-base-normalize-index';\nimport nulls from '@stdlib/array-base-nulls';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns a shifted view of an input ndarray along a specified dimension.\n*\n* @param {ndarray} x - input array\n* @param {integer} dim - index of dimension to slice\n* @param {integer} start - starting index (inclusive)\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {TypeError} first argument must be an ndarray having one or more dimensions\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\n*\n* @example\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceDimensionFrom( x, 0, 1, false, false );\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 sliceDimensionFrom( x, dim, start, strict, writable ) {\n\tvar args;\n\tvar N;\n\tvar d;\n\n\t// Retrieve array meta data:\n\tN = ndims( x );\n\n\t// Check whether we were provided a zero-dimensional array...\n\tif ( N === 0 ) {\n\t\tthrow new TypeError( format( '1lDF7', N ) );\n\t}\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, N-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( '1lDF8', N, dim ) );\n\t}\n\t// Define a list of slice arguments:\n\targs = nulls( N );\n\targs[ d ] = new Slice( start, null );\n\n\t// Return a new array view:\n\treturn slice( x, args2multislice( args ), strict, writable );\n}\n\n\n// EXPORTS //\n\nexport default sliceDimensionFrom;\n"],"names":["sliceDimensionFrom","x","dim","start","strict","writable","args","N","d","ndims","TypeError","format","normalizeIndex","RangeError","nulls","Slice","slice","args2multislice"],"mappings":";;upBAyEA,SAASA,EAAoBC,EAAGC,EAAKC,EAAOC,EAAQC,GACnD,IAAIC,EACAC,EACAC,EAMJ,GAAW,KAHXD,EAAIE,EAAOR,IAIV,MAAM,IAAIS,UAAWC,EAAQ,QAASJ,IAIvC,IAAY,KADZC,EAAII,EAAgBV,EAAKK,EAAE,IAE1B,MAAM,IAAIM,WAAYF,EAAQ,QAASJ,EAAGL,IAO3C,OAJAI,EAAOQ,EAAOP,IACRC,GAAM,IAAIO,EAAOZ,EAAO,MAGvBa,EAAOf,EAAGgB,EAAiBX,GAAQF,EAAQC,EACnD"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 0a5311b..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 5c394db478b2938d8acec057bc4c742558f3deb4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 9 Mar 2026 01:47:53 +0000 Subject: [PATCH 89/92] Auto-generated commit --- .editorconfig | 180 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 821 --- .github/workflows/publish.yml | 261 - .github/workflows/test.yml | 101 - .github/workflows/test_bundles.yml | 213 - .github/workflows/test_coverage.yml | 142 - .github/workflows/test_install.yml | 94 - .github/workflows/test_published_package.yml | 115 - .gitignore | 199 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 174 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 45 +- SECURITY.md | 5 - benchmark/benchmark.js | 681 --- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 49 - docs/types/test.ts | 164 - 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 | 102 - package.json | 71 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 621 --- 44 files changed, 4868 insertions(+), 5511 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index dab5d2a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,180 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 569810e..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2026-03-09T01:16:49.653Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index a53efc0..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-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 ced95ae..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-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 60a2bb4..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: '38 14 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 83d50c4..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,821 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send notification to Zulip if job fails: - - name: 'Send notification to Zulip in case of failure' - # Pin action to full length commit SHA - uses: zulip/github-actions-zulip/send-message@e4c8f27c732ba9bd98ac6be0583096dea82feea5 # v1.0.2 - if: failure() - with: - api-key: ${{ secrets.ZULIP_API_KEY }} - email: 'github-actions-bot@stdlib.zulipchat.com' - organization-url: 'https://stdlib.zulipchat.com' - to: 'workflows-standalone' - type: 'stream' - topic: ${{ github.event.repository.name }} - content: | - :cross_mark: **${{ github.workflow }}** workflow failed - - **Repository:** [${{ github.repository }}](${{ github.server_url }}/${{ github.repository }}) - **Run:** [View workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -202,7 +193,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]. diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 8a6b7a2..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,681 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 sliceDimensionFrom = require( './../lib' ); - - -// MAIN // - -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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2 ], { 'dtype': 'float64' } ), - empty( [ 2 ], { 'dtype': 'float32' } ), - empty( [ 2 ], { 'dtype': 'int32' } ), - empty( [ 2 ], { 'dtype': 'complex128' } ), - empty( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== '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 9543fcd..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-from" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-from -[production-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-slice-dimension-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 2ab577a..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import sliceDimensionFrom from '../docs/types/index'; -export = sliceDimensionFrom; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 2f5466d..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var v=function(i,r){return function(){return r||i((r={exports:{}}).exports,r),r.exports}};var o=v(function(p,u){"use strict";var l=require("@stdlib/slice-base-args2multislice"),c=require("@stdlib/slice-ctor"),q=require("@stdlib/ndarray-base-ndims"),f=require("@stdlib/ndarray-base-slice"),g=require("@stdlib/ndarray-base-normalize-index"),w=require("@stdlib/array-base-nulls"),s=require("@stdlib/string-format");function b(i,r,m,t,d){var n,e,a;if(e=q(i),e===0)throw new TypeError(s("invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.",e));if(a=g(r,e-1),a===-1)throw new RangeError(s("invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.",e,r));return n=w(e),n[a]=new c(m,null),f(i,l(n),t,d)}u.exports=b});var h=o();module.exports=h; -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 19dddde..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar args2multislice = require( '@stdlib/slice-base-args2multislice' );\nvar Slice = require( '@stdlib/slice-ctor' );\nvar ndims = require( '@stdlib/ndarray-base-ndims' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' );\nvar nulls = require( '@stdlib/array-base-nulls' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns a shifted view of an input ndarray along a specified dimension.\n*\n* @param {ndarray} x - input array\n* @param {integer} dim - index of dimension to slice\n* @param {integer} start - starting index (inclusive)\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {TypeError} first argument must be an ndarray having one or more dimensions\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceDimensionFrom( x, 0, 1, false, false );\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 sliceDimensionFrom( x, dim, start, strict, writable ) {\n\tvar args;\n\tvar N;\n\tvar d;\n\n\t// Retrieve array meta data:\n\tN = ndims( x );\n\n\t// Check whether we were provided a zero-dimensional array...\n\tif ( N === 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.', N ) );\n\t}\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, N-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', N, dim ) );\n\t}\n\t// Define a list of slice arguments:\n\targs = nulls( N );\n\targs[ d ] = new Slice( start, null );\n\n\t// Return a new array view:\n\treturn slice( x, args2multislice( args ), strict, writable );\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceDimensionFrom;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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 shifted view of an input ndarray along a specified dimension.\n*\n* @module @stdlib/ndarray-base-slice-dimension-from\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var sliceDimensionFrom = require( '@stdlib/ndarray-base-slice-dimension-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 = sliceDimensionFrom( x, 0, 1, false, false );\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,EAAkB,QAAS,oCAAqC,EAChEC,EAAQ,QAAS,oBAAqB,EACtCC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAiB,QAAS,sCAAuC,EACjEC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAS,QAAS,uBAAwB,EA6C9C,SAASC,EAAoBC,EAAGC,EAAKC,EAAOC,EAAQC,EAAW,CAC9D,IAAIC,EACAC,EACAC,EAMJ,GAHAD,EAAIZ,EAAOM,CAAE,EAGRM,IAAM,EACV,MAAM,IAAI,UAAWR,EAAQ,+GAAgHQ,CAAE,CAAE,EAIlJ,GADAC,EAAIX,EAAgBK,EAAKK,EAAE,CAAE,EACxBC,IAAM,GACV,MAAM,IAAI,WAAYT,EAAQ,6GAA8GQ,EAAGL,CAAI,CAAE,EAGtJ,OAAAI,EAAOR,EAAOS,CAAE,EAChBD,EAAME,CAAE,EAAI,IAAId,EAAOS,EAAO,IAAK,EAG5BP,EAAOK,EAAGR,EAAiBa,CAAK,EAAGF,EAAQC,CAAS,CAC5D,CAKAb,EAAO,QAAUQ,IC7CjB,IAAIS,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "args2multislice", "Slice", "ndims", "slice", "normalizeIndex", "nulls", "format", "sliceDimensionFrom", "x", "dim", "start", "strict", "writable", "args", "N", "d", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ffc1f03..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,49 +0,0 @@ - -{{alias}}( x, dim, start, strict, writable ) - Returns a shifted view of an input ndarray along a specified dimension. - - Parameters - ---------- - x: ndarray - Input array. - - dim: integer - Index of dimension to slice. If less than zero, the index is resolved - relative to the last dimension, with the last dimension corresponding to - the value `-1`. - - start: integer - Starting index (inclusive). If less than zero, the corresponding element - along the specified dimension is resolved relative to the last element - along that dimension. For negative integers, the last element - corresponds to the value `-1`. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - writable: boolean - Boolean indicating whether a returned ndarray should be writable. This - parameter only applies to ndarray constructors which support read-only - instances. - - Returns - ------- - out: ndarray - Output array view. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > x.shape - [ 2, 2 ] - > var y = {{alias}}( x, 1, 1, false, false ) - - > 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 9dfeaf3..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,164 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sliceDimensionFrom = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = 0; - - sliceDimensionFrom( empty( 'float64', sh, order ), 1, s, false, false ); // $ExpectType float64ndarray - sliceDimensionFrom( empty( 'float32', sh, order ), 1, s, false, false ); // $ExpectType float32ndarray - sliceDimensionFrom( empty( 'complex128', sh, order ), 1, s, false, false ); // $ExpectType complex128ndarray - sliceDimensionFrom( empty( 'complex64', sh, order ), 1, s, false, false ); // $ExpectType complex64ndarray - sliceDimensionFrom( empty( 'int32', sh, order ), 1, s, false, false ); // $ExpectType int32ndarray - sliceDimensionFrom( empty( 'int16', sh, order ), 1, s, false, false ); // $ExpectType int16ndarray - sliceDimensionFrom( empty( 'int8', sh, order ), 1, s, false, false ); // $ExpectType int8ndarray - sliceDimensionFrom( empty( 'uint32', sh, order ), 1, s, false, false ); // $ExpectType uint32ndarray - sliceDimensionFrom( empty( 'uint16', sh, order ), 1, s, false, false ); // $ExpectType uint16ndarray - sliceDimensionFrom( empty( 'uint8', sh, order ), 1, s, false, false ); // $ExpectType uint8ndarray - sliceDimensionFrom( empty( 'uint8c', sh, order ), 1, s, false, false ); // $ExpectType uint8cndarray - - sliceDimensionFrom( empty( 'float64', sh, order ), 1, s, true, true ); // $ExpectType float64ndarray - sliceDimensionFrom( empty( 'float32', sh, order ), 1, s, true, true ); // $ExpectType float32ndarray - sliceDimensionFrom( empty( 'complex128', sh, order ), 1, s, true, true ); // $ExpectType complex128ndarray - sliceDimensionFrom( empty( 'complex64', sh, order ), 1, s, true, true ); // $ExpectType complex64ndarray - sliceDimensionFrom( empty( 'int32', sh, order ), 1, s, true, true ); // $ExpectType int32ndarray - sliceDimensionFrom( empty( 'int16', sh, order ), 1, s, true, true ); // $ExpectType int16ndarray - sliceDimensionFrom( empty( 'int8', sh, order ), 1, s, true, true ); // $ExpectType int8ndarray - sliceDimensionFrom( empty( 'uint32', sh, order ), 1, s, true, true ); // $ExpectType uint32ndarray - sliceDimensionFrom( empty( 'uint16', sh, order ), 1, s, true, true ); // $ExpectType uint16ndarray - sliceDimensionFrom( empty( 'uint8', sh, order ), 1, s, true, true ); // $ExpectType uint8ndarray - sliceDimensionFrom( empty( 'uint8c', sh, order ), 1, s, true, true ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const s = 0; - - sliceDimensionFrom( '10', 1, s, false, false ); // $ExpectError - sliceDimensionFrom( 10, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( false, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( true, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( null, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( [], 1, s, false, false ); // $ExpectError - sliceDimensionFrom( {}, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( ( x: number ): number => x, 1, s, false, false ); // $ExpectError - - sliceDimensionFrom( '10', 1, s, true, true ); // $ExpectError - sliceDimensionFrom( 10, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( false, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( true, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( null, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( [], 1, s, true, true ); // $ExpectError - sliceDimensionFrom( {}, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( ( x: number ): number => x, 1, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a number... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 1; - - sliceDimensionFrom( x, '5', s, false, false ); // $ExpectError - sliceDimensionFrom( x, false, s, false, false ); // $ExpectError - sliceDimensionFrom( x, true, s, false, false ); // $ExpectError - sliceDimensionFrom( x, null, s, false, false ); // $ExpectError - sliceDimensionFrom( x, undefined, s, false, false ); // $ExpectError - sliceDimensionFrom( x, [ '5' ], s, false, false ); // $ExpectError - sliceDimensionFrom( x, {}, s, false, false ); // $ExpectError - sliceDimensionFrom( x, ( x: number ): number => x, s, false, false ); // $ExpectError - - sliceDimensionFrom( x, '5', s, true, true ); // $ExpectError - sliceDimensionFrom( x, false, s, true, true ); // $ExpectError - sliceDimensionFrom( x, true, s, true, true ); // $ExpectError - sliceDimensionFrom( x, null, s, true, true ); // $ExpectError - sliceDimensionFrom( x, undefined, s, true, true ); // $ExpectError - sliceDimensionFrom( x, [ '5' ], s, true, true ); // $ExpectError - sliceDimensionFrom( x, {}, s, true, true ); // $ExpectError - sliceDimensionFrom( x, ( x: number ): number => x, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceDimensionFrom( x, 1, '5', false, false ); // $ExpectError - sliceDimensionFrom( x, 1, false, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, true, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, null, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, undefined, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, [ '5' ], false, false ); // $ExpectError - sliceDimensionFrom( x, 1, {}, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, ( x: number ): number => x, 1, false, false ); // $ExpectError - - sliceDimensionFrom( x, 1, '5', true, true ); // $ExpectError - sliceDimensionFrom( x, 1, false, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, true, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, null, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, undefined, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, [ '5' ], true, true ); // $ExpectError - sliceDimensionFrom( x, 1, {}, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, ( x: number ): number => x, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x, 1, s, '5', false ); // $ExpectError - sliceDimensionFrom( x, 1, s, 5, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, null, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, undefined, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, [ '5' ], false ); // $ExpectError - sliceDimensionFrom( x, 1, s, {}, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x, 1, s, false, '5' ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, 5 ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, null ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, undefined ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, [ '5' ] ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, {} ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x ); // $ExpectError - sliceDimensionFrom( x, 1 ); // $ExpectError - sliceDimensionFrom( x, 1, s ); // $ExpectError - sliceDimensionFrom( x, 1, s, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index b17162a..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 sliceDimensionFrom = 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 = sliceDimensionFrom( x, 1, 1, false, false ); -// 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 columns of each matrix: -var y2 = sliceDimensionFrom( x, 2, 1, false, false ); -// returns - -var a2 = ndarray2array( y2 ); -console.log( a2 ); -// => [ [ [ 1, 2 ], [ 4, 5 ], [ 7, 8 ] ], [ [ 10, 11 ], [ 13, 14 ], [ 16, 17 ] ], [ [ 19, 20 ], [ 22, 23 ], [ 25, 26 ] ] ] - -// Get the last two matrices: -var y3 = sliceDimensionFrom( x, 0, 1, false, false ); -// returns - -var a3 = ndarray2array( y3 ); -console.log( a3 ); -// => [ [ [ 9, 10, 11 ], [ 12, 13, 14 ], [ 15, 16, 17 ] ], [ [ 18, 19, 20 ], [ 21, 22, 23 ], [ 24, 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 22f5594..49b5959 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..6f24d73 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.3-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-ctor@v0.2.3-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndims@v0.2.3-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.3-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-normalize-index@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-nulls@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";function m(m,l,o,j,a){var p,h,v;if(0===(h=r(m)))throw new TypeError(d("1lDF7",h));if(-1===(v=i(l,h-1)))throw new RangeError(d("1lDF8",h,l));return(p=n(h))[v]=new e(o,null),t(m,s(p),j,a)}export{m as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..425f555 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport Slice from '@stdlib/slice-ctor';\nimport ndims from '@stdlib/ndarray-base-ndims';\nimport slice from '@stdlib/ndarray-base-slice';\nimport normalizeIndex from '@stdlib/ndarray-base-normalize-index';\nimport nulls from '@stdlib/array-base-nulls';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns a shifted view of an input ndarray along a specified dimension.\n*\n* @param {ndarray} x - input array\n* @param {integer} dim - index of dimension to slice\n* @param {integer} start - starting index (inclusive)\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {TypeError} first argument must be an ndarray having one or more dimensions\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\n*\n* @example\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceDimensionFrom( x, 0, 1, false, false );\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 sliceDimensionFrom( x, dim, start, strict, writable ) {\n\tvar args;\n\tvar N;\n\tvar d;\n\n\t// Retrieve array meta data:\n\tN = ndims( x );\n\n\t// Check whether we were provided a zero-dimensional array...\n\tif ( N === 0 ) {\n\t\tthrow new TypeError( format( '1lDF7', N ) );\n\t}\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, N-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( '1lDF8', N, dim ) );\n\t}\n\t// Define a list of slice arguments:\n\targs = nulls( N );\n\targs[ d ] = new Slice( start, null );\n\n\t// Return a new array view:\n\treturn slice( x, args2multislice( args ), strict, writable );\n}\n\n\n// EXPORTS //\n\nexport default sliceDimensionFrom;\n"],"names":["sliceDimensionFrom","x","dim","start","strict","writable","args","N","d","ndims","TypeError","format","normalizeIndex","RangeError","nulls","Slice","slice","args2multislice"],"mappings":";;upBAyEA,SAASA,EAAoBC,EAAGC,EAAKC,EAAOC,EAAQC,GACnD,IAAIC,EACAC,EACAC,EAMJ,GAAW,KAHXD,EAAIE,EAAOR,IAIV,MAAM,IAAIS,UAAWC,EAAQ,QAASJ,IAIvC,IAAY,KADZC,EAAII,EAAgBV,EAAKK,EAAE,IAE1B,MAAM,IAAIM,WAAYF,EAAQ,QAASJ,EAAGL,IAO3C,OAJAI,EAAOQ,EAAOP,IACRC,GAAM,IAAIO,EAAOZ,EAAO,MAGvBa,EAAOf,EAAGgB,EAAiBX,GAAQF,EAAQC,EACnD"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index b3f97b2..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 shifted view of an input ndarray along a specified dimension. -* -* @module @stdlib/ndarray-base-slice-dimension-from -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var sliceDimensionFrom = require( '@stdlib/ndarray-base-slice-dimension-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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // 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 50e4c67..0000000 --- a/lib/main.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var Slice = require( '@stdlib/slice-ctor' ); -var ndims = require( '@stdlib/ndarray-base-ndims' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' ); -var nulls = require( '@stdlib/array-base-nulls' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param {ndarray} x - input array -* @param {integer} dim - index of dimension to slice -* @param {integer} start - starting index (inclusive) -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @param {boolean} writable - boolean indicating whether a returned array should be writable -* @throws {TypeError} first argument must be an ndarray having one or more dimensions -* @throws {RangeError} dimension index exceeds the number of dimensions -* @throws {RangeError} slice 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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -function sliceDimensionFrom( x, dim, start, strict, writable ) { - var args; - var N; - var d; - - // Retrieve array meta data: - N = ndims( x ); - - // Check whether we were provided a zero-dimensional array... - if ( N === 0 ) { - throw new TypeError( format( '1lDF7', N ) ); - } - // Normalize the dimension index: - d = normalizeIndex( dim, N-1 ); - if ( d === -1 ) { - throw new RangeError( format( '1lDF8', N, dim ) ); - } - // Define a list of slice arguments: - args = nulls( N ); - args[ d ] = new Slice( start, null ); - - // Return a new array view: - return slice( x, args2multislice( args ), strict, writable ); -} - - -// EXPORTS // - -module.exports = sliceDimensionFrom; diff --git a/package.json b/package.json index c03740a..608cd81 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.4", "description": "Return a shifted view of an input ndarray along a specific dimension.", "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,50 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-nulls": "^0.1.1", - "@stdlib/ndarray-base-ndims": "^0.2.3", - "@stdlib/ndarray-base-normalize-index": "^0.2.3", - "@stdlib/ndarray-base-slice": "^0.2.3", - "@stdlib/slice-base-args2multislice": "^0.2.3", - "@stdlib/slice-ctor": "^0.2.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.2", - "@stdlib/array-typed": "^0.3.2", - "@stdlib/assert-is-ndarray-like": "^0.2.3", - "@stdlib/ndarray-array": "^0.2.3", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.3", - "@stdlib/ndarray-base-ctor": "^0.3.1", - "@stdlib/ndarray-base-empty": "^0.3.2", - "@stdlib/ndarray-base-numel": "^0.2.3", - "@stdlib/ndarray-ctor": "^0.3.1", - "@stdlib/ndarray-empty": "^0.3.1", - "@stdlib/ndarray-to-array": "^0.2.2", - "@stdlib/ndarray-zeros": "^0.3.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.3" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..4c2950c --- /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 dd19802..0000000 --- a/test/test.js +++ /dev/null @@ -1,621 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 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 ndarray2array = require( '@stdlib/ndarray-to-array' ); -var baseCtor = require( '@stdlib/ndarray-base-ctor' ); -var ctor = require( '@stdlib/ndarray-ctor' ); -var sliceDimensionFrom = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sliceDimensionFrom, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a zero-dimensional array (strict=false)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error' ); - } - t.end(); - - function badValue( x ) { - return function badValue() { - sliceDimensionFrom( x, 0, 0, false, false ); - }; - } -}); - -tape( 'the function throws an error if provided a zero-dimensional array (strict=true)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error' ); - } - t.end(); - - function badValue( x ) { - return function badValue() { - sliceDimensionFrom( x, 0, 0, true, false ); - }; - } -}); - -tape( 'the function throws an error if the dimension index exceeds the number of dimensions (strict=false)', 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 ], 10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - t.throws( badValue( values[ i ], -10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - } - t.end(); - - function badValue( x, dim ) { - return function badValue() { - sliceDimensionFrom( x, dim, 0, false, false ); - }; - } -}); - -tape( 'the function throws an error if the dimension index exceeds the number of dimensions (strict=true)', 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 ], 10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - t.throws( badValue( values[ i ], -10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - } - t.end(); - - function badValue( x, dim ) { - return function badValue() { - sliceDimensionFrom( x, dim, 0, true, false ); - }; - } -}); - -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, - 20, - 20, - 20 - ]; - 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() { - sliceDimensionFrom( x, 0, s, true, false ); - }; - } -}); - -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; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - 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' } ) - ]; - - /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - start = [ - 10, - 20, - 20, - 20, - 10 - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceDimensionFrom( values[ i ], 0, start[ i ], false, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), 0, 'returns expected value' ); - t.strictEqual( actual.dtype, values[ i ].dtype, 'returns expected value' ); - } - t.end(); -}); - -tape( 'in non-strict mode, the function returns an empty array when a starting index is the one more than the last index along a dimension', function test( t ) { - var actual; - var values; - var start; - var dim; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - 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' } ) - ]; - - /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - dim = [ - 0, - 1, - 0, - 1, - 4 - ]; - - start = [ - 1, - 1, - 1, - 1, - 1 - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceDimensionFrom( values[ i ], dim[ i ], start[ i ], false, false ); // eslint-disable-line max-len - 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 a shifted view of a provided input array (ndims=1)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 2, true, false ); - - 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 = sliceDimensionFrom( x, 0, -4, true, false ); - - 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)', 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 1, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 2, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, -2, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 1, 1, true, false ); - - 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 = sliceDimensionFrom( x, 1, -2, true, false ); - - 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' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=3)', 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 1, true, false ); - - 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 = sliceDimensionFrom( x, 1, 1, true, false ); - - 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 = sliceDimensionFrom( x, 2, 2, true, false ); - - 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 = sliceDimensionFrom( x, 2, -1, true, false ); - - 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' ); - t.end(); -}); - -tape( 'if a provided ndarray has a constructor supporting read-only instances, the function returns a read-only instance', function test( t ) { - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - x = new baseCtor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports returning writable views', function test( t ) { - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - x = new baseCtor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - t.end(); -}); From 8b3470852bc365c84020224e0fd90d13b1873b29 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 10 Apr 2026 03:25:15 +0000 Subject: [PATCH 90/92] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 54bb1c2..50e4c67 100644 --- a/lib/main.js +++ b/lib/main.js @@ -26,7 +26,7 @@ var ndims = require( '@stdlib/ndarray-base-ndims' ); var slice = require( '@stdlib/ndarray-base-slice' ); var normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' ); var nulls = require( '@stdlib/array-base-nulls' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -81,12 +81,12 @@ function sliceDimensionFrom( x, dim, start, strict, writable ) { // Check whether we were provided a zero-dimensional array... if ( N === 0 ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.', N ) ); + throw new TypeError( format( '1lDF7', N ) ); } // Normalize the dimension index: d = normalizeIndex( dim, N-1 ); if ( d === -1 ) { - throw new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', N, dim ) ); + throw new RangeError( format( '1lDF8', N, dim ) ); } // Define a list of slice arguments: args = nulls( N ); diff --git a/package.json b/package.json index b6747ca..c03740a 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/ndarray-base-slice": "^0.2.3", "@stdlib/slice-base-args2multislice": "^0.2.3", "@stdlib/slice-ctor": "^0.2.3", - "@stdlib/string-format": "^0.2.3", + "@stdlib/error-tools-fmtprodmsg": "^0.2.3", "@stdlib/types": "^0.4.3", "@stdlib/error-tools-fmtprodmsg": "^0.2.3" }, From 4704f519bd2891e881858e6345cfe0efc8ad4196 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 10 Apr 2026 03:41:52 +0000 Subject: [PATCH 91/92] Remove files --- index.d.ts | 534 ------ index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5381 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 49b5959..0000000 --- a/index.d.ts +++ /dev/null @@ -1,534 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceDimensionFrom( x: float64ndarray, dim: number, start: number, strict: boolean, writable: boolean ): float64ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceDimensionFrom( x: float32ndarray, dim: number, start: number, strict: boolean, writable: boolean ): float32ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: int32ndarray, dim: number, start: number, strict: boolean, writable: boolean ): int32ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: int16ndarray, dim: number, start: number, strict: boolean, writable: boolean ): int16ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: int8ndarray, dim: number, start: number, strict: boolean, writable: boolean ): int8ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint32ndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint32ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint16ndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint16ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint8ndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint8ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: uint8cndarray, dim: number, start: number, strict: boolean, writable: boolean ): uint8cndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceDimensionFrom( x: complex128ndarray, dim: number, start: number, strict: boolean, writable: boolean ): complex128ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceDimensionFrom( x: complex64ndarray, dim: number, start: number, strict: boolean, writable: boolean ): complex64ndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: genericndarray, dim: number, start: number, strict: boolean, writable: boolean ): genericndarray; - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param x - input array -* @param dim - index of dimension to slice -* @param start - starting index (inclusive) -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceDimensionFrom( x: typedndarray, dim: number, start: number, strict: boolean, writable: boolean ): typedndarray; - - -// EXPORTS // - -export = sliceDimensionFrom; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 6f24d73..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.3-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-ctor@v0.2.3-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndims@v0.2.3-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.3-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-normalize-index@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-nulls@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";function m(m,l,o,j,a){var p,h,v;if(0===(h=r(m)))throw new TypeError(d("1lDF7",h));if(-1===(v=i(l,h-1)))throw new RangeError(d("1lDF8",h,l));return(p=n(h))[v]=new e(o,null),t(m,s(p),j,a)}export{m as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 425f555..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport Slice from '@stdlib/slice-ctor';\nimport ndims from '@stdlib/ndarray-base-ndims';\nimport slice from '@stdlib/ndarray-base-slice';\nimport normalizeIndex from '@stdlib/ndarray-base-normalize-index';\nimport nulls from '@stdlib/array-base-nulls';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns a shifted view of an input ndarray along a specified dimension.\n*\n* @param {ndarray} x - input array\n* @param {integer} dim - index of dimension to slice\n* @param {integer} start - starting index (inclusive)\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {TypeError} first argument must be an ndarray having one or more dimensions\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\n*\n* @example\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceDimensionFrom( x, 0, 1, false, false );\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 sliceDimensionFrom( x, dim, start, strict, writable ) {\n\tvar args;\n\tvar N;\n\tvar d;\n\n\t// Retrieve array meta data:\n\tN = ndims( x );\n\n\t// Check whether we were provided a zero-dimensional array...\n\tif ( N === 0 ) {\n\t\tthrow new TypeError( format( '1lDF7', N ) );\n\t}\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, N-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( '1lDF8', N, dim ) );\n\t}\n\t// Define a list of slice arguments:\n\targs = nulls( N );\n\targs[ d ] = new Slice( start, null );\n\n\t// Return a new array view:\n\treturn slice( x, args2multislice( args ), strict, writable );\n}\n\n\n// EXPORTS //\n\nexport default sliceDimensionFrom;\n"],"names":["sliceDimensionFrom","x","dim","start","strict","writable","args","N","d","ndims","TypeError","format","normalizeIndex","RangeError","nulls","Slice","slice","args2multislice"],"mappings":";;upBAyEA,SAASA,EAAoBC,EAAGC,EAAKC,EAAOC,EAAQC,GACnD,IAAIC,EACAC,EACAC,EAMJ,GAAW,KAHXD,EAAIE,EAAOR,IAIV,MAAM,IAAIS,UAAWC,EAAQ,QAASJ,IAIvC,IAAY,KADZC,EAAII,EAAgBV,EAAKK,EAAE,IAE1B,MAAM,IAAIM,WAAYF,EAAQ,QAASJ,EAAGL,IAO3C,OAJAI,EAAOQ,EAAOP,IACRC,GAAM,IAAIO,EAAOZ,EAAO,MAGvBa,EAAOf,EAAGgB,EAAiBX,GAAQF,EAAQC,EACnD"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 4c2950c..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 09bb4157deeea7d77054f9c486d36a00dc9aa978 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 10 Apr 2026 03:42:18 +0000 Subject: [PATCH 92/92] Auto-generated commit --- .editorconfig | 189 - .eslintrc.js | 1 - .gitattributes | 68 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 821 --- .github/workflows/publish.yml | 261 - .github/workflows/test.yml | 101 - .github/workflows/test_bundles.yml | 213 - .github/workflows/test_coverage.yml | 142 - .github/workflows/test_install.yml | 94 - .github/workflows/test_published_package.yml | 115 - .gitignore | 199 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 174 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 45 +- SECURITY.md | 5 - benchmark/benchmark.js | 681 --- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 49 - docs/types/test.ts | 164 - 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 | 102 - package.json | 71 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 621 --- 44 files changed, 4868 insertions(+), 5522 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 80f3fca..0000000 --- a/.editorconfig +++ /dev/null @@ -1,189 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Ignore generated lock files for GitHub Agentic Workflows: -[*.lock.yml] -charset = unset -end_of_line = unset -indent_style = unset -indent_size = unset -trim_trailing_whitespace = unset -insert_final_newline = unset - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 24b327f..0000000 --- a/.gitattributes +++ /dev/null @@ -1,68 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation - -.github/workflows/*.lock.yml linguist-generated=true merge=ours diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index e3f2019..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2026-04-10T03:23:40.084Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index a53efc0..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-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 ced95ae..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-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 60a2bb4..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: '38 14 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 83d50c4..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,821 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send notification to Zulip if job fails: - - name: 'Send notification to Zulip in case of failure' - # Pin action to full length commit SHA - uses: zulip/github-actions-zulip/send-message@e4c8f27c732ba9bd98ac6be0583096dea82feea5 # v1.0.2 - if: failure() - with: - api-key: ${{ secrets.ZULIP_API_KEY }} - email: 'github-actions-bot@stdlib.zulipchat.com' - organization-url: 'https://stdlib.zulipchat.com' - to: 'workflows-standalone' - type: 'stream' - topic: ${{ github.event.repository.name }} - content: | - :cross_mark: **${{ github.workflow }}** workflow failed - - **Repository:** [${{ github.repository }}](${{ github.server_url }}/${{ github.repository }}) - **Run:** [View workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -202,7 +193,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]. diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 8a6b7a2..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,681 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 sliceDimensionFrom = require( './../lib' ); - - -// MAIN // - -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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2 ], { 'dtype': 'float64' } ), - empty( [ 2 ], { 'dtype': 'float32' } ), - empty( [ 2 ], { 'dtype': 'int32' } ), - empty( [ 2 ], { 'dtype': 'complex128' } ), - empty( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 0, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 1, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 2, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 3, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return 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 = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = 20; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceDimensionFrom( values[ i%values.length ], 4, s, false, false ); - if ( typeof v !== '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 9543fcd..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-from" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-dimension-from -[production-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-slice-dimension-from/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-slice-dimension-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 2ab577a..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import sliceDimensionFrom from '../docs/types/index'; -export = sliceDimensionFrom; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 2f5466d..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var v=function(i,r){return function(){return r||i((r={exports:{}}).exports,r),r.exports}};var o=v(function(p,u){"use strict";var l=require("@stdlib/slice-base-args2multislice"),c=require("@stdlib/slice-ctor"),q=require("@stdlib/ndarray-base-ndims"),f=require("@stdlib/ndarray-base-slice"),g=require("@stdlib/ndarray-base-normalize-index"),w=require("@stdlib/array-base-nulls"),s=require("@stdlib/string-format");function b(i,r,m,t,d){var n,e,a;if(e=q(i),e===0)throw new TypeError(s("invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.",e));if(a=g(r,e-1),a===-1)throw new RangeError(s("invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.",e,r));return n=w(e),n[a]=new c(m,null),f(i,l(n),t,d)}u.exports=b});var h=o();module.exports=h; -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 19dddde..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar args2multislice = require( '@stdlib/slice-base-args2multislice' );\nvar Slice = require( '@stdlib/slice-ctor' );\nvar ndims = require( '@stdlib/ndarray-base-ndims' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' );\nvar nulls = require( '@stdlib/array-base-nulls' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns a shifted view of an input ndarray along a specified dimension.\n*\n* @param {ndarray} x - input array\n* @param {integer} dim - index of dimension to slice\n* @param {integer} start - starting index (inclusive)\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {TypeError} first argument must be an ndarray having one or more dimensions\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceDimensionFrom( x, 0, 1, false, false );\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 sliceDimensionFrom( x, dim, start, strict, writable ) {\n\tvar args;\n\tvar N;\n\tvar d;\n\n\t// Retrieve array meta data:\n\tN = ndims( x );\n\n\t// Check whether we were provided a zero-dimensional array...\n\tif ( N === 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.', N ) );\n\t}\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, N-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', N, dim ) );\n\t}\n\t// Define a list of slice arguments:\n\targs = nulls( N );\n\targs[ d ] = new Slice( start, null );\n\n\t// Return a new array view:\n\treturn slice( x, args2multislice( args ), strict, writable );\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceDimensionFrom;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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 shifted view of an input ndarray along a specified dimension.\n*\n* @module @stdlib/ndarray-base-slice-dimension-from\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var sliceDimensionFrom = require( '@stdlib/ndarray-base-slice-dimension-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 = sliceDimensionFrom( x, 0, 1, false, false );\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,EAAkB,QAAS,oCAAqC,EAChEC,EAAQ,QAAS,oBAAqB,EACtCC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAiB,QAAS,sCAAuC,EACjEC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAS,QAAS,uBAAwB,EA6C9C,SAASC,EAAoBC,EAAGC,EAAKC,EAAOC,EAAQC,EAAW,CAC9D,IAAIC,EACAC,EACAC,EAMJ,GAHAD,EAAIZ,EAAOM,CAAE,EAGRM,IAAM,EACV,MAAM,IAAI,UAAWR,EAAQ,+GAAgHQ,CAAE,CAAE,EAIlJ,GADAC,EAAIX,EAAgBK,EAAKK,EAAE,CAAE,EACxBC,IAAM,GACV,MAAM,IAAI,WAAYT,EAAQ,6GAA8GQ,EAAGL,CAAI,CAAE,EAGtJ,OAAAI,EAAOR,EAAOS,CAAE,EAChBD,EAAME,CAAE,EAAI,IAAId,EAAOS,EAAO,IAAK,EAG5BP,EAAOK,EAAGR,EAAiBa,CAAK,EAAGF,EAAQC,CAAS,CAC5D,CAKAb,EAAO,QAAUQ,IC7CjB,IAAIS,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "args2multislice", "Slice", "ndims", "slice", "normalizeIndex", "nulls", "format", "sliceDimensionFrom", "x", "dim", "start", "strict", "writable", "args", "N", "d", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ffc1f03..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,49 +0,0 @@ - -{{alias}}( x, dim, start, strict, writable ) - Returns a shifted view of an input ndarray along a specified dimension. - - Parameters - ---------- - x: ndarray - Input array. - - dim: integer - Index of dimension to slice. If less than zero, the index is resolved - relative to the last dimension, with the last dimension corresponding to - the value `-1`. - - start: integer - Starting index (inclusive). If less than zero, the corresponding element - along the specified dimension is resolved relative to the last element - along that dimension. For negative integers, the last element - corresponds to the value `-1`. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - writable: boolean - Boolean indicating whether a returned ndarray should be writable. This - parameter only applies to ndarray constructors which support read-only - instances. - - Returns - ------- - out: ndarray - Output array view. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > x.shape - [ 2, 2 ] - > var y = {{alias}}( x, 1, 1, false, false ) - - > 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 9dfeaf3..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,164 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sliceDimensionFrom = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = 0; - - sliceDimensionFrom( empty( 'float64', sh, order ), 1, s, false, false ); // $ExpectType float64ndarray - sliceDimensionFrom( empty( 'float32', sh, order ), 1, s, false, false ); // $ExpectType float32ndarray - sliceDimensionFrom( empty( 'complex128', sh, order ), 1, s, false, false ); // $ExpectType complex128ndarray - sliceDimensionFrom( empty( 'complex64', sh, order ), 1, s, false, false ); // $ExpectType complex64ndarray - sliceDimensionFrom( empty( 'int32', sh, order ), 1, s, false, false ); // $ExpectType int32ndarray - sliceDimensionFrom( empty( 'int16', sh, order ), 1, s, false, false ); // $ExpectType int16ndarray - sliceDimensionFrom( empty( 'int8', sh, order ), 1, s, false, false ); // $ExpectType int8ndarray - sliceDimensionFrom( empty( 'uint32', sh, order ), 1, s, false, false ); // $ExpectType uint32ndarray - sliceDimensionFrom( empty( 'uint16', sh, order ), 1, s, false, false ); // $ExpectType uint16ndarray - sliceDimensionFrom( empty( 'uint8', sh, order ), 1, s, false, false ); // $ExpectType uint8ndarray - sliceDimensionFrom( empty( 'uint8c', sh, order ), 1, s, false, false ); // $ExpectType uint8cndarray - - sliceDimensionFrom( empty( 'float64', sh, order ), 1, s, true, true ); // $ExpectType float64ndarray - sliceDimensionFrom( empty( 'float32', sh, order ), 1, s, true, true ); // $ExpectType float32ndarray - sliceDimensionFrom( empty( 'complex128', sh, order ), 1, s, true, true ); // $ExpectType complex128ndarray - sliceDimensionFrom( empty( 'complex64', sh, order ), 1, s, true, true ); // $ExpectType complex64ndarray - sliceDimensionFrom( empty( 'int32', sh, order ), 1, s, true, true ); // $ExpectType int32ndarray - sliceDimensionFrom( empty( 'int16', sh, order ), 1, s, true, true ); // $ExpectType int16ndarray - sliceDimensionFrom( empty( 'int8', sh, order ), 1, s, true, true ); // $ExpectType int8ndarray - sliceDimensionFrom( empty( 'uint32', sh, order ), 1, s, true, true ); // $ExpectType uint32ndarray - sliceDimensionFrom( empty( 'uint16', sh, order ), 1, s, true, true ); // $ExpectType uint16ndarray - sliceDimensionFrom( empty( 'uint8', sh, order ), 1, s, true, true ); // $ExpectType uint8ndarray - sliceDimensionFrom( empty( 'uint8c', sh, order ), 1, s, true, true ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const s = 0; - - sliceDimensionFrom( '10', 1, s, false, false ); // $ExpectError - sliceDimensionFrom( 10, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( false, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( true, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( null, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( [], 1, s, false, false ); // $ExpectError - sliceDimensionFrom( {}, 1, s, false, false ); // $ExpectError - sliceDimensionFrom( ( x: number ): number => x, 1, s, false, false ); // $ExpectError - - sliceDimensionFrom( '10', 1, s, true, true ); // $ExpectError - sliceDimensionFrom( 10, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( false, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( true, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( null, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( [], 1, s, true, true ); // $ExpectError - sliceDimensionFrom( {}, 1, s, true, true ); // $ExpectError - sliceDimensionFrom( ( x: number ): number => x, 1, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a number... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 1; - - sliceDimensionFrom( x, '5', s, false, false ); // $ExpectError - sliceDimensionFrom( x, false, s, false, false ); // $ExpectError - sliceDimensionFrom( x, true, s, false, false ); // $ExpectError - sliceDimensionFrom( x, null, s, false, false ); // $ExpectError - sliceDimensionFrom( x, undefined, s, false, false ); // $ExpectError - sliceDimensionFrom( x, [ '5' ], s, false, false ); // $ExpectError - sliceDimensionFrom( x, {}, s, false, false ); // $ExpectError - sliceDimensionFrom( x, ( x: number ): number => x, s, false, false ); // $ExpectError - - sliceDimensionFrom( x, '5', s, true, true ); // $ExpectError - sliceDimensionFrom( x, false, s, true, true ); // $ExpectError - sliceDimensionFrom( x, true, s, true, true ); // $ExpectError - sliceDimensionFrom( x, null, s, true, true ); // $ExpectError - sliceDimensionFrom( x, undefined, s, true, true ); // $ExpectError - sliceDimensionFrom( x, [ '5' ], s, true, true ); // $ExpectError - sliceDimensionFrom( x, {}, s, true, true ); // $ExpectError - sliceDimensionFrom( x, ( x: number ): number => x, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceDimensionFrom( x, 1, '5', false, false ); // $ExpectError - sliceDimensionFrom( x, 1, false, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, true, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, null, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, undefined, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, [ '5' ], false, false ); // $ExpectError - sliceDimensionFrom( x, 1, {}, false, false ); // $ExpectError - sliceDimensionFrom( x, 1, ( x: number ): number => x, 1, false, false ); // $ExpectError - - sliceDimensionFrom( x, 1, '5', true, true ); // $ExpectError - sliceDimensionFrom( x, 1, false, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, true, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, null, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, undefined, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, [ '5' ], true, true ); // $ExpectError - sliceDimensionFrom( x, 1, {}, true, true ); // $ExpectError - sliceDimensionFrom( x, 1, ( x: number ): number => x, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x, 1, s, '5', false ); // $ExpectError - sliceDimensionFrom( x, 1, s, 5, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, null, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, undefined, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, [ '5' ], false ); // $ExpectError - sliceDimensionFrom( x, 1, s, {}, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x, 1, s, false, '5' ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, 5 ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, null ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, undefined ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, [ '5' ] ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, {} ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = 0; - - sliceDimensionFrom( x ); // $ExpectError - sliceDimensionFrom( x, 1 ); // $ExpectError - sliceDimensionFrom( x, 1, s ); // $ExpectError - sliceDimensionFrom( x, 1, s, false ); // $ExpectError - sliceDimensionFrom( x, 1, s, false, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index b17162a..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 sliceDimensionFrom = 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 = sliceDimensionFrom( x, 1, 1, false, false ); -// 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 columns of each matrix: -var y2 = sliceDimensionFrom( x, 2, 1, false, false ); -// returns - -var a2 = ndarray2array( y2 ); -console.log( a2 ); -// => [ [ [ 1, 2 ], [ 4, 5 ], [ 7, 8 ] ], [ [ 10, 11 ], [ 13, 14 ], [ 16, 17 ] ], [ [ 19, 20 ], [ 22, 23 ], [ 25, 26 ] ] ] - -// Get the last two matrices: -var y3 = sliceDimensionFrom( x, 0, 1, false, false ); -// returns - -var a3 = ndarray2array( y3 ); -console.log( a3 ); -// => [ [ [ 9, 10, 11 ], [ 12, 13, 14 ], [ 15, 16, 17 ] ], [ [ 18, 19, 20 ], [ 21, 22, 23 ], [ 24, 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 22f5594..49b5959 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..6f24d73 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.3-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-ctor@v0.2.3-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndims@v0.2.3-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.3-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-normalize-index@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-nulls@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";function m(m,l,o,j,a){var p,h,v;if(0===(h=r(m)))throw new TypeError(d("1lDF7",h));if(-1===(v=i(l,h-1)))throw new RangeError(d("1lDF8",h,l));return(p=n(h))[v]=new e(o,null),t(m,s(p),j,a)}export{m as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..425f555 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport Slice from '@stdlib/slice-ctor';\nimport ndims from '@stdlib/ndarray-base-ndims';\nimport slice from '@stdlib/ndarray-base-slice';\nimport normalizeIndex from '@stdlib/ndarray-base-normalize-index';\nimport nulls from '@stdlib/array-base-nulls';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns a shifted view of an input ndarray along a specified dimension.\n*\n* @param {ndarray} x - input array\n* @param {integer} dim - index of dimension to slice\n* @param {integer} start - starting index (inclusive)\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {TypeError} first argument must be an ndarray having one or more dimensions\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\n*\n* @example\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceDimensionFrom( x, 0, 1, false, false );\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 sliceDimensionFrom( x, dim, start, strict, writable ) {\n\tvar args;\n\tvar N;\n\tvar d;\n\n\t// Retrieve array meta data:\n\tN = ndims( x );\n\n\t// Check whether we were provided a zero-dimensional array...\n\tif ( N === 0 ) {\n\t\tthrow new TypeError( format( '1lDF7', N ) );\n\t}\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, N-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( '1lDF8', N, dim ) );\n\t}\n\t// Define a list of slice arguments:\n\targs = nulls( N );\n\targs[ d ] = new Slice( start, null );\n\n\t// Return a new array view:\n\treturn slice( x, args2multislice( args ), strict, writable );\n}\n\n\n// EXPORTS //\n\nexport default sliceDimensionFrom;\n"],"names":["sliceDimensionFrom","x","dim","start","strict","writable","args","N","d","ndims","TypeError","format","normalizeIndex","RangeError","nulls","Slice","slice","args2multislice"],"mappings":";;upBAyEA,SAASA,EAAoBC,EAAGC,EAAKC,EAAOC,EAAQC,GACnD,IAAIC,EACAC,EACAC,EAMJ,GAAW,KAHXD,EAAIE,EAAOR,IAIV,MAAM,IAAIS,UAAWC,EAAQ,QAASJ,IAIvC,IAAY,KADZC,EAAII,EAAgBV,EAAKK,EAAE,IAE1B,MAAM,IAAIM,WAAYF,EAAQ,QAASJ,EAAGL,IAO3C,OAJAI,EAAOQ,EAAOP,IACRC,GAAM,IAAIO,EAAOZ,EAAO,MAGvBa,EAAOf,EAAGgB,EAAiBX,GAAQF,EAAQC,EACnD"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index b3f97b2..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 shifted view of an input ndarray along a specified dimension. -* -* @module @stdlib/ndarray-base-slice-dimension-from -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var sliceDimensionFrom = require( '@stdlib/ndarray-base-slice-dimension-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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // 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 50e4c67..0000000 --- a/lib/main.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var Slice = require( '@stdlib/slice-ctor' ); -var ndims = require( '@stdlib/ndarray-base-ndims' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' ); -var nulls = require( '@stdlib/array-base-nulls' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns a shifted view of an input ndarray along a specified dimension. -* -* @param {ndarray} x - input array -* @param {integer} dim - index of dimension to slice -* @param {integer} start - starting index (inclusive) -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @param {boolean} writable - boolean indicating whether a returned array should be writable -* @throws {TypeError} first argument must be an ndarray having one or more dimensions -* @throws {RangeError} dimension index exceeds the number of dimensions -* @throws {RangeError} slice 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 = sliceDimensionFrom( x, 0, 1, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -function sliceDimensionFrom( x, dim, start, strict, writable ) { - var args; - var N; - var d; - - // Retrieve array meta data: - N = ndims( x ); - - // Check whether we were provided a zero-dimensional array... - if ( N === 0 ) { - throw new TypeError( format( '1lDF7', N ) ); - } - // Normalize the dimension index: - d = normalizeIndex( dim, N-1 ); - if ( d === -1 ) { - throw new RangeError( format( '1lDF8', N, dim ) ); - } - // Define a list of slice arguments: - args = nulls( N ); - args[ d ] = new Slice( start, null ); - - // Return a new array view: - return slice( x, args2multislice( args ), strict, writable ); -} - - -// EXPORTS // - -module.exports = sliceDimensionFrom; diff --git a/package.json b/package.json index c03740a..608cd81 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.4", "description": "Return a shifted view of an input ndarray along a specific dimension.", "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,50 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-nulls": "^0.1.1", - "@stdlib/ndarray-base-ndims": "^0.2.3", - "@stdlib/ndarray-base-normalize-index": "^0.2.3", - "@stdlib/ndarray-base-slice": "^0.2.3", - "@stdlib/slice-base-args2multislice": "^0.2.3", - "@stdlib/slice-ctor": "^0.2.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.2", - "@stdlib/array-typed": "^0.3.2", - "@stdlib/assert-is-ndarray-like": "^0.2.3", - "@stdlib/ndarray-array": "^0.2.3", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.3", - "@stdlib/ndarray-base-ctor": "^0.3.1", - "@stdlib/ndarray-base-empty": "^0.3.2", - "@stdlib/ndarray-base-numel": "^0.2.3", - "@stdlib/ndarray-ctor": "^0.3.1", - "@stdlib/ndarray-empty": "^0.3.1", - "@stdlib/ndarray-to-array": "^0.2.2", - "@stdlib/ndarray-zeros": "^0.3.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.3" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..4c2950c --- /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 dd19802..0000000 --- a/test/test.js +++ /dev/null @@ -1,621 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 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 ndarray2array = require( '@stdlib/ndarray-to-array' ); -var baseCtor = require( '@stdlib/ndarray-base-ctor' ); -var ctor = require( '@stdlib/ndarray-ctor' ); -var sliceDimensionFrom = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sliceDimensionFrom, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a zero-dimensional array (strict=false)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error' ); - } - t.end(); - - function badValue( x ) { - return function badValue() { - sliceDimensionFrom( x, 0, 0, false, false ); - }; - } -}); - -tape( 'the function throws an error if provided a zero-dimensional array (strict=true)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error' ); - } - t.end(); - - function badValue( x ) { - return function badValue() { - sliceDimensionFrom( x, 0, 0, true, false ); - }; - } -}); - -tape( 'the function throws an error if the dimension index exceeds the number of dimensions (strict=false)', 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 ], 10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - t.throws( badValue( values[ i ], -10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - } - t.end(); - - function badValue( x, dim ) { - return function badValue() { - sliceDimensionFrom( x, dim, 0, false, false ); - }; - } -}); - -tape( 'the function throws an error if the dimension index exceeds the number of dimensions (strict=true)', 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 ], 10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - t.throws( badValue( values[ i ], -10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); - } - t.end(); - - function badValue( x, dim ) { - return function badValue() { - sliceDimensionFrom( x, dim, 0, true, false ); - }; - } -}); - -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, - 20, - 20, - 20 - ]; - 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() { - sliceDimensionFrom( x, 0, s, true, false ); - }; - } -}); - -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; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - 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' } ) - ]; - - /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - start = [ - 10, - 20, - 20, - 20, - 10 - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceDimensionFrom( values[ i ], 0, start[ i ], false, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), 0, 'returns expected value' ); - t.strictEqual( actual.dtype, values[ i ].dtype, 'returns expected value' ); - } - t.end(); -}); - -tape( 'in non-strict mode, the function returns an empty array when a starting index is the one more than the last index along a dimension', function test( t ) { - var actual; - var values; - var start; - var dim; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - 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' } ) - ]; - - /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - dim = [ - 0, - 1, - 0, - 1, - 4 - ]; - - start = [ - 1, - 1, - 1, - 1, - 1 - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceDimensionFrom( values[ i ], dim[ i ], start[ i ], false, false ); // eslint-disable-line max-len - 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 a shifted view of a provided input array (ndims=1)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 2, true, false ); - - 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 = sliceDimensionFrom( x, 0, -4, true, false ); - - 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)', 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 1, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 2, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, -2, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 1, 1, true, false ); - - 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 = sliceDimensionFrom( x, 1, -2, true, false ); - - 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' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=3)', 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 = sliceDimensionFrom( x, 0, 0, true, false ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - 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 = sliceDimensionFrom( x, 0, 1, true, false ); - - 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 = sliceDimensionFrom( x, 1, 1, true, false ); - - 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 = sliceDimensionFrom( x, 2, 2, true, false ); - - 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 = sliceDimensionFrom( x, 2, -1, true, false ); - - 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' ); - t.end(); -}); - -tape( 'if a provided ndarray has a constructor supporting read-only instances, the function returns a read-only instance', function test( t ) { - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - x = new baseCtor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports returning writable views', function test( t ) { - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - x = new baseCtor( 'float64', buf, sh, st, o, ord ); - - actual = sliceDimensionFrom( x, 0, 0, true, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - t.end(); -});