From 2196beb1099d7d5595d459af2f28f7920eed1d15 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 3 May 2026 07:31:27 +0000 Subject: [PATCH 01/23] 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 e7e61be..0075a88 100644 --- a/lib/main.js +++ b/lib/main.js @@ -29,7 +29,7 @@ var getOrder = require( '@stdlib/ndarray-base-order' ); var getData = require( '@stdlib/ndarray-base-data-buffer' ); var join = require( '@stdlib/array-base-join' ); var min = require( '@stdlib/math-base-special-min' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // diff --git a/package.json b/package.json index 17c5403..27c91df 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/ndarray-base-shape": "^0.2.3", "@stdlib/ndarray-base-strides": "^0.2.3", "@stdlib/ndarray-base-to-unique-normalized-indices": "^0.1.1", - "@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 b99875fba82e3e5b41c8fefed82915d5a9d482dc Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 3 May 2026 07:32:32 +0000 Subject: [PATCH 02/23] Auto-generated commit --- .editorconfig | 189 - .eslintrc.js | 1 - .gitattributes | 68 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 821 --- .github/workflows/publish.yml | 261 - .github/workflows/test.yml | 101 - .github/workflows/test_bundles.yml | 213 - .github/workflows/test_coverage.yml | 142 - .github/workflows/test_install.yml | 94 - .github/workflows/test_published_package.yml | 115 - .gitignore | 204 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 49 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 41 +- SECURITY.md | 5 - benchmark/benchmark.js | 272 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 51 - docs/types/test.ts | 92 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 44 - lib/main.js | 144 - package.json | 77 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 619 --- 43 files changed, 4866 insertions(+), 4919 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 (96%) 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/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 5dacce3..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/diagonal) 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 bbaa7c7..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/diagonal) 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 52ddcc8..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: '7 19 * * 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 + + ```
@@ -197,7 +188,7 @@ console.log( ndarray2array( y ) ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. 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 3a0a3bc..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,272 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var diagonal = require( './../lib' ); - - -// MAIN // - -bench( format( '%s::ndims=2,ctor=base', pkg ), function benchmark( b ) { - var values; - var v; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = diagonal( values[ i%values.length ], [ 0, 1 ], 0, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::ndims=2,ctor=non-base', pkg ), function benchmark( b ) { - var values; - var v; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - values = [ - empty( [ 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = diagonal( values[ i%values.length ], [ 0, 1 ], 0, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::ndims=3,ctor=base', pkg ), function benchmark( b ) { - var values; - var v; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = diagonal( values[ i%values.length ], [ 1, 2 ], 0, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::ndims=3,ctor=non-base', pkg ), function benchmark( b ) { - var values; - var v; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - values = [ - empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = diagonal( values[ i%values.length ], [ 1, 2 ], 0, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::ndims=4,ctor=base', pkg ), function benchmark( b ) { - var values; - var v; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = diagonal( values[ i%values.length ], [ 2, 3 ], 0, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::ndims=4,ctor=non-base', pkg ), function benchmark( b ) { - var values; - var v; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - values = [ - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = diagonal( values[ i%values.length ], [ 2, 3 ], 0, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::ndims=5,ctor=base', pkg ), function benchmark( b ) { - var values; - var v; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = diagonal( values[ i%values.length ], [ 3, 4 ], 0, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::ndims=5,ctor=non-base', pkg ), function benchmark( b ) { - var values; - var v; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - values = [ - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = diagonal( values[ i%values.length ], [ 3, 4 ], 0, false ); - if ( typeof v !== '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 437ecb7..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/diagonal" -%% click B href "https://github.com/stdlib-js/ndarray-base-diagonal/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-diagonal/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-diagonal/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-diagonal/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-diagonal/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/diagonal -[production-url]: https://github.com/stdlib-js/ndarray-base-diagonal/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-diagonal/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-diagonal/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-diagonal/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-diagonal/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-diagonal/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-diagonal/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 a7ab3b4..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import diagonal from '../docs/types/index'; -export = diagonal; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 83ad7b8..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var M=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var y=M(function(T,b){ -var R=require('@stdlib/ndarray-base-to-unique-normalized-indices/dist'),S=require('@stdlib/ndarray-base-dtype/dist'),V=require('@stdlib/ndarray-base-shape/dist'),D=require('@stdlib/ndarray-base-strides/dist'),N=require('@stdlib/ndarray-base-offset/dist'),O=require('@stdlib/ndarray-base-order/dist'),j=require('@stdlib/ndarray-base-data-buffer/dist'),m=require('@stdlib/array-base-join/dist'),z=require('@stdlib/math-base-special-min/dist'),g=require('@stdlib/error-tools-fmtprodmsg/dist');function F(e,r,l,E){var o,f,a,s,p,w,t,v,h,c,q,d,i,u,n;if(r.length!==2)throw new RangeError(g("invalid argument. Must provide exactly two dimension indices. Value: `[%s]`.",m(r,", ")));if(t=V(e),a=t.length,a<2)throw new RangeError(g("invalid argument. First argument must be an ndarray having at least two dimensions. Number of dimensions: %d.",a));if(v=D(e),i=R(r,a-1),i===null)throw new RangeError(g('nullHO',a,a-1,m(r,", ")));if(i.length!==r.length)throw new Error(g('nullHP',m(r,", ")));for(h=v[i[0]],c=v[i[1]],d=l>0?l:0,q=d-l,p=t[i[0]]-q,w=t[i[1]]-d,u=z(p,w),u<0&&(u=0),f=N(e),u>0&&(f+=d*c+q*h),s=[],o=[],n=0;n 0`, the function returns the diagonal above the main diagonal; and when `k < 0`, the function returns the diagonal below the main diagonal.\n* - The returned ndarray is a **view** of the input ndarray. Accordingly, writing to the original ndarray will **mutate** the returned ndarray and vice versa.\n* - The `writable` parameter **only** applies to ndarray constructors supporting **read-only** instances.\n*\n* @param {ndarray} x - input array\n* @param {IntegerArray} dims - dimension indices defining the plane from which to extract the diagonal\n* @param {integer} k - diagonal offset\n* @param {boolean} writable - boolean indicating whether the returned ndarray should be writable\n* @throws {RangeError} must provide exactly two dimension indices\n* @throws {RangeError} input ndarray must have at least two dimensions\n* @throws {RangeError} must provide valid dimension indices\n* @throws {Error} must provide unique dimension indices\n* @returns {ndarray} ndarray view\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] );\n* // returns [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ]\n*\n* var y = diagonal( x, [ 0, 1 ], 0, false );\n* // returns [ 1.0, 5.0, 9.0 ]\n*/\nfunction diagonal( x, dims, k, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar ndims;\n\tvar shape;\n\tvar rows;\n\tvar cols;\n\tvar sh;\n\tvar st;\n\tvar sr;\n\tvar sc;\n\tvar ro;\n\tvar co;\n\tvar d;\n\tvar L;\n\tvar i;\n\n\tif ( dims.length !== 2 ) {\n\t\tthrow new RangeError( format( 'invalid argument. Must provide exactly two dimension indices. Value: `[%s]`.', join( dims, ', ' ) ) );\n\t}\n\tsh = getShape( x );\n\tndims = sh.length;\n\tif ( ndims < 2 ) {\n\t\tthrow new RangeError( format( 'invalid argument. First argument must be an ndarray having at least two dimensions. Number of dimensions: %d.', ndims ) );\n\t}\n\tst = getStrides( x );\n\n\t// Resolve dimension indices...\n\td = toUniqueNormalizedIndices( dims, ndims-1 );\n\tif ( d === null ) {\n\t\tthrow new RangeError( format( 'invalid argument. Specified dimension index is out-of-bounds. Must be on the interval: [-%u, %u]. Value: `[%s]`.', ndims, ndims-1, join( dims, ', ' ) ) );\n\t}\n\tif ( d.length !== dims.length ) {\n\t\tthrow new Error( format( 'invalid argument. Must provide unique dimension indices. Value: `[%s]`.', join( dims, ', ' ) ) );\n\t}\n\tsr = st[ d[0] ];\n\tsc = st[ d[1] ];\n\n\t// Resolve the row and column offsets corresponding to the diagonal offset `k = column - row`:\n\tco = ( k > 0 ) ? k : 0;\n\tro = co - k;\n\n\t// Compute the length of the diagonal:\n\trows = sh[ d[0] ] - ro;\n\tcols = sh[ d[1] ] - co;\n\tL = min( rows, cols );\n\tif ( L < 0 ) {\n\t\tL = 0;\n\t}\n\n\t// Adjust the offset so that we point to the first element along the specified diagonal:\n\toffset = getOffset( x );\n\tif ( L > 0 ) {\n\t\toffset += ( co*sc ) + ( ro*sr );\n\t}\n\n\t// Drop the specified dimensions and append the diagonal dimension:\n\tshape = [];\n\tstrides = [];\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tif ( i === d[0] || i === d[1] ) {\n\t\t\tcontinue;\n\t\t}\n\t\tshape.push( sh[ i ] );\n\t\tstrides.push( st[ i ] );\n\t}\n\tshape.push( L );\n\tstrides.push( sr + sc );\n\n\treturn new x.constructor( getDType( x ), getData( x ), shape, strides, offset, getOrder( x ), { // eslint-disable-line max-len\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nmodule.exports = diagonal;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Return a view of the diagonal of a matrix (or stack of matrices).\n*\n* @module @stdlib/ndarray-base-diagonal\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var diagonal = require( '@stdlib/ndarray-base-diagonal' );\n*\n* var x = array( [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] );\n* // returns [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ]\n*\n* var y = diagonal( x, [ 0, 1 ], 0, false );\n* // returns [ 1.0, 5.0, 9.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,EAA4B,QAAS,mDAAoD,EACzFC,EAAW,QAAS,4BAA6B,EACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAa,QAAS,8BAA+B,EACrDC,EAAY,QAAS,6BAA8B,EACnDC,EAAW,QAAS,4BAA6B,EACjDC,EAAU,QAAS,kCAAmC,EACtDC,EAAO,QAAS,yBAA0B,EAC1CC,EAAM,QAAS,+BAAgC,EAC/CC,EAAS,QAAS,uBAAwB,EAmC9C,SAASC,EAAUC,EAAGC,EAAMC,EAAGC,EAAW,CACzC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAKjB,EAAK,SAAW,EACpB,MAAM,IAAI,WAAYH,EAAQ,+EAAgFF,EAAMK,EAAM,IAAK,CAAE,CAAE,EAIpI,GAFAS,EAAKnB,EAAUS,CAAE,EACjBM,EAAQI,EAAG,OACNJ,EAAQ,EACZ,MAAM,IAAI,WAAYR,EAAQ,gHAAiHQ,CAAM,CAAE,EAMxJ,GAJAK,EAAKnB,EAAYQ,CAAE,EAGnBgB,EAAI3B,EAA2BY,EAAMK,EAAM,CAAE,EACxCU,IAAM,KACV,MAAM,IAAI,WAAYlB,EAAQ,mHAAoHQ,EAAOA,EAAM,EAAGV,EAAMK,EAAM,IAAK,CAAE,CAAE,EAExL,GAAKe,EAAE,SAAWf,EAAK,OACtB,MAAM,IAAI,MAAOH,EAAQ,0EAA2EF,EAAMK,EAAM,IAAK,CAAE,CAAE,EA0B1H,IAxBAW,EAAKD,EAAIK,EAAE,CAAC,CAAE,EACdH,EAAKF,EAAIK,EAAE,CAAC,CAAE,EAGdD,EAAOb,EAAI,EAAMA,EAAI,EACrBY,EAAKC,EAAKb,EAGVM,EAAOE,EAAIM,EAAE,CAAC,CAAE,EAAIF,EACpBL,EAAOC,EAAIM,EAAE,CAAC,CAAE,EAAID,EACpBE,EAAIpB,EAAKW,EAAMC,CAAK,EACfQ,EAAI,IACRA,EAAI,GAILZ,EAASZ,EAAWO,CAAE,EACjBiB,EAAI,IACRZ,GAAYU,EAAGF,EAASC,EAAGF,GAI5BL,EAAQ,CAAC,EACTH,EAAU,CAAC,EACLc,EAAI,EAAGA,EAAIZ,EAAOY,IAClBA,IAAMF,EAAE,CAAC,GAAKE,IAAMF,EAAE,CAAC,IAG5BT,EAAM,KAAMG,EAAIQ,CAAE,CAAE,EACpBd,EAAQ,KAAMO,EAAIO,CAAE,CAAE,GAEvB,OAAAX,EAAM,KAAMU,CAAE,EACdb,EAAQ,KAAMQ,EAAKC,CAAG,EAEf,IAAIb,EAAE,YAAaV,EAAUU,CAAE,EAAGL,EAASK,CAAE,EAAGO,EAAOH,EAASC,EAAQX,EAAUM,CAAE,EAAG,CAC7F,SAAY,CAACG,CACd,CAAC,CACF,CAKAf,EAAO,QAAUW,ICzGjB,IAAIoB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "toUniqueNormalizedIndices", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "getData", "join", "min", "format", "diagonal", "x", "dims", "k", "writable", "strides", "offset", "ndims", "shape", "rows", "cols", "sh", "st", "sr", "sc", "ro", "co", "d", "L", "i", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index da74ae9..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,51 +0,0 @@ - -{{alias}}( x, dims, k, writable ) - Returns a view of the diagonal of a matrix (or stack of matrices). - - The order of the dimension indices contained in `dims` matters. The first - element specifies the row-like dimension. The second element specifies - the column-like dimension. - - Each provided dimension index must reside on the interval [-ndims, ndims-1]. - - The diagonal offset `k` is interpreted as `column - row`. Accordingly, - when `k = 0`, the function returns the main diagonal; when `k > 0`, the - function returns the diagonal above the main diagonal; and when `k < 0`, - the function returns the diagonal below the main diagonal. - - The returned ndarray is a *view* of the input ndarray. Accordingly, - writing to the original ndarray will mutate the returned ndarray and - vice versa. - - The `writable` parameter only applies to ndarray constructors supporting - read-only instances. - - Parameters - ---------- - x: ndarray - Input array. - - dims: ArrayLikeObject - Dimension indices defining the plane from which to extract the diagonal. - - k: integer - Diagonal offset. - - writable: boolean - Boolean indicating whether the returned ndarray should be writable. - - Returns - ------- - out: ndarray - Output array view. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ) - [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] - > var y = {{alias}}( x, [ 0, 1 ], 0, false ) - [ 1.0, 4.0 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 513a253..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,92 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 zeros = require( '@stdlib/ndarray-zeros' ); -import diagonal = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - - diagonal( x, [ 0, 1 ], 0, false ); // $ExpectType float64ndarray -} - -// The compiler throws an error if the function is not provided a first argument which is an ndarray... -{ - diagonal( '5', [ 0, 1 ], 0, false ); // $ExpectError - diagonal( 5, [ 0, 1 ], 0, false ); // $ExpectError - diagonal( true, [ 0, 1 ], 0, false ); // $ExpectError - diagonal( false, [ 0, 1 ], 0, false ); // $ExpectError - diagonal( null, [ 0, 1 ], 0, false ); // $ExpectError - diagonal( {}, [ 0, 1 ], 0, false ); // $ExpectError - diagonal( [ '5' ], [ 0, 1 ], 0, false ); // $ExpectError - diagonal( ( x: number ): number => x, [ 0, 1 ], 0, false ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a second argument which is an array-like object containing numbers... -{ - const x = zeros( [ 2, 2 ] ); - - diagonal( x, '5', 0, false ); // $ExpectError - diagonal( x, 5, 0, false ); // $ExpectError - diagonal( x, true, 0, false ); // $ExpectError - diagonal( x, false, 0, false ); // $ExpectError - diagonal( x, null, 0, false ); // $ExpectError - diagonal( x, {}, 0, false ); // $ExpectError - diagonal( x, [ '5' ], 0, false ); // $ExpectError - diagonal( x, ( x: number ): number => x, 0, false ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a third argument which is a number... -{ - const x = zeros( [ 2, 2 ] ); - - diagonal( x, [ 0, 1 ], '5', false ); // $ExpectError - diagonal( x, [ 0, 1 ], true, false ); // $ExpectError - diagonal( x, [ 0, 1 ], false, false ); // $ExpectError - diagonal( x, [ 0, 1 ], null, false ); // $ExpectError - diagonal( x, [ 0, 1 ], {}, false ); // $ExpectError - diagonal( x, [ 0, 1 ], [], false ); // $ExpectError - diagonal( x, [ 0, 1 ], ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a fourth argument which is a boolean... -{ - const x = zeros( [ 2, 2 ] ); - - diagonal( x, [ 0, 1 ], 0, '5' ); // $ExpectError - diagonal( x, [ 0, 1 ], 0, 5 ); // $ExpectError - diagonal( x, [ 0, 1 ], 0, null ); // $ExpectError - diagonal( x, [ 0, 1 ], 0, {} ); // $ExpectError - diagonal( x, [ 0, 1 ], 0, [] ); // $ExpectError - diagonal( x, [ 0, 1 ], 0, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = zeros( [ 2, 2 ] ); - - diagonal(); // $ExpectError - diagonal( x ); // $ExpectError - diagonal( x, [ 0, 1 ] ); // $ExpectError - diagonal( x, [ 0, 1 ], 0 ); // $ExpectError - diagonal( x, [ 0, 1 ], 0, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 742dc69..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 uniform = require( '@stdlib/random-uniform' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var diagonal = require( './../lib' ); - -// Create a stack of matrices: -var x = uniform( [ 2, 3, 3 ], -10.0, 10.0, { - 'dtype': 'float64' -}); -console.log( ndarray2array( x ) ); - -// Extract the main diagonals from the stack: -var y = diagonal( x, [ 1, 2 ], 0, false ); -console.log( ndarray2array( y ) ); - -// Extract super-diagonals from the stack: -y = diagonal( x, [ 1, 2 ], 1, false ); -console.log( ndarray2array( y ) ); - -// Extract sub-diagonals from the stack: -y = diagonal( x, [ 1, 2 ], -1, false ); -console.log( ndarray2array( y ) ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index 5ab7709..9e71468 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/array'; import { typedndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..ce94273 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-to-unique-normalized-indices@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.3-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.3-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.3-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.3-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.3-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-join@v0.1.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-min@v0.2.4-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";function l(l,h,p,j){var u,v,f,b,g,c,x,y,w,E,M,R,V,q,z;if(2!==h.length)throw new RangeError(o("invalid argument. Must provide exactly two dimension indices. Value: `[%s]`.",a(h,", ")));if((f=(x=r(l)).length)<2)throw new RangeError(o("invalid argument. First argument must be an ndarray having at least two dimensions. Number of dimensions: %d.",f));if(y=t(l),null===(V=e(h,f-1)))throw new RangeError(o("invalid argument. Specified dimension index is out-of-bounds. Must be on the interval: [-%u, %u]. Value: `[%s]`.",f,f-1,a(h,", ")));if(V.length!==h.length)throw new Error(o("invalid argument. Must provide unique dimension indices. Value: `[%s]`.",a(h,", ")));for(w=y[V[0]],E=y[V[1]],M=(R=p>0?p:0)-p,g=x[V[0]]-M,c=x[V[1]]-R,(q=m(g,c))<0&&(q=0),v=n(l),q>0&&(v+=R*E+M*w),b=[],u=[],z=0;z 0`, the function returns the diagonal above the main diagonal; and when `k < 0`, the function returns the diagonal below the main diagonal.\n* - The returned ndarray is a **view** of the input ndarray. Accordingly, writing to the original ndarray will **mutate** the returned ndarray and vice versa.\n* - The `writable` parameter **only** applies to ndarray constructors supporting **read-only** instances.\n*\n* @param {ndarray} x - input array\n* @param {IntegerArray} dims - dimension indices defining the plane from which to extract the diagonal\n* @param {integer} k - diagonal offset\n* @param {boolean} writable - boolean indicating whether the returned ndarray should be writable\n* @throws {RangeError} must provide exactly two dimension indices\n* @throws {RangeError} input ndarray must have at least two dimensions\n* @throws {RangeError} must provide valid dimension indices\n* @throws {Error} must provide unique dimension indices\n* @returns {ndarray} ndarray view\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] );\n* // returns [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ]\n*\n* var y = diagonal( x, [ 0, 1 ], 0, false );\n* // returns [ 1.0, 5.0, 9.0 ]\n*/\nfunction diagonal( x, dims, k, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar ndims;\n\tvar shape;\n\tvar rows;\n\tvar cols;\n\tvar sh;\n\tvar st;\n\tvar sr;\n\tvar sc;\n\tvar ro;\n\tvar co;\n\tvar d;\n\tvar L;\n\tvar i;\n\n\tif ( dims.length !== 2 ) {\n\t\tthrow new RangeError( format( 'invalid argument. Must provide exactly two dimension indices. Value: `[%s]`.', join( dims, ', ' ) ) );\n\t}\n\tsh = getShape( x );\n\tndims = sh.length;\n\tif ( ndims < 2 ) {\n\t\tthrow new RangeError( format( 'invalid argument. First argument must be an ndarray having at least two dimensions. Number of dimensions: %d.', ndims ) );\n\t}\n\tst = getStrides( x );\n\n\t// Resolve dimension indices...\n\td = toUniqueNormalizedIndices( dims, ndims-1 );\n\tif ( d === null ) {\n\t\tthrow new RangeError( format( 'invalid argument. Specified dimension index is out-of-bounds. Must be on the interval: [-%u, %u]. Value: `[%s]`.', ndims, ndims-1, join( dims, ', ' ) ) );\n\t}\n\tif ( d.length !== dims.length ) {\n\t\tthrow new Error( format( 'invalid argument. Must provide unique dimension indices. Value: `[%s]`.', join( dims, ', ' ) ) );\n\t}\n\tsr = st[ d[0] ];\n\tsc = st[ d[1] ];\n\n\t// Resolve the row and column offsets corresponding to the diagonal offset `k = column - row`:\n\tco = ( k > 0 ) ? k : 0;\n\tro = co - k;\n\n\t// Compute the length of the diagonal:\n\trows = sh[ d[0] ] - ro;\n\tcols = sh[ d[1] ] - co;\n\tL = min( rows, cols );\n\tif ( L < 0 ) {\n\t\tL = 0;\n\t}\n\n\t// Adjust the offset so that we point to the first element along the specified diagonal:\n\toffset = getOffset( x );\n\tif ( L > 0 ) {\n\t\toffset += ( co*sc ) + ( ro*sr );\n\t}\n\n\t// Drop the specified dimensions and append the diagonal dimension:\n\tshape = [];\n\tstrides = [];\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tif ( i === d[0] || i === d[1] ) {\n\t\t\tcontinue;\n\t\t}\n\t\tshape.push( sh[ i ] );\n\t\tstrides.push( st[ i ] );\n\t}\n\tshape.push( L );\n\tstrides.push( sr + sc );\n\n\treturn new x.constructor( getDType( x ), getData( x ), shape, strides, offset, getOrder( x ), { // eslint-disable-line max-len\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default diagonal;\n"],"names":["diagonal","x","dims","k","writable","strides","offset","ndims","shape","rows","cols","sh","st","sr","sc","ro","co","d","L","i","length","RangeError","format","join","getShape","getStrides","toUniqueNormalizedIndices","Error","min","getOffset","push","constructor","getDType","getData","getOrder","readonly"],"mappings":";;s8BAkEA,SAASA,EAAUC,EAAGC,EAAMC,EAAGC,GAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAqB,IAAhBjB,EAAKkB,OACT,MAAM,IAAIC,WAAYC,EAAQ,+EAAgFC,EAAMrB,EAAM,QAI3H,IADAK,GADAI,EAAKa,EAAUvB,IACJmB,QACE,EACZ,MAAM,IAAIC,WAAYC,EAAQ,gHAAiHf,IAMhJ,GAJAK,EAAKa,EAAYxB,GAIN,QADXgB,EAAIS,EAA2BxB,EAAMK,EAAM,IAE1C,MAAM,IAAIc,WAAYC,EAAQ,mHAAoHf,EAAOA,EAAM,EAAGgB,EAAMrB,EAAM,QAE/K,GAAKe,EAAEG,SAAWlB,EAAKkB,OACtB,MAAM,IAAIO,MAAOL,EAAQ,0EAA2EC,EAAMrB,EAAM,QA0BjH,IAxBAW,EAAKD,EAAIK,EAAE,IACXH,EAAKF,EAAIK,EAAE,IAIXF,GADAC,EAAOb,EAAI,EAAMA,EAAI,GACXA,EAGVM,EAAOE,EAAIM,EAAE,IAAOF,EACpBL,EAAOC,EAAIM,EAAE,IAAOD,GACpBE,EAAIU,EAAKnB,EAAMC,IACN,IACRQ,EAAI,GAILZ,EAASuB,EAAW5B,GACfiB,EAAI,IACRZ,GAAYU,EAAGF,EAASC,EAAGF,GAI5BL,EAAQ,GACRH,EAAU,GACJc,EAAI,EAAGA,EAAIZ,EAAOY,IAClBA,IAAMF,EAAE,IAAME,IAAMF,EAAE,KAG3BT,EAAMsB,KAAMnB,EAAIQ,IAChBd,EAAQyB,KAAMlB,EAAIO,KAKnB,OAHAX,EAAMsB,KAAMZ,GACZb,EAAQyB,KAAMjB,EAAKC,GAEZ,IAAIb,EAAE8B,YAAaC,EAAU/B,GAAKgC,EAAShC,GAAKO,EAAOH,EAASC,EAAQ4B,EAAUjC,GAAK,CAC7FkC,UAAa/B,GAEf"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a541856..0000000 --- a/lib/index.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Return a view of the diagonal of a matrix (or stack of matrices). -* -* @module @stdlib/ndarray-base-diagonal -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var diagonal = require( '@stdlib/ndarray-base-diagonal' ); -* -* var x = array( [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] ); -* // returns [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] -* -* var y = diagonal( x, [ 0, 1 ], 0, false ); -* // returns [ 1.0, 5.0, 9.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 0075a88..0000000 --- a/lib/main.js +++ /dev/null @@ -1,144 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var toUniqueNormalizedIndices = require( '@stdlib/ndarray-base-to-unique-normalized-indices' ); -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); -var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var join = require( '@stdlib/array-base-join' ); -var min = require( '@stdlib/math-base-special-min' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns a view of the diagonal of a matrix (or stack of matrices). -* -* ## Notes -* -* - The order of the dimension indices contained in `dims` matters. The first element specifies the row-like dimension. The second element specifies the column-like dimension. -* - Each provided dimension index must reside on the interval `[-ndims, ndims-1]`. -* - The diagonal offset `k` is interpreted as `column - row`. Accordingly, when `k = 0`, the function returns the main diagonal; when `k > 0`, the function returns the diagonal above the main diagonal; and when `k < 0`, the function returns the diagonal below the main diagonal. -* - The returned ndarray is a **view** of the input ndarray. Accordingly, writing to the original ndarray will **mutate** the returned ndarray and vice versa. -* - The `writable` parameter **only** applies to ndarray constructors supporting **read-only** instances. -* -* @param {ndarray} x - input array -* @param {IntegerArray} dims - dimension indices defining the plane from which to extract the diagonal -* @param {integer} k - diagonal offset -* @param {boolean} writable - boolean indicating whether the returned ndarray should be writable -* @throws {RangeError} must provide exactly two dimension indices -* @throws {RangeError} input ndarray must have at least two dimensions -* @throws {RangeError} must provide valid dimension indices -* @throws {Error} must provide unique dimension indices -* @returns {ndarray} ndarray view -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] ); -* // returns [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] -* -* var y = diagonal( x, [ 0, 1 ], 0, false ); -* // returns [ 1.0, 5.0, 9.0 ] -*/ -function diagonal( x, dims, k, writable ) { - var strides; - var offset; - var ndims; - var shape; - var rows; - var cols; - var sh; - var st; - var sr; - var sc; - var ro; - var co; - var d; - var L; - var i; - - if ( dims.length !== 2 ) { - throw new RangeError( format( 'invalid argument. Must provide exactly two dimension indices. Value: `[%s]`.', join( dims, ', ' ) ) ); - } - sh = getShape( x ); - ndims = sh.length; - if ( ndims < 2 ) { - throw new RangeError( format( 'invalid argument. First argument must be an ndarray having at least two dimensions. Number of dimensions: %d.', ndims ) ); - } - st = getStrides( x ); - - // Resolve dimension indices... - d = toUniqueNormalizedIndices( dims, ndims-1 ); - if ( d === null ) { - throw new RangeError( format( 'invalid argument. Specified dimension index is out-of-bounds. Must be on the interval: [-%u, %u]. Value: `[%s]`.', ndims, ndims-1, join( dims, ', ' ) ) ); - } - if ( d.length !== dims.length ) { - throw new Error( format( 'invalid argument. Must provide unique dimension indices. Value: `[%s]`.', join( dims, ', ' ) ) ); - } - sr = st[ d[0] ]; - sc = st[ d[1] ]; - - // Resolve the row and column offsets corresponding to the diagonal offset `k = column - row`: - co = ( k > 0 ) ? k : 0; - ro = co - k; - - // Compute the length of the diagonal: - rows = sh[ d[0] ] - ro; - cols = sh[ d[1] ] - co; - L = min( rows, cols ); - if ( L < 0 ) { - L = 0; - } - - // Adjust the offset so that we point to the first element along the specified diagonal: - offset = getOffset( x ); - if ( L > 0 ) { - offset += ( co*sc ) + ( ro*sr ); - } - - // Drop the specified dimensions and append the diagonal dimension: - shape = []; - strides = []; - for ( i = 0; i < ndims; i++ ) { - if ( i === d[0] || i === d[1] ) { - continue; - } - shape.push( sh[ i ] ); - strides.push( st[ i ] ); - } - shape.push( L ); - strides.push( sr + sc ); - - return new x.constructor( getDType( x ), getData( x ), shape, strides, offset, getOrder( x ), { // eslint-disable-line max-len - 'readonly': !writable - }); -} - - -// EXPORTS // - -module.exports = diagonal; diff --git a/package.json b/package.json index 27c91df..1e256a2 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Return a view of the diagonal of a matrix (or stack of matrices).", "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,56 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-join": "^0.1.2", - "@stdlib/math-base-special-min": "^0.2.4", - "@stdlib/ndarray-base-data-buffer": "^0.2.3", - "@stdlib/ndarray-base-dtype": "^0.2.3", - "@stdlib/ndarray-base-offset": "^0.2.3", - "@stdlib/ndarray-base-order": "^0.2.3", - "@stdlib/ndarray-base-shape": "^0.2.3", - "@stdlib/ndarray-base-strides": "^0.2.3", - "@stdlib/ndarray-base-to-unique-normalized-indices": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.2.3", - "@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-data-buffer": "^0.2.3", - "@stdlib/ndarray-empty": "^0.3.1", - "@stdlib/ndarray-offset": "^0.2.3", - "@stdlib/ndarray-order": "^0.2.3", - "@stdlib/ndarray-shape": "^0.2.3", - "@stdlib/ndarray-stride": "^0.2.3", - "@stdlib/ndarray-strides": "^0.2.3", - "@stdlib/ndarray-to-array": "^0.2.2", - "@stdlib/random-uniform": "^0.1.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..c71bc8b --- /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 fabc8fa..0000000 --- a/test/test.js +++ /dev/null @@ -1,619 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var array = require( '@stdlib/ndarray-array' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var getStrides = require( '@stdlib/ndarray-strides' ); -var getStride = require( '@stdlib/ndarray-stride' ); -var getOffset = require( '@stdlib/ndarray-offset' ); -var getData = require( '@stdlib/ndarray-data-buffer' ); -var getOrder = require( '@stdlib/ndarray-order' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var diagonal = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof diagonal, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided exactly two dimension indices', function test( t ) { - var values; - var x; - var i; - - x = new ndarray( 'float64', new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); - - values = [ - [], - [ 0 ], - [ 0, 1, 0 ], - [ 0, 1, 0, 1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ].length + ' dimension indices' ); - } - t.end(); - - function badValue( dims ) { - return function badValue() { - diagonal( x, dims, 0, false ); - }; - } -}); - -tape( 'the function throws an error if provided an input ndarray with fewer than two dimensions', function test( t ) { - var values; - var i; - - values = [ - new ndarray( 'float64', new Float64Array( [ 5.0 ] ), [], [ 0 ], 0, 'row-major' ), - new ndarray( 'float64', new Float64Array( [ 1.0, 2.0, 3.0 ] ), [ 3 ], [ 1 ], 0, 'row-major' ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided an input ndarray with '+values[ i ].ndims+' dimensions' ); - } - t.end(); - - function badValue( x ) { - return function badValue() { - diagonal( x, [ 0, 1 ], 0, false ); - }; - } -}); - -tape( 'the function throws an error if provided out-of-bounds dimension indices', function test( t ) { - var values; - var x; - var i; - - x = new ndarray( 'float64', new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); - - values = [ - [ 0, 2 ], - [ 2, 0 ], - [ -3, 0 ], - [ 0, -3 ], - [ 10, 0 ], - [ 0, 10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided dimension indices ['+values[ i ]+']' ); - } - t.end(); - - function badValue( dims ) { - return function badValue() { - diagonal( x, dims, 0, false ); - }; - } -}); - -tape( 'the function throws an error if provided duplicate dimension indices', function test( t ) { - var values; - var x; - var i; - - x = new ndarray( 'float64', new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ), [ 2, 2, 2 ], [ 4, 2, 1 ], 0, 'row-major' ); - - values = [ - [ 0, 0 ], - [ 1, 1 ], - [ 2, 2 ], - [ 0, -3 ], - [ -2, 1 ], - [ -1, 2 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided dimension indices ['+values[ i ]+']' ); - } - t.end(); - - function badValue( dims ) { - return function badValue() { - diagonal( x, dims, 0, false ); - }; - } -}); - -tape( 'the function returns a view of the main diagonal of a square matrix', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); - - y = diagonal( x, [ 0, 1 ], 0, false ); - - expected = [ 3 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 1, 5, 9 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.strictEqual( getData( y ), getData( x ), 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of the super-diagonal of a square matrix', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); - - y = diagonal( x, [ 0, 1 ], 1, false ); - - expected = [ 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 2, 6 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], 2, false ); - - expected = [ 1 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 3 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of the sub-diagonal of a square matrix', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); - - y = diagonal( x, [ 0, 1 ], -1, false ); - - expected = [ 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 4, 8 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], -2, false ); - - expected = [ 1 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 7 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of the diagonal of a non-square matrix (M < N)', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ 1, 2, 3, 4 ], [ 5, 6, 7, 8 ] ] ); - - y = diagonal( x, [ 0, 1 ], 0, false ); - - expected = [ 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 1, 6 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], 2, false ); - - expected = [ 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 3, 8 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], -1, false ); - - expected = [ 1 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 5 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of the diagonal of a non-square matrix (M > N)', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ], [ 7, 8 ] ] ); - - y = diagonal( x, [ 0, 1 ], 0, false ); - - expected = [ 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 1, 4 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], -2, false ); - - expected = [ 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 5, 8 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], 1, false ); - - expected = [ 1 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 2 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an empty view when the diagonal offset is out-of-bounds', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); - - y = diagonal( x, [ 0, 1 ], 3, false ); - - expected = [ 0 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = []; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], -3, false ); - - expected = [ 0 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = []; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], 100, false ); - - expected = [ 0 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = []; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function swaps the row-like and column-like dimensions when `dims` is reversed', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); - - y = diagonal( x, [ 1, 0 ], 1, false ); - - expected = [ 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 4, 8 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 1, 0 ], -1, false ); - - expected = [ 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 2, 6 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of the diagonals of a stack of matrices', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); - - y = diagonal( x, [ 1, 2 ], 0, false ); - - expected = [ 2, 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ [ 1, 4 ], [ 5, 8 ] ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 1, 2 ], 1, false ); - - expected = [ 2, 1 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ [ 2 ], [ 6 ] ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 1, 2 ], -1, false ); - - expected = [ 2, 1 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ [ 3 ], [ 7 ] ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function appends the diagonal dimension as the trailing dimension of the output ndarray', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ [ 1, 2, 3 ], [ 4, 5, 6 ] ], [ [ 7, 8, 9 ], [ 10, 11, 12 ] ] ] ); - - y = diagonal( x, [ 0, 2 ], 0, false ); - - expected = [ 2, 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ [ 1, 8 ], [ 4, 11 ] ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function normalizes negative dimension indices', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); - - y = diagonal( x, [ -2, -1 ], 0, false ); - - expected = [ 3 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 1, 5, 9 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a column-major ndarray when the input ndarray is column-major', function test( t ) { - var expected; - var x; - var y; - - x = ndarray( 'generic', [ 1, 4, 7, 2, 5, 8, 3, 6, 9 ], [ 3, 3 ], [ 1, 3 ], 0, 'column-major' ); - - y = diagonal( x, [ 0, 1 ], 0, false ); - - expected = 'column-major'; - t.strictEqual( getOrder( y ), expected, 'returns expected value' ); - - expected = [ 3 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 1, 5, 9 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a writable ndarray when `writable` is `true`', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); - y = diagonal( x, [ 0, 1 ], 0, true ); - - t.strictEqual( isReadOnly( y ), false, 'returns expected value' ); - t.strictEqual( getData( y ), getData( x ), 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a read-only ndarray when `writable` is `false`', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); - y = diagonal( x, [ 0, 1 ], 0, false ); - - t.strictEqual( isReadOnly( y ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function constructs the output by retaining all dimensions except the specified dimensions and appending the diagonal dimension', function test( t ) { - var expected; - var x; - var y; - - x = array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ], { - 'shape': [ 3, 2, 2 ] - }); - - y = diagonal( x, [ 1, 2 ], 0, false ); - - expected = [ 3, 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 4, 3 ]; - t.deepEqual( getStrides( y ), expected, 'returns expected value' ); - - expected = getOffset( x ); - t.strictEqual( getOffset( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function adjusts the offset to point to the first element of the requested diagonal', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); - - y = diagonal( x, [ 0, 1 ], 1, false ); - - expected = getOffset( x ) + getStride( x, 1 ); - t.strictEqual( getOffset( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], -1, false ); - - expected = getOffset( x ) + getStride( x, 0 ); - t.strictEqual( getOffset( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports input ndarrays having a non-zero buffer offset', function test( t ) { - var expected; - var x; - var y; - - x = ndarray( 'generic', [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], [ 3, 3 ], [ 3, 1 ], 1, 'row-major' ); - - y = diagonal( x, [ 0, 1 ], 0, false ); - - expected = [ 3 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 1, 5, 9 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.strictEqual( getData( y ), getData( x ), 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], 1, false ); - - expected = [ 2, 6 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], -1, false ); - - expected = [ 4, 8 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports 4D inputs with non-trailing `dims`', function test( t ) { - var expected; - var arr; - var x; - var y; - - arr = [ - [ - [ - [ 0, 1 ], - [ 2, 3 ], - [ 4, 5 ] - ], - [ - [ 6, 7 ], - [ 8, 9 ], - [ 10, 11 ] - ], - [ - [ 12, 13 ], - [ 14, 15 ], - [ 16, 17 ] - ] - ], - [ - [ - [ 18, 19 ], - [ 20, 21 ], - [ 22, 23 ] - ], - [ - [ 24, 25 ], - [ 26, 27 ], - [ 28, 29 ] - ], - [ - [ 30, 31 ], - [ 32, 33 ], - [ 34, 35 ] - ] - ] - ]; - x = array( arr ); - y = diagonal( x, [ 1, 2 ], 0, false ); - expected = [ 2, 2, 3 ]; - - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ - [ - [ 0, 8, 16 ], - [ 1, 9, 17 ] - ], - [ - [ 18, 26, 34 ], - [ 19, 27, 35 ] - ] - ]; - - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - t.strictEqual( getData( y ), getData( x ), 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports negative dimension indices combined with a non-zero `k`', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); - y = diagonal( x, [ -2, -1 ], 1, false ); - - expected = [ 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 2, 6 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ -2, -1 ], -1, false ); - - expected = [ 4, 8 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); From ef59e5d72b0410ab53e73c4c2fec1708f2ce121c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 4 May 2026 21:11:38 +0000 Subject: [PATCH 03/23] 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 e7e61be..0075a88 100644 --- a/lib/main.js +++ b/lib/main.js @@ -29,7 +29,7 @@ var getOrder = require( '@stdlib/ndarray-base-order' ); var getData = require( '@stdlib/ndarray-base-data-buffer' ); var join = require( '@stdlib/array-base-join' ); var min = require( '@stdlib/math-base-special-min' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // diff --git a/package.json b/package.json index 17c5403..27c91df 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/ndarray-base-shape": "^0.2.3", "@stdlib/ndarray-base-strides": "^0.2.3", "@stdlib/ndarray-base-to-unique-normalized-indices": "^0.1.1", - "@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 71d74be955d58fcf238e2980d6db04b1d37032ad Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 4 May 2026 21:16:20 +0000 Subject: [PATCH 04/23] Remove files --- index.d.ts | 57 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4904 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 9e71468..0000000 --- a/index.d.ts +++ /dev/null @@ -1,57 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { Collection } from '@stdlib/types/array'; -import { typedndarray } from '@stdlib/types/ndarray'; - -/** -* Returns a view of the diagonal of a matrix (or stack of matrices). -* -* ## Notes -* -* - The order of the dimension indices contained in `dims` matters. The first element specifies the row-like dimension. The second element specifies the column-like dimension. -* - Each provided dimension index must reside on the interval `[-ndims, ndims-1]`. -* - The diagonal offset `k` is interpreted as `column - row`. Accordingly, when `k = 0`, the function returns the main diagonal; when `k > 0`, the function returns the diagonal above the main diagonal; and when `k < 0`, the function returns the diagonal below the main diagonal. -* - The returned ndarray is a **view** of the input ndarray. Accordingly, writing to the original ndarray will **mutate** the returned ndarray and vice versa. -* - The `writable` parameter **only** applies to ndarray constructors supporting **read-only** instances. -* -* @param x - input array -* @param dims - dimension indices defining the plane from which to extract the diagonal -* @param k - diagonal offset -* @param writable - boolean indicating whether the returned ndarray should be writable -* @returns ndarray view -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] ); -* // returns [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] -* -* var y = diagonal( x, [ 0, 1 ], 0, false ); -* // returns [ 1.0, 5.0, 9.0 ] -*/ -declare function diagonal = typedndarray>( x: U, dims: Collection, k: number, writable: boolean ): U; - - -// EXPORTS // - -export = diagonal; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index ce94273..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-to-unique-normalized-indices@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.3-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.3-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.3-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.3-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.3-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-join@v0.1.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-min@v0.2.4-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";function l(l,h,p,j){var u,v,f,b,g,c,x,y,w,E,M,R,V,q,z;if(2!==h.length)throw new RangeError(o("invalid argument. Must provide exactly two dimension indices. Value: `[%s]`.",a(h,", ")));if((f=(x=r(l)).length)<2)throw new RangeError(o("invalid argument. First argument must be an ndarray having at least two dimensions. Number of dimensions: %d.",f));if(y=t(l),null===(V=e(h,f-1)))throw new RangeError(o("invalid argument. Specified dimension index is out-of-bounds. Must be on the interval: [-%u, %u]. Value: `[%s]`.",f,f-1,a(h,", ")));if(V.length!==h.length)throw new Error(o("invalid argument. Must provide unique dimension indices. Value: `[%s]`.",a(h,", ")));for(w=y[V[0]],E=y[V[1]],M=(R=p>0?p:0)-p,g=x[V[0]]-M,c=x[V[1]]-R,(q=m(g,c))<0&&(q=0),v=n(l),q>0&&(v+=R*E+M*w),b=[],u=[],z=0;z 0`, the function returns the diagonal above the main diagonal; and when `k < 0`, the function returns the diagonal below the main diagonal.\n* - The returned ndarray is a **view** of the input ndarray. Accordingly, writing to the original ndarray will **mutate** the returned ndarray and vice versa.\n* - The `writable` parameter **only** applies to ndarray constructors supporting **read-only** instances.\n*\n* @param {ndarray} x - input array\n* @param {IntegerArray} dims - dimension indices defining the plane from which to extract the diagonal\n* @param {integer} k - diagonal offset\n* @param {boolean} writable - boolean indicating whether the returned ndarray should be writable\n* @throws {RangeError} must provide exactly two dimension indices\n* @throws {RangeError} input ndarray must have at least two dimensions\n* @throws {RangeError} must provide valid dimension indices\n* @throws {Error} must provide unique dimension indices\n* @returns {ndarray} ndarray view\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] );\n* // returns [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ]\n*\n* var y = diagonal( x, [ 0, 1 ], 0, false );\n* // returns [ 1.0, 5.0, 9.0 ]\n*/\nfunction diagonal( x, dims, k, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar ndims;\n\tvar shape;\n\tvar rows;\n\tvar cols;\n\tvar sh;\n\tvar st;\n\tvar sr;\n\tvar sc;\n\tvar ro;\n\tvar co;\n\tvar d;\n\tvar L;\n\tvar i;\n\n\tif ( dims.length !== 2 ) {\n\t\tthrow new RangeError( format( 'invalid argument. Must provide exactly two dimension indices. Value: `[%s]`.', join( dims, ', ' ) ) );\n\t}\n\tsh = getShape( x );\n\tndims = sh.length;\n\tif ( ndims < 2 ) {\n\t\tthrow new RangeError( format( 'invalid argument. First argument must be an ndarray having at least two dimensions. Number of dimensions: %d.', ndims ) );\n\t}\n\tst = getStrides( x );\n\n\t// Resolve dimension indices...\n\td = toUniqueNormalizedIndices( dims, ndims-1 );\n\tif ( d === null ) {\n\t\tthrow new RangeError( format( 'invalid argument. Specified dimension index is out-of-bounds. Must be on the interval: [-%u, %u]. Value: `[%s]`.', ndims, ndims-1, join( dims, ', ' ) ) );\n\t}\n\tif ( d.length !== dims.length ) {\n\t\tthrow new Error( format( 'invalid argument. Must provide unique dimension indices. Value: `[%s]`.', join( dims, ', ' ) ) );\n\t}\n\tsr = st[ d[0] ];\n\tsc = st[ d[1] ];\n\n\t// Resolve the row and column offsets corresponding to the diagonal offset `k = column - row`:\n\tco = ( k > 0 ) ? k : 0;\n\tro = co - k;\n\n\t// Compute the length of the diagonal:\n\trows = sh[ d[0] ] - ro;\n\tcols = sh[ d[1] ] - co;\n\tL = min( rows, cols );\n\tif ( L < 0 ) {\n\t\tL = 0;\n\t}\n\n\t// Adjust the offset so that we point to the first element along the specified diagonal:\n\toffset = getOffset( x );\n\tif ( L > 0 ) {\n\t\toffset += ( co*sc ) + ( ro*sr );\n\t}\n\n\t// Drop the specified dimensions and append the diagonal dimension:\n\tshape = [];\n\tstrides = [];\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tif ( i === d[0] || i === d[1] ) {\n\t\t\tcontinue;\n\t\t}\n\t\tshape.push( sh[ i ] );\n\t\tstrides.push( st[ i ] );\n\t}\n\tshape.push( L );\n\tstrides.push( sr + sc );\n\n\treturn new x.constructor( getDType( x ), getData( x ), shape, strides, offset, getOrder( x ), { // eslint-disable-line max-len\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default diagonal;\n"],"names":["diagonal","x","dims","k","writable","strides","offset","ndims","shape","rows","cols","sh","st","sr","sc","ro","co","d","L","i","length","RangeError","format","join","getShape","getStrides","toUniqueNormalizedIndices","Error","min","getOffset","push","constructor","getDType","getData","getOrder","readonly"],"mappings":";;s8BAkEA,SAASA,EAAUC,EAAGC,EAAMC,EAAGC,GAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAqB,IAAhBjB,EAAKkB,OACT,MAAM,IAAIC,WAAYC,EAAQ,+EAAgFC,EAAMrB,EAAM,QAI3H,IADAK,GADAI,EAAKa,EAAUvB,IACJmB,QACE,EACZ,MAAM,IAAIC,WAAYC,EAAQ,gHAAiHf,IAMhJ,GAJAK,EAAKa,EAAYxB,GAIN,QADXgB,EAAIS,EAA2BxB,EAAMK,EAAM,IAE1C,MAAM,IAAIc,WAAYC,EAAQ,mHAAoHf,EAAOA,EAAM,EAAGgB,EAAMrB,EAAM,QAE/K,GAAKe,EAAEG,SAAWlB,EAAKkB,OACtB,MAAM,IAAIO,MAAOL,EAAQ,0EAA2EC,EAAMrB,EAAM,QA0BjH,IAxBAW,EAAKD,EAAIK,EAAE,IACXH,EAAKF,EAAIK,EAAE,IAIXF,GADAC,EAAOb,EAAI,EAAMA,EAAI,GACXA,EAGVM,EAAOE,EAAIM,EAAE,IAAOF,EACpBL,EAAOC,EAAIM,EAAE,IAAOD,GACpBE,EAAIU,EAAKnB,EAAMC,IACN,IACRQ,EAAI,GAILZ,EAASuB,EAAW5B,GACfiB,EAAI,IACRZ,GAAYU,EAAGF,EAASC,EAAGF,GAI5BL,EAAQ,GACRH,EAAU,GACJc,EAAI,EAAGA,EAAIZ,EAAOY,IAClBA,IAAMF,EAAE,IAAME,IAAMF,EAAE,KAG3BT,EAAMsB,KAAMnB,EAAIQ,IAChBd,EAAQyB,KAAMlB,EAAIO,KAKnB,OAHAX,EAAMsB,KAAMZ,GACZb,EAAQyB,KAAMjB,EAAKC,GAEZ,IAAIb,EAAE8B,YAAaC,EAAU/B,GAAKgC,EAAShC,GAAKO,EAAOH,EAASC,EAAQ4B,EAAUjC,GAAK,CAC7FkC,UAAa/B,GAEf"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index c71bc8b..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From ba43b33b47c6ecbe1701d45a97d1f06eb2dbf497 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 4 May 2026 21:16:59 +0000 Subject: [PATCH 05/23] Auto-generated commit --- .editorconfig | 189 - .eslintrc.js | 1 - .gitattributes | 68 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 821 --- .github/workflows/publish.yml | 261 - .github/workflows/test.yml | 101 - .github/workflows/test_bundles.yml | 213 - .github/workflows/test_coverage.yml | 142 - .github/workflows/test_install.yml | 94 - .github/workflows/test_published_package.yml | 115 - .gitignore | 204 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 51 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 41 +- SECURITY.md | 5 - benchmark/benchmark.js | 272 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 51 - docs/types/test.ts | 92 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 44 - lib/main.js | 144 - package.json | 77 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 619 --- 43 files changed, 4866 insertions(+), 4921 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 (96%) 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/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 5dacce3..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/diagonal) 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 bbaa7c7..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/diagonal) 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 52ddcc8..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: '7 19 * * 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 + + ```
@@ -207,7 +198,7 @@ console.log( ndarray2array( y ) ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. 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 3a0a3bc..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,272 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var diagonal = require( './../lib' ); - - -// MAIN // - -bench( format( '%s::ndims=2,ctor=base', pkg ), function benchmark( b ) { - var values; - var v; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = diagonal( values[ i%values.length ], [ 0, 1 ], 0, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::ndims=2,ctor=non-base', pkg ), function benchmark( b ) { - var values; - var v; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - values = [ - empty( [ 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = diagonal( values[ i%values.length ], [ 0, 1 ], 0, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::ndims=3,ctor=base', pkg ), function benchmark( b ) { - var values; - var v; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = diagonal( values[ i%values.length ], [ 1, 2 ], 0, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::ndims=3,ctor=non-base', pkg ), function benchmark( b ) { - var values; - var v; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - values = [ - empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = diagonal( values[ i%values.length ], [ 1, 2 ], 0, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::ndims=4,ctor=base', pkg ), function benchmark( b ) { - var values; - var v; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = diagonal( values[ i%values.length ], [ 2, 3 ], 0, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::ndims=4,ctor=non-base', pkg ), function benchmark( b ) { - var values; - var v; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - values = [ - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = diagonal( values[ i%values.length ], [ 2, 3 ], 0, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::ndims=5,ctor=base', pkg ), function benchmark( b ) { - var values; - var v; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = diagonal( values[ i%values.length ], [ 3, 4 ], 0, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::ndims=5,ctor=non-base', pkg ), function benchmark( b ) { - var values; - var v; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - values = [ - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = diagonal( values[ i%values.length ], [ 3, 4 ], 0, false ); - if ( typeof v !== '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 437ecb7..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/diagonal" -%% click B href "https://github.com/stdlib-js/ndarray-base-diagonal/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-diagonal/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-diagonal/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-diagonal/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-diagonal/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/diagonal -[production-url]: https://github.com/stdlib-js/ndarray-base-diagonal/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-diagonal/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-diagonal/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-diagonal/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-diagonal/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-diagonal/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-diagonal/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 a7ab3b4..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import diagonal from '../docs/types/index'; -export = diagonal; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 83ad7b8..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var M=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var y=M(function(T,b){ -var R=require('@stdlib/ndarray-base-to-unique-normalized-indices/dist'),S=require('@stdlib/ndarray-base-dtype/dist'),V=require('@stdlib/ndarray-base-shape/dist'),D=require('@stdlib/ndarray-base-strides/dist'),N=require('@stdlib/ndarray-base-offset/dist'),O=require('@stdlib/ndarray-base-order/dist'),j=require('@stdlib/ndarray-base-data-buffer/dist'),m=require('@stdlib/array-base-join/dist'),z=require('@stdlib/math-base-special-min/dist'),g=require('@stdlib/error-tools-fmtprodmsg/dist');function F(e,r,l,E){var o,f,a,s,p,w,t,v,h,c,q,d,i,u,n;if(r.length!==2)throw new RangeError(g("invalid argument. Must provide exactly two dimension indices. Value: `[%s]`.",m(r,", ")));if(t=V(e),a=t.length,a<2)throw new RangeError(g("invalid argument. First argument must be an ndarray having at least two dimensions. Number of dimensions: %d.",a));if(v=D(e),i=R(r,a-1),i===null)throw new RangeError(g('nullHO',a,a-1,m(r,", ")));if(i.length!==r.length)throw new Error(g('nullHP',m(r,", ")));for(h=v[i[0]],c=v[i[1]],d=l>0?l:0,q=d-l,p=t[i[0]]-q,w=t[i[1]]-d,u=z(p,w),u<0&&(u=0),f=N(e),u>0&&(f+=d*c+q*h),s=[],o=[],n=0;n 0`, the function returns the diagonal above the main diagonal; and when `k < 0`, the function returns the diagonal below the main diagonal.\n* - The returned ndarray is a **view** of the input ndarray. Accordingly, writing to the original ndarray will **mutate** the returned ndarray and vice versa.\n* - The `writable` parameter **only** applies to ndarray constructors supporting **read-only** instances.\n*\n* @param {ndarray} x - input array\n* @param {IntegerArray} dims - dimension indices defining the plane from which to extract the diagonal\n* @param {integer} k - diagonal offset\n* @param {boolean} writable - boolean indicating whether the returned ndarray should be writable\n* @throws {RangeError} must provide exactly two dimension indices\n* @throws {RangeError} input ndarray must have at least two dimensions\n* @throws {RangeError} must provide valid dimension indices\n* @throws {Error} must provide unique dimension indices\n* @returns {ndarray} ndarray view\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] );\n* // returns [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ]\n*\n* var y = diagonal( x, [ 0, 1 ], 0, false );\n* // returns [ 1.0, 5.0, 9.0 ]\n*/\nfunction diagonal( x, dims, k, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar ndims;\n\tvar shape;\n\tvar rows;\n\tvar cols;\n\tvar sh;\n\tvar st;\n\tvar sr;\n\tvar sc;\n\tvar ro;\n\tvar co;\n\tvar d;\n\tvar L;\n\tvar i;\n\n\tif ( dims.length !== 2 ) {\n\t\tthrow new RangeError( format( 'invalid argument. Must provide exactly two dimension indices. Value: `[%s]`.', join( dims, ', ' ) ) );\n\t}\n\tsh = getShape( x );\n\tndims = sh.length;\n\tif ( ndims < 2 ) {\n\t\tthrow new RangeError( format( 'invalid argument. First argument must be an ndarray having at least two dimensions. Number of dimensions: %d.', ndims ) );\n\t}\n\tst = getStrides( x );\n\n\t// Resolve dimension indices...\n\td = toUniqueNormalizedIndices( dims, ndims-1 );\n\tif ( d === null ) {\n\t\tthrow new RangeError( format( 'invalid argument. Specified dimension index is out-of-bounds. Must be on the interval: [-%u, %u]. Value: `[%s]`.', ndims, ndims-1, join( dims, ', ' ) ) );\n\t}\n\tif ( d.length !== dims.length ) {\n\t\tthrow new Error( format( 'invalid argument. Must provide unique dimension indices. Value: `[%s]`.', join( dims, ', ' ) ) );\n\t}\n\tsr = st[ d[0] ];\n\tsc = st[ d[1] ];\n\n\t// Resolve the row and column offsets corresponding to the diagonal offset `k = column - row`:\n\tco = ( k > 0 ) ? k : 0;\n\tro = co - k;\n\n\t// Compute the length of the diagonal:\n\trows = sh[ d[0] ] - ro;\n\tcols = sh[ d[1] ] - co;\n\tL = min( rows, cols );\n\tif ( L < 0 ) {\n\t\tL = 0;\n\t}\n\n\t// Adjust the offset so that we point to the first element along the specified diagonal:\n\toffset = getOffset( x );\n\tif ( L > 0 ) {\n\t\toffset += ( co*sc ) + ( ro*sr );\n\t}\n\n\t// Drop the specified dimensions and append the diagonal dimension:\n\tshape = [];\n\tstrides = [];\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tif ( i === d[0] || i === d[1] ) {\n\t\t\tcontinue;\n\t\t}\n\t\tshape.push( sh[ i ] );\n\t\tstrides.push( st[ i ] );\n\t}\n\tshape.push( L );\n\tstrides.push( sr + sc );\n\n\treturn new x.constructor( getDType( x ), getData( x ), shape, strides, offset, getOrder( x ), { // eslint-disable-line max-len\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nmodule.exports = diagonal;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Return a view of the diagonal of a matrix (or stack of matrices).\n*\n* @module @stdlib/ndarray-base-diagonal\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var diagonal = require( '@stdlib/ndarray-base-diagonal' );\n*\n* var x = array( [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] );\n* // returns [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ]\n*\n* var y = diagonal( x, [ 0, 1 ], 0, false );\n* // returns [ 1.0, 5.0, 9.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,EAA4B,QAAS,mDAAoD,EACzFC,EAAW,QAAS,4BAA6B,EACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAa,QAAS,8BAA+B,EACrDC,EAAY,QAAS,6BAA8B,EACnDC,EAAW,QAAS,4BAA6B,EACjDC,EAAU,QAAS,kCAAmC,EACtDC,EAAO,QAAS,yBAA0B,EAC1CC,EAAM,QAAS,+BAAgC,EAC/CC,EAAS,QAAS,uBAAwB,EAmC9C,SAASC,EAAUC,EAAGC,EAAMC,EAAGC,EAAW,CACzC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAKjB,EAAK,SAAW,EACpB,MAAM,IAAI,WAAYH,EAAQ,+EAAgFF,EAAMK,EAAM,IAAK,CAAE,CAAE,EAIpI,GAFAS,EAAKnB,EAAUS,CAAE,EACjBM,EAAQI,EAAG,OACNJ,EAAQ,EACZ,MAAM,IAAI,WAAYR,EAAQ,gHAAiHQ,CAAM,CAAE,EAMxJ,GAJAK,EAAKnB,EAAYQ,CAAE,EAGnBgB,EAAI3B,EAA2BY,EAAMK,EAAM,CAAE,EACxCU,IAAM,KACV,MAAM,IAAI,WAAYlB,EAAQ,mHAAoHQ,EAAOA,EAAM,EAAGV,EAAMK,EAAM,IAAK,CAAE,CAAE,EAExL,GAAKe,EAAE,SAAWf,EAAK,OACtB,MAAM,IAAI,MAAOH,EAAQ,0EAA2EF,EAAMK,EAAM,IAAK,CAAE,CAAE,EA0B1H,IAxBAW,EAAKD,EAAIK,EAAE,CAAC,CAAE,EACdH,EAAKF,EAAIK,EAAE,CAAC,CAAE,EAGdD,EAAOb,EAAI,EAAMA,EAAI,EACrBY,EAAKC,EAAKb,EAGVM,EAAOE,EAAIM,EAAE,CAAC,CAAE,EAAIF,EACpBL,EAAOC,EAAIM,EAAE,CAAC,CAAE,EAAID,EACpBE,EAAIpB,EAAKW,EAAMC,CAAK,EACfQ,EAAI,IACRA,EAAI,GAILZ,EAASZ,EAAWO,CAAE,EACjBiB,EAAI,IACRZ,GAAYU,EAAGF,EAASC,EAAGF,GAI5BL,EAAQ,CAAC,EACTH,EAAU,CAAC,EACLc,EAAI,EAAGA,EAAIZ,EAAOY,IAClBA,IAAMF,EAAE,CAAC,GAAKE,IAAMF,EAAE,CAAC,IAG5BT,EAAM,KAAMG,EAAIQ,CAAE,CAAE,EACpBd,EAAQ,KAAMO,EAAIO,CAAE,CAAE,GAEvB,OAAAX,EAAM,KAAMU,CAAE,EACdb,EAAQ,KAAMQ,EAAKC,CAAG,EAEf,IAAIb,EAAE,YAAaV,EAAUU,CAAE,EAAGL,EAASK,CAAE,EAAGO,EAAOH,EAASC,EAAQX,EAAUM,CAAE,EAAG,CAC7F,SAAY,CAACG,CACd,CAAC,CACF,CAKAf,EAAO,QAAUW,ICzGjB,IAAIoB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "toUniqueNormalizedIndices", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "getData", "join", "min", "format", "diagonal", "x", "dims", "k", "writable", "strides", "offset", "ndims", "shape", "rows", "cols", "sh", "st", "sr", "sc", "ro", "co", "d", "L", "i", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index da74ae9..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,51 +0,0 @@ - -{{alias}}( x, dims, k, writable ) - Returns a view of the diagonal of a matrix (or stack of matrices). - - The order of the dimension indices contained in `dims` matters. The first - element specifies the row-like dimension. The second element specifies - the column-like dimension. - - Each provided dimension index must reside on the interval [-ndims, ndims-1]. - - The diagonal offset `k` is interpreted as `column - row`. Accordingly, - when `k = 0`, the function returns the main diagonal; when `k > 0`, the - function returns the diagonal above the main diagonal; and when `k < 0`, - the function returns the diagonal below the main diagonal. - - The returned ndarray is a *view* of the input ndarray. Accordingly, - writing to the original ndarray will mutate the returned ndarray and - vice versa. - - The `writable` parameter only applies to ndarray constructors supporting - read-only instances. - - Parameters - ---------- - x: ndarray - Input array. - - dims: ArrayLikeObject - Dimension indices defining the plane from which to extract the diagonal. - - k: integer - Diagonal offset. - - writable: boolean - Boolean indicating whether the returned ndarray should be writable. - - Returns - ------- - out: ndarray - Output array view. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ) - [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] - > var y = {{alias}}( x, [ 0, 1 ], 0, false ) - [ 1.0, 4.0 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 513a253..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,92 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 zeros = require( '@stdlib/ndarray-zeros' ); -import diagonal = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - - diagonal( x, [ 0, 1 ], 0, false ); // $ExpectType float64ndarray -} - -// The compiler throws an error if the function is not provided a first argument which is an ndarray... -{ - diagonal( '5', [ 0, 1 ], 0, false ); // $ExpectError - diagonal( 5, [ 0, 1 ], 0, false ); // $ExpectError - diagonal( true, [ 0, 1 ], 0, false ); // $ExpectError - diagonal( false, [ 0, 1 ], 0, false ); // $ExpectError - diagonal( null, [ 0, 1 ], 0, false ); // $ExpectError - diagonal( {}, [ 0, 1 ], 0, false ); // $ExpectError - diagonal( [ '5' ], [ 0, 1 ], 0, false ); // $ExpectError - diagonal( ( x: number ): number => x, [ 0, 1 ], 0, false ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a second argument which is an array-like object containing numbers... -{ - const x = zeros( [ 2, 2 ] ); - - diagonal( x, '5', 0, false ); // $ExpectError - diagonal( x, 5, 0, false ); // $ExpectError - diagonal( x, true, 0, false ); // $ExpectError - diagonal( x, false, 0, false ); // $ExpectError - diagonal( x, null, 0, false ); // $ExpectError - diagonal( x, {}, 0, false ); // $ExpectError - diagonal( x, [ '5' ], 0, false ); // $ExpectError - diagonal( x, ( x: number ): number => x, 0, false ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a third argument which is a number... -{ - const x = zeros( [ 2, 2 ] ); - - diagonal( x, [ 0, 1 ], '5', false ); // $ExpectError - diagonal( x, [ 0, 1 ], true, false ); // $ExpectError - diagonal( x, [ 0, 1 ], false, false ); // $ExpectError - diagonal( x, [ 0, 1 ], null, false ); // $ExpectError - diagonal( x, [ 0, 1 ], {}, false ); // $ExpectError - diagonal( x, [ 0, 1 ], [], false ); // $ExpectError - diagonal( x, [ 0, 1 ], ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a fourth argument which is a boolean... -{ - const x = zeros( [ 2, 2 ] ); - - diagonal( x, [ 0, 1 ], 0, '5' ); // $ExpectError - diagonal( x, [ 0, 1 ], 0, 5 ); // $ExpectError - diagonal( x, [ 0, 1 ], 0, null ); // $ExpectError - diagonal( x, [ 0, 1 ], 0, {} ); // $ExpectError - diagonal( x, [ 0, 1 ], 0, [] ); // $ExpectError - diagonal( x, [ 0, 1 ], 0, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = zeros( [ 2, 2 ] ); - - diagonal(); // $ExpectError - diagonal( x ); // $ExpectError - diagonal( x, [ 0, 1 ] ); // $ExpectError - diagonal( x, [ 0, 1 ], 0 ); // $ExpectError - diagonal( x, [ 0, 1 ], 0, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 742dc69..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 uniform = require( '@stdlib/random-uniform' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var diagonal = require( './../lib' ); - -// Create a stack of matrices: -var x = uniform( [ 2, 3, 3 ], -10.0, 10.0, { - 'dtype': 'float64' -}); -console.log( ndarray2array( x ) ); - -// Extract the main diagonals from the stack: -var y = diagonal( x, [ 1, 2 ], 0, false ); -console.log( ndarray2array( y ) ); - -// Extract super-diagonals from the stack: -y = diagonal( x, [ 1, 2 ], 1, false ); -console.log( ndarray2array( y ) ); - -// Extract sub-diagonals from the stack: -y = diagonal( x, [ 1, 2 ], -1, false ); -console.log( ndarray2array( y ) ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index 5ab7709..9e71468 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/array'; import { typedndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..ce94273 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-to-unique-normalized-indices@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.3-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.3-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.3-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.3-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.3-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-join@v0.1.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-min@v0.2.4-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";function l(l,h,p,j){var u,v,f,b,g,c,x,y,w,E,M,R,V,q,z;if(2!==h.length)throw new RangeError(o("invalid argument. Must provide exactly two dimension indices. Value: `[%s]`.",a(h,", ")));if((f=(x=r(l)).length)<2)throw new RangeError(o("invalid argument. First argument must be an ndarray having at least two dimensions. Number of dimensions: %d.",f));if(y=t(l),null===(V=e(h,f-1)))throw new RangeError(o("invalid argument. Specified dimension index is out-of-bounds. Must be on the interval: [-%u, %u]. Value: `[%s]`.",f,f-1,a(h,", ")));if(V.length!==h.length)throw new Error(o("invalid argument. Must provide unique dimension indices. Value: `[%s]`.",a(h,", ")));for(w=y[V[0]],E=y[V[1]],M=(R=p>0?p:0)-p,g=x[V[0]]-M,c=x[V[1]]-R,(q=m(g,c))<0&&(q=0),v=n(l),q>0&&(v+=R*E+M*w),b=[],u=[],z=0;z 0`, the function returns the diagonal above the main diagonal; and when `k < 0`, the function returns the diagonal below the main diagonal.\n* - The returned ndarray is a **view** of the input ndarray. Accordingly, writing to the original ndarray will **mutate** the returned ndarray and vice versa.\n* - The `writable` parameter **only** applies to ndarray constructors supporting **read-only** instances.\n*\n* @param {ndarray} x - input array\n* @param {IntegerArray} dims - dimension indices defining the plane from which to extract the diagonal\n* @param {integer} k - diagonal offset\n* @param {boolean} writable - boolean indicating whether the returned ndarray should be writable\n* @throws {RangeError} must provide exactly two dimension indices\n* @throws {RangeError} input ndarray must have at least two dimensions\n* @throws {RangeError} must provide valid dimension indices\n* @throws {Error} must provide unique dimension indices\n* @returns {ndarray} ndarray view\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] );\n* // returns [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ]\n*\n* var y = diagonal( x, [ 0, 1 ], 0, false );\n* // returns [ 1.0, 5.0, 9.0 ]\n*/\nfunction diagonal( x, dims, k, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar ndims;\n\tvar shape;\n\tvar rows;\n\tvar cols;\n\tvar sh;\n\tvar st;\n\tvar sr;\n\tvar sc;\n\tvar ro;\n\tvar co;\n\tvar d;\n\tvar L;\n\tvar i;\n\n\tif ( dims.length !== 2 ) {\n\t\tthrow new RangeError( format( 'invalid argument. Must provide exactly two dimension indices. Value: `[%s]`.', join( dims, ', ' ) ) );\n\t}\n\tsh = getShape( x );\n\tndims = sh.length;\n\tif ( ndims < 2 ) {\n\t\tthrow new RangeError( format( 'invalid argument. First argument must be an ndarray having at least two dimensions. Number of dimensions: %d.', ndims ) );\n\t}\n\tst = getStrides( x );\n\n\t// Resolve dimension indices...\n\td = toUniqueNormalizedIndices( dims, ndims-1 );\n\tif ( d === null ) {\n\t\tthrow new RangeError( format( 'invalid argument. Specified dimension index is out-of-bounds. Must be on the interval: [-%u, %u]. Value: `[%s]`.', ndims, ndims-1, join( dims, ', ' ) ) );\n\t}\n\tif ( d.length !== dims.length ) {\n\t\tthrow new Error( format( 'invalid argument. Must provide unique dimension indices. Value: `[%s]`.', join( dims, ', ' ) ) );\n\t}\n\tsr = st[ d[0] ];\n\tsc = st[ d[1] ];\n\n\t// Resolve the row and column offsets corresponding to the diagonal offset `k = column - row`:\n\tco = ( k > 0 ) ? k : 0;\n\tro = co - k;\n\n\t// Compute the length of the diagonal:\n\trows = sh[ d[0] ] - ro;\n\tcols = sh[ d[1] ] - co;\n\tL = min( rows, cols );\n\tif ( L < 0 ) {\n\t\tL = 0;\n\t}\n\n\t// Adjust the offset so that we point to the first element along the specified diagonal:\n\toffset = getOffset( x );\n\tif ( L > 0 ) {\n\t\toffset += ( co*sc ) + ( ro*sr );\n\t}\n\n\t// Drop the specified dimensions and append the diagonal dimension:\n\tshape = [];\n\tstrides = [];\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tif ( i === d[0] || i === d[1] ) {\n\t\t\tcontinue;\n\t\t}\n\t\tshape.push( sh[ i ] );\n\t\tstrides.push( st[ i ] );\n\t}\n\tshape.push( L );\n\tstrides.push( sr + sc );\n\n\treturn new x.constructor( getDType( x ), getData( x ), shape, strides, offset, getOrder( x ), { // eslint-disable-line max-len\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default diagonal;\n"],"names":["diagonal","x","dims","k","writable","strides","offset","ndims","shape","rows","cols","sh","st","sr","sc","ro","co","d","L","i","length","RangeError","format","join","getShape","getStrides","toUniqueNormalizedIndices","Error","min","getOffset","push","constructor","getDType","getData","getOrder","readonly"],"mappings":";;s8BAkEA,SAASA,EAAUC,EAAGC,EAAMC,EAAGC,GAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAqB,IAAhBjB,EAAKkB,OACT,MAAM,IAAIC,WAAYC,EAAQ,+EAAgFC,EAAMrB,EAAM,QAI3H,IADAK,GADAI,EAAKa,EAAUvB,IACJmB,QACE,EACZ,MAAM,IAAIC,WAAYC,EAAQ,gHAAiHf,IAMhJ,GAJAK,EAAKa,EAAYxB,GAIN,QADXgB,EAAIS,EAA2BxB,EAAMK,EAAM,IAE1C,MAAM,IAAIc,WAAYC,EAAQ,mHAAoHf,EAAOA,EAAM,EAAGgB,EAAMrB,EAAM,QAE/K,GAAKe,EAAEG,SAAWlB,EAAKkB,OACtB,MAAM,IAAIO,MAAOL,EAAQ,0EAA2EC,EAAMrB,EAAM,QA0BjH,IAxBAW,EAAKD,EAAIK,EAAE,IACXH,EAAKF,EAAIK,EAAE,IAIXF,GADAC,EAAOb,EAAI,EAAMA,EAAI,GACXA,EAGVM,EAAOE,EAAIM,EAAE,IAAOF,EACpBL,EAAOC,EAAIM,EAAE,IAAOD,GACpBE,EAAIU,EAAKnB,EAAMC,IACN,IACRQ,EAAI,GAILZ,EAASuB,EAAW5B,GACfiB,EAAI,IACRZ,GAAYU,EAAGF,EAASC,EAAGF,GAI5BL,EAAQ,GACRH,EAAU,GACJc,EAAI,EAAGA,EAAIZ,EAAOY,IAClBA,IAAMF,EAAE,IAAME,IAAMF,EAAE,KAG3BT,EAAMsB,KAAMnB,EAAIQ,IAChBd,EAAQyB,KAAMlB,EAAIO,KAKnB,OAHAX,EAAMsB,KAAMZ,GACZb,EAAQyB,KAAMjB,EAAKC,GAEZ,IAAIb,EAAE8B,YAAaC,EAAU/B,GAAKgC,EAAShC,GAAKO,EAAOH,EAASC,EAAQ4B,EAAUjC,GAAK,CAC7FkC,UAAa/B,GAEf"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a541856..0000000 --- a/lib/index.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Return a view of the diagonal of a matrix (or stack of matrices). -* -* @module @stdlib/ndarray-base-diagonal -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var diagonal = require( '@stdlib/ndarray-base-diagonal' ); -* -* var x = array( [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] ); -* // returns [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] -* -* var y = diagonal( x, [ 0, 1 ], 0, false ); -* // returns [ 1.0, 5.0, 9.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 0075a88..0000000 --- a/lib/main.js +++ /dev/null @@ -1,144 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var toUniqueNormalizedIndices = require( '@stdlib/ndarray-base-to-unique-normalized-indices' ); -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); -var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var join = require( '@stdlib/array-base-join' ); -var min = require( '@stdlib/math-base-special-min' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns a view of the diagonal of a matrix (or stack of matrices). -* -* ## Notes -* -* - The order of the dimension indices contained in `dims` matters. The first element specifies the row-like dimension. The second element specifies the column-like dimension. -* - Each provided dimension index must reside on the interval `[-ndims, ndims-1]`. -* - The diagonal offset `k` is interpreted as `column - row`. Accordingly, when `k = 0`, the function returns the main diagonal; when `k > 0`, the function returns the diagonal above the main diagonal; and when `k < 0`, the function returns the diagonal below the main diagonal. -* - The returned ndarray is a **view** of the input ndarray. Accordingly, writing to the original ndarray will **mutate** the returned ndarray and vice versa. -* - The `writable` parameter **only** applies to ndarray constructors supporting **read-only** instances. -* -* @param {ndarray} x - input array -* @param {IntegerArray} dims - dimension indices defining the plane from which to extract the diagonal -* @param {integer} k - diagonal offset -* @param {boolean} writable - boolean indicating whether the returned ndarray should be writable -* @throws {RangeError} must provide exactly two dimension indices -* @throws {RangeError} input ndarray must have at least two dimensions -* @throws {RangeError} must provide valid dimension indices -* @throws {Error} must provide unique dimension indices -* @returns {ndarray} ndarray view -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] ); -* // returns [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] -* -* var y = diagonal( x, [ 0, 1 ], 0, false ); -* // returns [ 1.0, 5.0, 9.0 ] -*/ -function diagonal( x, dims, k, writable ) { - var strides; - var offset; - var ndims; - var shape; - var rows; - var cols; - var sh; - var st; - var sr; - var sc; - var ro; - var co; - var d; - var L; - var i; - - if ( dims.length !== 2 ) { - throw new RangeError( format( 'invalid argument. Must provide exactly two dimension indices. Value: `[%s]`.', join( dims, ', ' ) ) ); - } - sh = getShape( x ); - ndims = sh.length; - if ( ndims < 2 ) { - throw new RangeError( format( 'invalid argument. First argument must be an ndarray having at least two dimensions. Number of dimensions: %d.', ndims ) ); - } - st = getStrides( x ); - - // Resolve dimension indices... - d = toUniqueNormalizedIndices( dims, ndims-1 ); - if ( d === null ) { - throw new RangeError( format( 'invalid argument. Specified dimension index is out-of-bounds. Must be on the interval: [-%u, %u]. Value: `[%s]`.', ndims, ndims-1, join( dims, ', ' ) ) ); - } - if ( d.length !== dims.length ) { - throw new Error( format( 'invalid argument. Must provide unique dimension indices. Value: `[%s]`.', join( dims, ', ' ) ) ); - } - sr = st[ d[0] ]; - sc = st[ d[1] ]; - - // Resolve the row and column offsets corresponding to the diagonal offset `k = column - row`: - co = ( k > 0 ) ? k : 0; - ro = co - k; - - // Compute the length of the diagonal: - rows = sh[ d[0] ] - ro; - cols = sh[ d[1] ] - co; - L = min( rows, cols ); - if ( L < 0 ) { - L = 0; - } - - // Adjust the offset so that we point to the first element along the specified diagonal: - offset = getOffset( x ); - if ( L > 0 ) { - offset += ( co*sc ) + ( ro*sr ); - } - - // Drop the specified dimensions and append the diagonal dimension: - shape = []; - strides = []; - for ( i = 0; i < ndims; i++ ) { - if ( i === d[0] || i === d[1] ) { - continue; - } - shape.push( sh[ i ] ); - strides.push( st[ i ] ); - } - shape.push( L ); - strides.push( sr + sc ); - - return new x.constructor( getDType( x ), getData( x ), shape, strides, offset, getOrder( x ), { // eslint-disable-line max-len - 'readonly': !writable - }); -} - - -// EXPORTS // - -module.exports = diagonal; diff --git a/package.json b/package.json index 27c91df..1e256a2 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Return a view of the diagonal of a matrix (or stack of matrices).", "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,56 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-join": "^0.1.2", - "@stdlib/math-base-special-min": "^0.2.4", - "@stdlib/ndarray-base-data-buffer": "^0.2.3", - "@stdlib/ndarray-base-dtype": "^0.2.3", - "@stdlib/ndarray-base-offset": "^0.2.3", - "@stdlib/ndarray-base-order": "^0.2.3", - "@stdlib/ndarray-base-shape": "^0.2.3", - "@stdlib/ndarray-base-strides": "^0.2.3", - "@stdlib/ndarray-base-to-unique-normalized-indices": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.2.3", - "@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-data-buffer": "^0.2.3", - "@stdlib/ndarray-empty": "^0.3.1", - "@stdlib/ndarray-offset": "^0.2.3", - "@stdlib/ndarray-order": "^0.2.3", - "@stdlib/ndarray-shape": "^0.2.3", - "@stdlib/ndarray-stride": "^0.2.3", - "@stdlib/ndarray-strides": "^0.2.3", - "@stdlib/ndarray-to-array": "^0.2.2", - "@stdlib/random-uniform": "^0.1.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..c71bc8b --- /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 fabc8fa..0000000 --- a/test/test.js +++ /dev/null @@ -1,619 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var array = require( '@stdlib/ndarray-array' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var getStrides = require( '@stdlib/ndarray-strides' ); -var getStride = require( '@stdlib/ndarray-stride' ); -var getOffset = require( '@stdlib/ndarray-offset' ); -var getData = require( '@stdlib/ndarray-data-buffer' ); -var getOrder = require( '@stdlib/ndarray-order' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var diagonal = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof diagonal, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided exactly two dimension indices', function test( t ) { - var values; - var x; - var i; - - x = new ndarray( 'float64', new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); - - values = [ - [], - [ 0 ], - [ 0, 1, 0 ], - [ 0, 1, 0, 1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ].length + ' dimension indices' ); - } - t.end(); - - function badValue( dims ) { - return function badValue() { - diagonal( x, dims, 0, false ); - }; - } -}); - -tape( 'the function throws an error if provided an input ndarray with fewer than two dimensions', function test( t ) { - var values; - var i; - - values = [ - new ndarray( 'float64', new Float64Array( [ 5.0 ] ), [], [ 0 ], 0, 'row-major' ), - new ndarray( 'float64', new Float64Array( [ 1.0, 2.0, 3.0 ] ), [ 3 ], [ 1 ], 0, 'row-major' ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided an input ndarray with '+values[ i ].ndims+' dimensions' ); - } - t.end(); - - function badValue( x ) { - return function badValue() { - diagonal( x, [ 0, 1 ], 0, false ); - }; - } -}); - -tape( 'the function throws an error if provided out-of-bounds dimension indices', function test( t ) { - var values; - var x; - var i; - - x = new ndarray( 'float64', new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); - - values = [ - [ 0, 2 ], - [ 2, 0 ], - [ -3, 0 ], - [ 0, -3 ], - [ 10, 0 ], - [ 0, 10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided dimension indices ['+values[ i ]+']' ); - } - t.end(); - - function badValue( dims ) { - return function badValue() { - diagonal( x, dims, 0, false ); - }; - } -}); - -tape( 'the function throws an error if provided duplicate dimension indices', function test( t ) { - var values; - var x; - var i; - - x = new ndarray( 'float64', new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ), [ 2, 2, 2 ], [ 4, 2, 1 ], 0, 'row-major' ); - - values = [ - [ 0, 0 ], - [ 1, 1 ], - [ 2, 2 ], - [ 0, -3 ], - [ -2, 1 ], - [ -1, 2 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided dimension indices ['+values[ i ]+']' ); - } - t.end(); - - function badValue( dims ) { - return function badValue() { - diagonal( x, dims, 0, false ); - }; - } -}); - -tape( 'the function returns a view of the main diagonal of a square matrix', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); - - y = diagonal( x, [ 0, 1 ], 0, false ); - - expected = [ 3 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 1, 5, 9 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.strictEqual( getData( y ), getData( x ), 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of the super-diagonal of a square matrix', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); - - y = diagonal( x, [ 0, 1 ], 1, false ); - - expected = [ 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 2, 6 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], 2, false ); - - expected = [ 1 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 3 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of the sub-diagonal of a square matrix', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); - - y = diagonal( x, [ 0, 1 ], -1, false ); - - expected = [ 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 4, 8 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], -2, false ); - - expected = [ 1 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 7 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of the diagonal of a non-square matrix (M < N)', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ 1, 2, 3, 4 ], [ 5, 6, 7, 8 ] ] ); - - y = diagonal( x, [ 0, 1 ], 0, false ); - - expected = [ 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 1, 6 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], 2, false ); - - expected = [ 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 3, 8 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], -1, false ); - - expected = [ 1 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 5 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of the diagonal of a non-square matrix (M > N)', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ], [ 7, 8 ] ] ); - - y = diagonal( x, [ 0, 1 ], 0, false ); - - expected = [ 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 1, 4 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], -2, false ); - - expected = [ 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 5, 8 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], 1, false ); - - expected = [ 1 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 2 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an empty view when the diagonal offset is out-of-bounds', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); - - y = diagonal( x, [ 0, 1 ], 3, false ); - - expected = [ 0 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = []; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], -3, false ); - - expected = [ 0 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = []; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], 100, false ); - - expected = [ 0 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = []; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function swaps the row-like and column-like dimensions when `dims` is reversed', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); - - y = diagonal( x, [ 1, 0 ], 1, false ); - - expected = [ 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 4, 8 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 1, 0 ], -1, false ); - - expected = [ 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 2, 6 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of the diagonals of a stack of matrices', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); - - y = diagonal( x, [ 1, 2 ], 0, false ); - - expected = [ 2, 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ [ 1, 4 ], [ 5, 8 ] ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 1, 2 ], 1, false ); - - expected = [ 2, 1 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ [ 2 ], [ 6 ] ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 1, 2 ], -1, false ); - - expected = [ 2, 1 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ [ 3 ], [ 7 ] ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function appends the diagonal dimension as the trailing dimension of the output ndarray', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ [ 1, 2, 3 ], [ 4, 5, 6 ] ], [ [ 7, 8, 9 ], [ 10, 11, 12 ] ] ] ); - - y = diagonal( x, [ 0, 2 ], 0, false ); - - expected = [ 2, 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ [ 1, 8 ], [ 4, 11 ] ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function normalizes negative dimension indices', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); - - y = diagonal( x, [ -2, -1 ], 0, false ); - - expected = [ 3 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 1, 5, 9 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a column-major ndarray when the input ndarray is column-major', function test( t ) { - var expected; - var x; - var y; - - x = ndarray( 'generic', [ 1, 4, 7, 2, 5, 8, 3, 6, 9 ], [ 3, 3 ], [ 1, 3 ], 0, 'column-major' ); - - y = diagonal( x, [ 0, 1 ], 0, false ); - - expected = 'column-major'; - t.strictEqual( getOrder( y ), expected, 'returns expected value' ); - - expected = [ 3 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 1, 5, 9 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a writable ndarray when `writable` is `true`', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); - y = diagonal( x, [ 0, 1 ], 0, true ); - - t.strictEqual( isReadOnly( y ), false, 'returns expected value' ); - t.strictEqual( getData( y ), getData( x ), 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a read-only ndarray when `writable` is `false`', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); - y = diagonal( x, [ 0, 1 ], 0, false ); - - t.strictEqual( isReadOnly( y ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function constructs the output by retaining all dimensions except the specified dimensions and appending the diagonal dimension', function test( t ) { - var expected; - var x; - var y; - - x = array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ], { - 'shape': [ 3, 2, 2 ] - }); - - y = diagonal( x, [ 1, 2 ], 0, false ); - - expected = [ 3, 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 4, 3 ]; - t.deepEqual( getStrides( y ), expected, 'returns expected value' ); - - expected = getOffset( x ); - t.strictEqual( getOffset( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function adjusts the offset to point to the first element of the requested diagonal', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); - - y = diagonal( x, [ 0, 1 ], 1, false ); - - expected = getOffset( x ) + getStride( x, 1 ); - t.strictEqual( getOffset( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], -1, false ); - - expected = getOffset( x ) + getStride( x, 0 ); - t.strictEqual( getOffset( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports input ndarrays having a non-zero buffer offset', function test( t ) { - var expected; - var x; - var y; - - x = ndarray( 'generic', [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], [ 3, 3 ], [ 3, 1 ], 1, 'row-major' ); - - y = diagonal( x, [ 0, 1 ], 0, false ); - - expected = [ 3 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 1, 5, 9 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.strictEqual( getData( y ), getData( x ), 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], 1, false ); - - expected = [ 2, 6 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], -1, false ); - - expected = [ 4, 8 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports 4D inputs with non-trailing `dims`', function test( t ) { - var expected; - var arr; - var x; - var y; - - arr = [ - [ - [ - [ 0, 1 ], - [ 2, 3 ], - [ 4, 5 ] - ], - [ - [ 6, 7 ], - [ 8, 9 ], - [ 10, 11 ] - ], - [ - [ 12, 13 ], - [ 14, 15 ], - [ 16, 17 ] - ] - ], - [ - [ - [ 18, 19 ], - [ 20, 21 ], - [ 22, 23 ] - ], - [ - [ 24, 25 ], - [ 26, 27 ], - [ 28, 29 ] - ], - [ - [ 30, 31 ], - [ 32, 33 ], - [ 34, 35 ] - ] - ] - ]; - x = array( arr ); - y = diagonal( x, [ 1, 2 ], 0, false ); - expected = [ 2, 2, 3 ]; - - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ - [ - [ 0, 8, 16 ], - [ 1, 9, 17 ] - ], - [ - [ 18, 26, 34 ], - [ 19, 27, 35 ] - ] - ]; - - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - t.strictEqual( getData( y ), getData( x ), 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports negative dimension indices combined with a non-zero `k`', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); - y = diagonal( x, [ -2, -1 ], 1, false ); - - expected = [ 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 2, 6 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ -2, -1 ], -1, false ); - - expected = [ 4, 8 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); From be16fc0c10f8c68c36af01465bcdfb40d61876b4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 11 May 2026 21:02:19 +0000 Subject: [PATCH 06/23] 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 a3666a6..acf301d 100644 --- a/lib/main.js +++ b/lib/main.js @@ -29,7 +29,7 @@ var getOrder = require( '@stdlib/ndarray-base-order' ); var getData = require( '@stdlib/ndarray-base-data-buffer' ); var join = require( '@stdlib/array-base-join' ); var min = require( '@stdlib/math-base-special-min' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // diff --git a/package.json b/package.json index 17c5403..27c91df 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/ndarray-base-shape": "^0.2.3", "@stdlib/ndarray-base-strides": "^0.2.3", "@stdlib/ndarray-base-to-unique-normalized-indices": "^0.1.1", - "@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 60bc89b2fc05b8308a27d4b868b3f8e12c152249 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 11 May 2026 21:02:57 +0000 Subject: [PATCH 07/23] Remove files --- index.d.ts | 57 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4904 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 9e71468..0000000 --- a/index.d.ts +++ /dev/null @@ -1,57 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { Collection } from '@stdlib/types/array'; -import { typedndarray } from '@stdlib/types/ndarray'; - -/** -* Returns a view of the diagonal of a matrix (or stack of matrices). -* -* ## Notes -* -* - The order of the dimension indices contained in `dims` matters. The first element specifies the row-like dimension. The second element specifies the column-like dimension. -* - Each provided dimension index must reside on the interval `[-ndims, ndims-1]`. -* - The diagonal offset `k` is interpreted as `column - row`. Accordingly, when `k = 0`, the function returns the main diagonal; when `k > 0`, the function returns the diagonal above the main diagonal; and when `k < 0`, the function returns the diagonal below the main diagonal. -* - The returned ndarray is a **view** of the input ndarray. Accordingly, writing to the original ndarray will **mutate** the returned ndarray and vice versa. -* - The `writable` parameter **only** applies to ndarray constructors supporting **read-only** instances. -* -* @param x - input array -* @param dims - dimension indices defining the plane from which to extract the diagonal -* @param k - diagonal offset -* @param writable - boolean indicating whether the returned ndarray should be writable -* @returns ndarray view -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] ); -* // returns [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] -* -* var y = diagonal( x, [ 0, 1 ], 0, false ); -* // returns [ 1.0, 5.0, 9.0 ] -*/ -declare function diagonal = typedndarray>( x: U, dims: Collection, k: number, writable: boolean ): U; - - -// EXPORTS // - -export = diagonal; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index ce94273..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-to-unique-normalized-indices@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.3-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.3-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.3-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.3-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.3-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-join@v0.1.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-min@v0.2.4-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";function l(l,h,p,j){var u,v,f,b,g,c,x,y,w,E,M,R,V,q,z;if(2!==h.length)throw new RangeError(o("invalid argument. Must provide exactly two dimension indices. Value: `[%s]`.",a(h,", ")));if((f=(x=r(l)).length)<2)throw new RangeError(o("invalid argument. First argument must be an ndarray having at least two dimensions. Number of dimensions: %d.",f));if(y=t(l),null===(V=e(h,f-1)))throw new RangeError(o("invalid argument. Specified dimension index is out-of-bounds. Must be on the interval: [-%u, %u]. Value: `[%s]`.",f,f-1,a(h,", ")));if(V.length!==h.length)throw new Error(o("invalid argument. Must provide unique dimension indices. Value: `[%s]`.",a(h,", ")));for(w=y[V[0]],E=y[V[1]],M=(R=p>0?p:0)-p,g=x[V[0]]-M,c=x[V[1]]-R,(q=m(g,c))<0&&(q=0),v=n(l),q>0&&(v+=R*E+M*w),b=[],u=[],z=0;z 0`, the function returns the diagonal above the main diagonal; and when `k < 0`, the function returns the diagonal below the main diagonal.\n* - The returned ndarray is a **view** of the input ndarray. Accordingly, writing to the original ndarray will **mutate** the returned ndarray and vice versa.\n* - The `writable` parameter **only** applies to ndarray constructors supporting **read-only** instances.\n*\n* @param {ndarray} x - input array\n* @param {IntegerArray} dims - dimension indices defining the plane from which to extract the diagonal\n* @param {integer} k - diagonal offset\n* @param {boolean} writable - boolean indicating whether the returned ndarray should be writable\n* @throws {RangeError} must provide exactly two dimension indices\n* @throws {RangeError} input ndarray must have at least two dimensions\n* @throws {RangeError} must provide valid dimension indices\n* @throws {Error} must provide unique dimension indices\n* @returns {ndarray} ndarray view\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] );\n* // returns [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ]\n*\n* var y = diagonal( x, [ 0, 1 ], 0, false );\n* // returns [ 1.0, 5.0, 9.0 ]\n*/\nfunction diagonal( x, dims, k, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar ndims;\n\tvar shape;\n\tvar rows;\n\tvar cols;\n\tvar sh;\n\tvar st;\n\tvar sr;\n\tvar sc;\n\tvar ro;\n\tvar co;\n\tvar d;\n\tvar L;\n\tvar i;\n\n\tif ( dims.length !== 2 ) {\n\t\tthrow new RangeError( format( 'invalid argument. Must provide exactly two dimension indices. Value: `[%s]`.', join( dims, ', ' ) ) );\n\t}\n\tsh = getShape( x );\n\tndims = sh.length;\n\tif ( ndims < 2 ) {\n\t\tthrow new RangeError( format( 'invalid argument. First argument must be an ndarray having at least two dimensions. Number of dimensions: %d.', ndims ) );\n\t}\n\tst = getStrides( x );\n\n\t// Resolve dimension indices...\n\td = toUniqueNormalizedIndices( dims, ndims-1 );\n\tif ( d === null ) {\n\t\tthrow new RangeError( format( 'invalid argument. Specified dimension index is out-of-bounds. Must be on the interval: [-%u, %u]. Value: `[%s]`.', ndims, ndims-1, join( dims, ', ' ) ) );\n\t}\n\tif ( d.length !== dims.length ) {\n\t\tthrow new Error( format( 'invalid argument. Must provide unique dimension indices. Value: `[%s]`.', join( dims, ', ' ) ) );\n\t}\n\tsr = st[ d[0] ];\n\tsc = st[ d[1] ];\n\n\t// Resolve the row and column offsets corresponding to the diagonal offset `k = column - row`:\n\tco = ( k > 0 ) ? k : 0;\n\tro = co - k;\n\n\t// Compute the length of the diagonal:\n\trows = sh[ d[0] ] - ro;\n\tcols = sh[ d[1] ] - co;\n\tL = min( rows, cols );\n\tif ( L < 0 ) {\n\t\tL = 0;\n\t}\n\n\t// Adjust the offset so that we point to the first element along the specified diagonal:\n\toffset = getOffset( x );\n\tif ( L > 0 ) {\n\t\toffset += ( co*sc ) + ( ro*sr );\n\t}\n\n\t// Drop the specified dimensions and append the diagonal dimension:\n\tshape = [];\n\tstrides = [];\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tif ( i === d[0] || i === d[1] ) {\n\t\t\tcontinue;\n\t\t}\n\t\tshape.push( sh[ i ] );\n\t\tstrides.push( st[ i ] );\n\t}\n\tshape.push( L );\n\tstrides.push( sr + sc );\n\n\treturn new x.constructor( getDType( x ), getData( x ), shape, strides, offset, getOrder( x ), { // eslint-disable-line max-len\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default diagonal;\n"],"names":["diagonal","x","dims","k","writable","strides","offset","ndims","shape","rows","cols","sh","st","sr","sc","ro","co","d","L","i","length","RangeError","format","join","getShape","getStrides","toUniqueNormalizedIndices","Error","min","getOffset","push","constructor","getDType","getData","getOrder","readonly"],"mappings":";;s8BAkEA,SAASA,EAAUC,EAAGC,EAAMC,EAAGC,GAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAqB,IAAhBjB,EAAKkB,OACT,MAAM,IAAIC,WAAYC,EAAQ,+EAAgFC,EAAMrB,EAAM,QAI3H,IADAK,GADAI,EAAKa,EAAUvB,IACJmB,QACE,EACZ,MAAM,IAAIC,WAAYC,EAAQ,gHAAiHf,IAMhJ,GAJAK,EAAKa,EAAYxB,GAIN,QADXgB,EAAIS,EAA2BxB,EAAMK,EAAM,IAE1C,MAAM,IAAIc,WAAYC,EAAQ,mHAAoHf,EAAOA,EAAM,EAAGgB,EAAMrB,EAAM,QAE/K,GAAKe,EAAEG,SAAWlB,EAAKkB,OACtB,MAAM,IAAIO,MAAOL,EAAQ,0EAA2EC,EAAMrB,EAAM,QA0BjH,IAxBAW,EAAKD,EAAIK,EAAE,IACXH,EAAKF,EAAIK,EAAE,IAIXF,GADAC,EAAOb,EAAI,EAAMA,EAAI,GACXA,EAGVM,EAAOE,EAAIM,EAAE,IAAOF,EACpBL,EAAOC,EAAIM,EAAE,IAAOD,GACpBE,EAAIU,EAAKnB,EAAMC,IACN,IACRQ,EAAI,GAILZ,EAASuB,EAAW5B,GACfiB,EAAI,IACRZ,GAAYU,EAAGF,EAASC,EAAGF,GAI5BL,EAAQ,GACRH,EAAU,GACJc,EAAI,EAAGA,EAAIZ,EAAOY,IAClBA,IAAMF,EAAE,IAAME,IAAMF,EAAE,KAG3BT,EAAMsB,KAAMnB,EAAIQ,IAChBd,EAAQyB,KAAMlB,EAAIO,KAKnB,OAHAX,EAAMsB,KAAMZ,GACZb,EAAQyB,KAAMjB,EAAKC,GAEZ,IAAIb,EAAE8B,YAAaC,EAAU/B,GAAKgC,EAAShC,GAAKO,EAAOH,EAASC,EAAQ4B,EAAUjC,GAAK,CAC7FkC,UAAa/B,GAEf"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index c71bc8b..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 7aff753c031744543ecb13faae0f73682fe9e4a8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 11 May 2026 21:03:22 +0000 Subject: [PATCH 08/23] Auto-generated commit --- .editorconfig | 189 - .eslintrc.js | 1 - .gitattributes | 68 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 821 --- .github/workflows/publish.yml | 261 - .github/workflows/test.yml | 101 - .github/workflows/test_bundles.yml | 213 - .github/workflows/test_coverage.yml | 142 - .github/workflows/test_install.yml | 94 - .github/workflows/test_published_package.yml | 115 - .gitignore | 204 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 52 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 41 +- SECURITY.md | 5 - benchmark/benchmark.js | 272 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 51 - docs/types/test.ts | 92 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 44 - lib/main.js | 144 - package.json | 77 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 619 --- 43 files changed, 4866 insertions(+), 4922 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 (96%) 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/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 5dacce3..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/diagonal) 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 bbaa7c7..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/diagonal) 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 52ddcc8..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: '7 19 * * 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 + + ```
@@ -207,7 +198,7 @@ console.log( ndarray2array( y ) ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. 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 3a0a3bc..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,272 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var diagonal = require( './../lib' ); - - -// MAIN // - -bench( format( '%s::ndims=2,ctor=base', pkg ), function benchmark( b ) { - var values; - var v; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = diagonal( values[ i%values.length ], [ 0, 1 ], 0, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::ndims=2,ctor=non-base', pkg ), function benchmark( b ) { - var values; - var v; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - values = [ - empty( [ 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = diagonal( values[ i%values.length ], [ 0, 1 ], 0, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::ndims=3,ctor=base', pkg ), function benchmark( b ) { - var values; - var v; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = diagonal( values[ i%values.length ], [ 1, 2 ], 0, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::ndims=3,ctor=non-base', pkg ), function benchmark( b ) { - var values; - var v; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - values = [ - empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = diagonal( values[ i%values.length ], [ 1, 2 ], 0, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::ndims=4,ctor=base', pkg ), function benchmark( b ) { - var values; - var v; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = diagonal( values[ i%values.length ], [ 2, 3 ], 0, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::ndims=4,ctor=non-base', pkg ), function benchmark( b ) { - var values; - var v; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - values = [ - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = diagonal( values[ i%values.length ], [ 2, 3 ], 0, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::ndims=5,ctor=base', pkg ), function benchmark( b ) { - var values; - var v; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = diagonal( values[ i%values.length ], [ 3, 4 ], 0, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::ndims=5,ctor=non-base', pkg ), function benchmark( b ) { - var values; - var v; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - values = [ - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = diagonal( values[ i%values.length ], [ 3, 4 ], 0, false ); - if ( typeof v !== '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 437ecb7..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/diagonal" -%% click B href "https://github.com/stdlib-js/ndarray-base-diagonal/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-diagonal/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-diagonal/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-diagonal/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-diagonal/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/diagonal -[production-url]: https://github.com/stdlib-js/ndarray-base-diagonal/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-diagonal/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-diagonal/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-diagonal/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-diagonal/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-diagonal/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-diagonal/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 a7ab3b4..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import diagonal from '../docs/types/index'; -export = diagonal; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index a4a250a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var M=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var y=M(function(T,b){ -var R=require('@stdlib/ndarray-base-to-unique-normalized-indices/dist'),S=require('@stdlib/ndarray-base-dtype/dist'),V=require('@stdlib/ndarray-base-shape/dist'),D=require('@stdlib/ndarray-base-strides/dist'),N=require('@stdlib/ndarray-base-offset/dist'),O=require('@stdlib/ndarray-base-order/dist'),j=require('@stdlib/ndarray-base-data-buffer/dist'),q=require('@stdlib/array-base-join/dist'),z=require('@stdlib/math-base-special-min/dist'),g=require('@stdlib/error-tools-fmtprodmsg/dist');function F(e,r,l,E){var u,f,a,s,p,w,t,v,h,c,m,d,i,o,n;if(r.length!==2)throw new RangeError(g("invalid argument. Must provide exactly two dimension indices. Value: `[%s]`.",q(r,", ")));if(t=V(e),a=t.length,a<2)throw new RangeError(g("invalid argument. First argument must be an ndarray having two or more dimensions. Number of dimensions: %d.",a));if(v=D(e),i=R(r,a-1),i===null)throw new RangeError(g('nullHO',a,a-1,q(r,", ")));if(i.length!==r.length)throw new Error(g('nullHP',q(r,", ")));for(h=v[i[0]],c=v[i[1]],d=l>0?l:0,m=d-l,p=t[i[0]]-m,w=t[i[1]]-d,o=z(p,w),o<0&&(o=0),f=N(e),o>0&&(f+=d*c+m*h),s=[],u=[],n=0;n 0`, the function returns the diagonal above the main diagonal; and when `k < 0`, the function returns the diagonal below the main diagonal.\n* - The returned ndarray is a **view** of the input ndarray. Accordingly, writing to the original ndarray will **mutate** the returned ndarray and vice versa.\n* - The `writable` parameter **only** applies to ndarray constructors supporting **read-only** instances.\n*\n* @param {ndarray} x - input array\n* @param {IntegerArray} dims - dimension indices defining the plane from which to extract the diagonal\n* @param {integer} k - diagonal offset\n* @param {boolean} writable - boolean indicating whether the returned ndarray should be writable\n* @throws {RangeError} must provide exactly two dimension indices\n* @throws {RangeError} must provide an ndarray having two or more dimensions\n* @throws {RangeError} must provide valid dimension indices\n* @throws {Error} must provide unique dimension indices\n* @returns {ndarray} ndarray view\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] );\n* // returns [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ]\n*\n* var y = diagonal( x, [ 0, 1 ], 0, false );\n* // returns [ 1.0, 5.0, 9.0 ]\n*/\nfunction diagonal( x, dims, k, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar ndims;\n\tvar shape;\n\tvar rows;\n\tvar cols;\n\tvar sh;\n\tvar st;\n\tvar sr;\n\tvar sc;\n\tvar ro;\n\tvar co;\n\tvar d;\n\tvar L;\n\tvar i;\n\n\tif ( dims.length !== 2 ) {\n\t\tthrow new RangeError( format( 'invalid argument. Must provide exactly two dimension indices. Value: `[%s]`.', join( dims, ', ' ) ) );\n\t}\n\tsh = getShape( x );\n\tndims = sh.length;\n\tif ( ndims < 2 ) {\n\t\tthrow new RangeError( format( 'invalid argument. First argument must be an ndarray having two or more dimensions. Number of dimensions: %d.', ndims ) );\n\t}\n\tst = getStrides( x );\n\n\t// Resolve dimension indices...\n\td = toUniqueNormalizedIndices( dims, ndims-1 );\n\tif ( d === null ) {\n\t\tthrow new RangeError( format( 'invalid argument. Specified dimension index is out-of-bounds. Must be on the interval: [-%u, %u]. Value: `[%s]`.', ndims, ndims-1, join( dims, ', ' ) ) );\n\t}\n\tif ( d.length !== dims.length ) {\n\t\tthrow new Error( format( 'invalid argument. Must provide unique dimension indices. Value: `[%s]`.', join( dims, ', ' ) ) );\n\t}\n\tsr = st[ d[0] ];\n\tsc = st[ d[1] ];\n\n\t// Resolve the row and column offsets corresponding to the diagonal offset `k = column - row`:\n\tco = ( k > 0 ) ? k : 0;\n\tro = co - k;\n\n\t// Compute the length of the diagonal:\n\trows = sh[ d[0] ] - ro;\n\tcols = sh[ d[1] ] - co;\n\tL = min( rows, cols );\n\tif ( L < 0 ) {\n\t\tL = 0;\n\t}\n\n\t// Adjust the offset so that we point to the first element along the specified diagonal:\n\toffset = getOffset( x );\n\tif ( L > 0 ) {\n\t\toffset += ( co*sc ) + ( ro*sr );\n\t}\n\n\t// Drop the specified dimensions and append the diagonal dimension:\n\tshape = [];\n\tstrides = [];\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tif ( i === d[0] || i === d[1] ) {\n\t\t\tcontinue;\n\t\t}\n\t\tshape.push( sh[ i ] );\n\t\tstrides.push( st[ i ] );\n\t}\n\tshape.push( L );\n\tstrides.push( sr + sc );\n\n\treturn new x.constructor( getDType( x ), getData( x ), shape, strides, offset, getOrder( x ), { // eslint-disable-line max-len\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nmodule.exports = diagonal;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Return a view of the diagonal of a matrix (or stack of matrices).\n*\n* @module @stdlib/ndarray-base-diagonal\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var diagonal = require( '@stdlib/ndarray-base-diagonal' );\n*\n* var x = array( [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] );\n* // returns [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ]\n*\n* var y = diagonal( x, [ 0, 1 ], 0, false );\n* // returns [ 1.0, 5.0, 9.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,EAA4B,QAAS,mDAAoD,EACzFC,EAAW,QAAS,4BAA6B,EACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAa,QAAS,8BAA+B,EACrDC,EAAY,QAAS,6BAA8B,EACnDC,EAAW,QAAS,4BAA6B,EACjDC,EAAU,QAAS,kCAAmC,EACtDC,EAAO,QAAS,yBAA0B,EAC1CC,EAAM,QAAS,+BAAgC,EAC/CC,EAAS,QAAS,uBAAwB,EAmC9C,SAASC,EAAUC,EAAGC,EAAMC,EAAGC,EAAW,CACzC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAKjB,EAAK,SAAW,EACpB,MAAM,IAAI,WAAYH,EAAQ,+EAAgFF,EAAMK,EAAM,IAAK,CAAE,CAAE,EAIpI,GAFAS,EAAKnB,EAAUS,CAAE,EACjBM,EAAQI,EAAG,OACNJ,EAAQ,EACZ,MAAM,IAAI,WAAYR,EAAQ,+GAAgHQ,CAAM,CAAE,EAMvJ,GAJAK,EAAKnB,EAAYQ,CAAE,EAGnBgB,EAAI3B,EAA2BY,EAAMK,EAAM,CAAE,EACxCU,IAAM,KACV,MAAM,IAAI,WAAYlB,EAAQ,mHAAoHQ,EAAOA,EAAM,EAAGV,EAAMK,EAAM,IAAK,CAAE,CAAE,EAExL,GAAKe,EAAE,SAAWf,EAAK,OACtB,MAAM,IAAI,MAAOH,EAAQ,0EAA2EF,EAAMK,EAAM,IAAK,CAAE,CAAE,EA0B1H,IAxBAW,EAAKD,EAAIK,EAAE,CAAC,CAAE,EACdH,EAAKF,EAAIK,EAAE,CAAC,CAAE,EAGdD,EAAOb,EAAI,EAAMA,EAAI,EACrBY,EAAKC,EAAKb,EAGVM,EAAOE,EAAIM,EAAE,CAAC,CAAE,EAAIF,EACpBL,EAAOC,EAAIM,EAAE,CAAC,CAAE,EAAID,EACpBE,EAAIpB,EAAKW,EAAMC,CAAK,EACfQ,EAAI,IACRA,EAAI,GAILZ,EAASZ,EAAWO,CAAE,EACjBiB,EAAI,IACRZ,GAAYU,EAAGF,EAASC,EAAGF,GAI5BL,EAAQ,CAAC,EACTH,EAAU,CAAC,EACLc,EAAI,EAAGA,EAAIZ,EAAOY,IAClBA,IAAMF,EAAE,CAAC,GAAKE,IAAMF,EAAE,CAAC,IAG5BT,EAAM,KAAMG,EAAIQ,CAAE,CAAE,EACpBd,EAAQ,KAAMO,EAAIO,CAAE,CAAE,GAEvB,OAAAX,EAAM,KAAMU,CAAE,EACdb,EAAQ,KAAMQ,EAAKC,CAAG,EAEf,IAAIb,EAAE,YAAaV,EAAUU,CAAE,EAAGL,EAASK,CAAE,EAAGO,EAAOH,EAASC,EAAQX,EAAUM,CAAE,EAAG,CAC7F,SAAY,CAACG,CACd,CAAC,CACF,CAKAf,EAAO,QAAUW,ICzGjB,IAAIoB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "toUniqueNormalizedIndices", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "getData", "join", "min", "format", "diagonal", "x", "dims", "k", "writable", "strides", "offset", "ndims", "shape", "rows", "cols", "sh", "st", "sr", "sc", "ro", "co", "d", "L", "i", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index da74ae9..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,51 +0,0 @@ - -{{alias}}( x, dims, k, writable ) - Returns a view of the diagonal of a matrix (or stack of matrices). - - The order of the dimension indices contained in `dims` matters. The first - element specifies the row-like dimension. The second element specifies - the column-like dimension. - - Each provided dimension index must reside on the interval [-ndims, ndims-1]. - - The diagonal offset `k` is interpreted as `column - row`. Accordingly, - when `k = 0`, the function returns the main diagonal; when `k > 0`, the - function returns the diagonal above the main diagonal; and when `k < 0`, - the function returns the diagonal below the main diagonal. - - The returned ndarray is a *view* of the input ndarray. Accordingly, - writing to the original ndarray will mutate the returned ndarray and - vice versa. - - The `writable` parameter only applies to ndarray constructors supporting - read-only instances. - - Parameters - ---------- - x: ndarray - Input array. - - dims: ArrayLikeObject - Dimension indices defining the plane from which to extract the diagonal. - - k: integer - Diagonal offset. - - writable: boolean - Boolean indicating whether the returned ndarray should be writable. - - Returns - ------- - out: ndarray - Output array view. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ) - [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] - > var y = {{alias}}( x, [ 0, 1 ], 0, false ) - [ 1.0, 4.0 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 513a253..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,92 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 zeros = require( '@stdlib/ndarray-zeros' ); -import diagonal = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - - diagonal( x, [ 0, 1 ], 0, false ); // $ExpectType float64ndarray -} - -// The compiler throws an error if the function is not provided a first argument which is an ndarray... -{ - diagonal( '5', [ 0, 1 ], 0, false ); // $ExpectError - diagonal( 5, [ 0, 1 ], 0, false ); // $ExpectError - diagonal( true, [ 0, 1 ], 0, false ); // $ExpectError - diagonal( false, [ 0, 1 ], 0, false ); // $ExpectError - diagonal( null, [ 0, 1 ], 0, false ); // $ExpectError - diagonal( {}, [ 0, 1 ], 0, false ); // $ExpectError - diagonal( [ '5' ], [ 0, 1 ], 0, false ); // $ExpectError - diagonal( ( x: number ): number => x, [ 0, 1 ], 0, false ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a second argument which is an array-like object containing numbers... -{ - const x = zeros( [ 2, 2 ] ); - - diagonal( x, '5', 0, false ); // $ExpectError - diagonal( x, 5, 0, false ); // $ExpectError - diagonal( x, true, 0, false ); // $ExpectError - diagonal( x, false, 0, false ); // $ExpectError - diagonal( x, null, 0, false ); // $ExpectError - diagonal( x, {}, 0, false ); // $ExpectError - diagonal( x, [ '5' ], 0, false ); // $ExpectError - diagonal( x, ( x: number ): number => x, 0, false ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a third argument which is a number... -{ - const x = zeros( [ 2, 2 ] ); - - diagonal( x, [ 0, 1 ], '5', false ); // $ExpectError - diagonal( x, [ 0, 1 ], true, false ); // $ExpectError - diagonal( x, [ 0, 1 ], false, false ); // $ExpectError - diagonal( x, [ 0, 1 ], null, false ); // $ExpectError - diagonal( x, [ 0, 1 ], {}, false ); // $ExpectError - diagonal( x, [ 0, 1 ], [], false ); // $ExpectError - diagonal( x, [ 0, 1 ], ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a fourth argument which is a boolean... -{ - const x = zeros( [ 2, 2 ] ); - - diagonal( x, [ 0, 1 ], 0, '5' ); // $ExpectError - diagonal( x, [ 0, 1 ], 0, 5 ); // $ExpectError - diagonal( x, [ 0, 1 ], 0, null ); // $ExpectError - diagonal( x, [ 0, 1 ], 0, {} ); // $ExpectError - diagonal( x, [ 0, 1 ], 0, [] ); // $ExpectError - diagonal( x, [ 0, 1 ], 0, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = zeros( [ 2, 2 ] ); - - diagonal(); // $ExpectError - diagonal( x ); // $ExpectError - diagonal( x, [ 0, 1 ] ); // $ExpectError - diagonal( x, [ 0, 1 ], 0 ); // $ExpectError - diagonal( x, [ 0, 1 ], 0, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 742dc69..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 uniform = require( '@stdlib/random-uniform' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var diagonal = require( './../lib' ); - -// Create a stack of matrices: -var x = uniform( [ 2, 3, 3 ], -10.0, 10.0, { - 'dtype': 'float64' -}); -console.log( ndarray2array( x ) ); - -// Extract the main diagonals from the stack: -var y = diagonal( x, [ 1, 2 ], 0, false ); -console.log( ndarray2array( y ) ); - -// Extract super-diagonals from the stack: -y = diagonal( x, [ 1, 2 ], 1, false ); -console.log( ndarray2array( y ) ); - -// Extract sub-diagonals from the stack: -y = diagonal( x, [ 1, 2 ], -1, false ); -console.log( ndarray2array( y ) ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index 5ab7709..9e71468 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/array'; import { typedndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..8e4e50f --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-to-unique-normalized-indices@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.3-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.3-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.3-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.3-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.3-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-join@v0.1.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-min@v0.2.4-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";function l(l,h,p,j){var u,v,f,b,g,c,x,y,w,E,M,R,V,q,z;if(2!==h.length)throw new RangeError(a("invalid argument. Must provide exactly two dimension indices. Value: `[%s]`.",o(h,", ")));if((f=(x=r(l)).length)<2)throw new RangeError(a("invalid argument. First argument must be an ndarray having two or more dimensions. Number of dimensions: %d.",f));if(y=n(l),null===(V=e(h,f-1)))throw new RangeError(a("invalid argument. Specified dimension index is out-of-bounds. Must be on the interval: [-%u, %u]. Value: `[%s]`.",f,f-1,o(h,", ")));if(V.length!==h.length)throw new Error(a("invalid argument. Must provide unique dimension indices. Value: `[%s]`.",o(h,", ")));for(w=y[V[0]],E=y[V[1]],M=(R=p>0?p:0)-p,g=x[V[0]]-M,c=x[V[1]]-R,(q=m(g,c))<0&&(q=0),v=t(l),q>0&&(v+=R*E+M*w),b=[],u=[],z=0;z 0`, the function returns the diagonal above the main diagonal; and when `k < 0`, the function returns the diagonal below the main diagonal.\n* - The returned ndarray is a **view** of the input ndarray. Accordingly, writing to the original ndarray will **mutate** the returned ndarray and vice versa.\n* - The `writable` parameter **only** applies to ndarray constructors supporting **read-only** instances.\n*\n* @param {ndarray} x - input array\n* @param {IntegerArray} dims - dimension indices defining the plane from which to extract the diagonal\n* @param {integer} k - diagonal offset\n* @param {boolean} writable - boolean indicating whether the returned ndarray should be writable\n* @throws {RangeError} must provide exactly two dimension indices\n* @throws {RangeError} must provide an ndarray having two or more dimensions\n* @throws {RangeError} must provide valid dimension indices\n* @throws {Error} must provide unique dimension indices\n* @returns {ndarray} ndarray view\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] );\n* // returns [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ]\n*\n* var y = diagonal( x, [ 0, 1 ], 0, false );\n* // returns [ 1.0, 5.0, 9.0 ]\n*/\nfunction diagonal( x, dims, k, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar ndims;\n\tvar shape;\n\tvar rows;\n\tvar cols;\n\tvar sh;\n\tvar st;\n\tvar sr;\n\tvar sc;\n\tvar ro;\n\tvar co;\n\tvar d;\n\tvar L;\n\tvar i;\n\n\tif ( dims.length !== 2 ) {\n\t\tthrow new RangeError( format( 'invalid argument. Must provide exactly two dimension indices. Value: `[%s]`.', join( dims, ', ' ) ) );\n\t}\n\tsh = getShape( x );\n\tndims = sh.length;\n\tif ( ndims < 2 ) {\n\t\tthrow new RangeError( format( 'invalid argument. First argument must be an ndarray having two or more dimensions. Number of dimensions: %d.', ndims ) );\n\t}\n\tst = getStrides( x );\n\n\t// Resolve dimension indices...\n\td = toUniqueNormalizedIndices( dims, ndims-1 );\n\tif ( d === null ) {\n\t\tthrow new RangeError( format( 'invalid argument. Specified dimension index is out-of-bounds. Must be on the interval: [-%u, %u]. Value: `[%s]`.', ndims, ndims-1, join( dims, ', ' ) ) );\n\t}\n\tif ( d.length !== dims.length ) {\n\t\tthrow new Error( format( 'invalid argument. Must provide unique dimension indices. Value: `[%s]`.', join( dims, ', ' ) ) );\n\t}\n\tsr = st[ d[0] ];\n\tsc = st[ d[1] ];\n\n\t// Resolve the row and column offsets corresponding to the diagonal offset `k = column - row`:\n\tco = ( k > 0 ) ? k : 0;\n\tro = co - k;\n\n\t// Compute the length of the diagonal:\n\trows = sh[ d[0] ] - ro;\n\tcols = sh[ d[1] ] - co;\n\tL = min( rows, cols );\n\tif ( L < 0 ) {\n\t\tL = 0;\n\t}\n\n\t// Adjust the offset so that we point to the first element along the specified diagonal:\n\toffset = getOffset( x );\n\tif ( L > 0 ) {\n\t\toffset += ( co*sc ) + ( ro*sr );\n\t}\n\n\t// Drop the specified dimensions and append the diagonal dimension:\n\tshape = [];\n\tstrides = [];\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tif ( i === d[0] || i === d[1] ) {\n\t\t\tcontinue;\n\t\t}\n\t\tshape.push( sh[ i ] );\n\t\tstrides.push( st[ i ] );\n\t}\n\tshape.push( L );\n\tstrides.push( sr + sc );\n\n\treturn new x.constructor( getDType( x ), getData( x ), shape, strides, offset, getOrder( x ), { // eslint-disable-line max-len\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default diagonal;\n"],"names":["diagonal","x","dims","k","writable","strides","offset","ndims","shape","rows","cols","sh","st","sr","sc","ro","co","d","L","i","length","RangeError","format","join","getShape","getStrides","toUniqueNormalizedIndices","Error","min","getOffset","push","constructor","getDType","getData","getOrder","readonly"],"mappings":";;s8BAkEA,SAASA,EAAUC,EAAGC,EAAMC,EAAGC,GAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAqB,IAAhBjB,EAAKkB,OACT,MAAM,IAAIC,WAAYC,EAAQ,+EAAgFC,EAAMrB,EAAM,QAI3H,IADAK,GADAI,EAAKa,EAAUvB,IACJmB,QACE,EACZ,MAAM,IAAIC,WAAYC,EAAQ,+GAAgHf,IAM/I,GAJAK,EAAKa,EAAYxB,GAIN,QADXgB,EAAIS,EAA2BxB,EAAMK,EAAM,IAE1C,MAAM,IAAIc,WAAYC,EAAQ,mHAAoHf,EAAOA,EAAM,EAAGgB,EAAMrB,EAAM,QAE/K,GAAKe,EAAEG,SAAWlB,EAAKkB,OACtB,MAAM,IAAIO,MAAOL,EAAQ,0EAA2EC,EAAMrB,EAAM,QA0BjH,IAxBAW,EAAKD,EAAIK,EAAE,IACXH,EAAKF,EAAIK,EAAE,IAIXF,GADAC,EAAOb,EAAI,EAAMA,EAAI,GACXA,EAGVM,EAAOE,EAAIM,EAAE,IAAOF,EACpBL,EAAOC,EAAIM,EAAE,IAAOD,GACpBE,EAAIU,EAAKnB,EAAMC,IACN,IACRQ,EAAI,GAILZ,EAASuB,EAAW5B,GACfiB,EAAI,IACRZ,GAAYU,EAAGF,EAASC,EAAGF,GAI5BL,EAAQ,GACRH,EAAU,GACJc,EAAI,EAAGA,EAAIZ,EAAOY,IAClBA,IAAMF,EAAE,IAAME,IAAMF,EAAE,KAG3BT,EAAMsB,KAAMnB,EAAIQ,IAChBd,EAAQyB,KAAMlB,EAAIO,KAKnB,OAHAX,EAAMsB,KAAMZ,GACZb,EAAQyB,KAAMjB,EAAKC,GAEZ,IAAIb,EAAE8B,YAAaC,EAAU/B,GAAKgC,EAAShC,GAAKO,EAAOH,EAASC,EAAQ4B,EAAUjC,GAAK,CAC7FkC,UAAa/B,GAEf"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a541856..0000000 --- a/lib/index.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Return a view of the diagonal of a matrix (or stack of matrices). -* -* @module @stdlib/ndarray-base-diagonal -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var diagonal = require( '@stdlib/ndarray-base-diagonal' ); -* -* var x = array( [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] ); -* // returns [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] -* -* var y = diagonal( x, [ 0, 1 ], 0, false ); -* // returns [ 1.0, 5.0, 9.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 acf301d..0000000 --- a/lib/main.js +++ /dev/null @@ -1,144 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var toUniqueNormalizedIndices = require( '@stdlib/ndarray-base-to-unique-normalized-indices' ); -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); -var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var join = require( '@stdlib/array-base-join' ); -var min = require( '@stdlib/math-base-special-min' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns a view of the diagonal of a matrix (or stack of matrices). -* -* ## Notes -* -* - The order of the dimension indices contained in `dims` matters. The first element specifies the row-like dimension. The second element specifies the column-like dimension. -* - Each provided dimension index must reside on the interval `[-ndims, ndims-1]`. -* - The diagonal offset `k` is interpreted as `column - row`. Accordingly, when `k = 0`, the function returns the main diagonal; when `k > 0`, the function returns the diagonal above the main diagonal; and when `k < 0`, the function returns the diagonal below the main diagonal. -* - The returned ndarray is a **view** of the input ndarray. Accordingly, writing to the original ndarray will **mutate** the returned ndarray and vice versa. -* - The `writable` parameter **only** applies to ndarray constructors supporting **read-only** instances. -* -* @param {ndarray} x - input array -* @param {IntegerArray} dims - dimension indices defining the plane from which to extract the diagonal -* @param {integer} k - diagonal offset -* @param {boolean} writable - boolean indicating whether the returned ndarray should be writable -* @throws {RangeError} must provide exactly two dimension indices -* @throws {RangeError} must provide an ndarray having two or more dimensions -* @throws {RangeError} must provide valid dimension indices -* @throws {Error} must provide unique dimension indices -* @returns {ndarray} ndarray view -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] ); -* // returns [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] -* -* var y = diagonal( x, [ 0, 1 ], 0, false ); -* // returns [ 1.0, 5.0, 9.0 ] -*/ -function diagonal( x, dims, k, writable ) { - var strides; - var offset; - var ndims; - var shape; - var rows; - var cols; - var sh; - var st; - var sr; - var sc; - var ro; - var co; - var d; - var L; - var i; - - if ( dims.length !== 2 ) { - throw new RangeError( format( 'invalid argument. Must provide exactly two dimension indices. Value: `[%s]`.', join( dims, ', ' ) ) ); - } - sh = getShape( x ); - ndims = sh.length; - if ( ndims < 2 ) { - throw new RangeError( format( 'invalid argument. First argument must be an ndarray having two or more dimensions. Number of dimensions: %d.', ndims ) ); - } - st = getStrides( x ); - - // Resolve dimension indices... - d = toUniqueNormalizedIndices( dims, ndims-1 ); - if ( d === null ) { - throw new RangeError( format( 'invalid argument. Specified dimension index is out-of-bounds. Must be on the interval: [-%u, %u]. Value: `[%s]`.', ndims, ndims-1, join( dims, ', ' ) ) ); - } - if ( d.length !== dims.length ) { - throw new Error( format( 'invalid argument. Must provide unique dimension indices. Value: `[%s]`.', join( dims, ', ' ) ) ); - } - sr = st[ d[0] ]; - sc = st[ d[1] ]; - - // Resolve the row and column offsets corresponding to the diagonal offset `k = column - row`: - co = ( k > 0 ) ? k : 0; - ro = co - k; - - // Compute the length of the diagonal: - rows = sh[ d[0] ] - ro; - cols = sh[ d[1] ] - co; - L = min( rows, cols ); - if ( L < 0 ) { - L = 0; - } - - // Adjust the offset so that we point to the first element along the specified diagonal: - offset = getOffset( x ); - if ( L > 0 ) { - offset += ( co*sc ) + ( ro*sr ); - } - - // Drop the specified dimensions and append the diagonal dimension: - shape = []; - strides = []; - for ( i = 0; i < ndims; i++ ) { - if ( i === d[0] || i === d[1] ) { - continue; - } - shape.push( sh[ i ] ); - strides.push( st[ i ] ); - } - shape.push( L ); - strides.push( sr + sc ); - - return new x.constructor( getDType( x ), getData( x ), shape, strides, offset, getOrder( x ), { // eslint-disable-line max-len - 'readonly': !writable - }); -} - - -// EXPORTS // - -module.exports = diagonal; diff --git a/package.json b/package.json index 27c91df..1e256a2 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Return a view of the diagonal of a matrix (or stack of matrices).", "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,56 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-join": "^0.1.2", - "@stdlib/math-base-special-min": "^0.2.4", - "@stdlib/ndarray-base-data-buffer": "^0.2.3", - "@stdlib/ndarray-base-dtype": "^0.2.3", - "@stdlib/ndarray-base-offset": "^0.2.3", - "@stdlib/ndarray-base-order": "^0.2.3", - "@stdlib/ndarray-base-shape": "^0.2.3", - "@stdlib/ndarray-base-strides": "^0.2.3", - "@stdlib/ndarray-base-to-unique-normalized-indices": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.2.3", - "@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-data-buffer": "^0.2.3", - "@stdlib/ndarray-empty": "^0.3.1", - "@stdlib/ndarray-offset": "^0.2.3", - "@stdlib/ndarray-order": "^0.2.3", - "@stdlib/ndarray-shape": "^0.2.3", - "@stdlib/ndarray-stride": "^0.2.3", - "@stdlib/ndarray-strides": "^0.2.3", - "@stdlib/ndarray-to-array": "^0.2.2", - "@stdlib/random-uniform": "^0.1.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..ecc38ac --- /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 fabc8fa..0000000 --- a/test/test.js +++ /dev/null @@ -1,619 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var array = require( '@stdlib/ndarray-array' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var getStrides = require( '@stdlib/ndarray-strides' ); -var getStride = require( '@stdlib/ndarray-stride' ); -var getOffset = require( '@stdlib/ndarray-offset' ); -var getData = require( '@stdlib/ndarray-data-buffer' ); -var getOrder = require( '@stdlib/ndarray-order' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var diagonal = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof diagonal, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided exactly two dimension indices', function test( t ) { - var values; - var x; - var i; - - x = new ndarray( 'float64', new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); - - values = [ - [], - [ 0 ], - [ 0, 1, 0 ], - [ 0, 1, 0, 1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ].length + ' dimension indices' ); - } - t.end(); - - function badValue( dims ) { - return function badValue() { - diagonal( x, dims, 0, false ); - }; - } -}); - -tape( 'the function throws an error if provided an input ndarray with fewer than two dimensions', function test( t ) { - var values; - var i; - - values = [ - new ndarray( 'float64', new Float64Array( [ 5.0 ] ), [], [ 0 ], 0, 'row-major' ), - new ndarray( 'float64', new Float64Array( [ 1.0, 2.0, 3.0 ] ), [ 3 ], [ 1 ], 0, 'row-major' ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided an input ndarray with '+values[ i ].ndims+' dimensions' ); - } - t.end(); - - function badValue( x ) { - return function badValue() { - diagonal( x, [ 0, 1 ], 0, false ); - }; - } -}); - -tape( 'the function throws an error if provided out-of-bounds dimension indices', function test( t ) { - var values; - var x; - var i; - - x = new ndarray( 'float64', new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); - - values = [ - [ 0, 2 ], - [ 2, 0 ], - [ -3, 0 ], - [ 0, -3 ], - [ 10, 0 ], - [ 0, 10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided dimension indices ['+values[ i ]+']' ); - } - t.end(); - - function badValue( dims ) { - return function badValue() { - diagonal( x, dims, 0, false ); - }; - } -}); - -tape( 'the function throws an error if provided duplicate dimension indices', function test( t ) { - var values; - var x; - var i; - - x = new ndarray( 'float64', new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ), [ 2, 2, 2 ], [ 4, 2, 1 ], 0, 'row-major' ); - - values = [ - [ 0, 0 ], - [ 1, 1 ], - [ 2, 2 ], - [ 0, -3 ], - [ -2, 1 ], - [ -1, 2 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided dimension indices ['+values[ i ]+']' ); - } - t.end(); - - function badValue( dims ) { - return function badValue() { - diagonal( x, dims, 0, false ); - }; - } -}); - -tape( 'the function returns a view of the main diagonal of a square matrix', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); - - y = diagonal( x, [ 0, 1 ], 0, false ); - - expected = [ 3 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 1, 5, 9 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.strictEqual( getData( y ), getData( x ), 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of the super-diagonal of a square matrix', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); - - y = diagonal( x, [ 0, 1 ], 1, false ); - - expected = [ 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 2, 6 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], 2, false ); - - expected = [ 1 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 3 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of the sub-diagonal of a square matrix', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); - - y = diagonal( x, [ 0, 1 ], -1, false ); - - expected = [ 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 4, 8 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], -2, false ); - - expected = [ 1 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 7 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of the diagonal of a non-square matrix (M < N)', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ 1, 2, 3, 4 ], [ 5, 6, 7, 8 ] ] ); - - y = diagonal( x, [ 0, 1 ], 0, false ); - - expected = [ 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 1, 6 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], 2, false ); - - expected = [ 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 3, 8 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], -1, false ); - - expected = [ 1 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 5 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of the diagonal of a non-square matrix (M > N)', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ], [ 7, 8 ] ] ); - - y = diagonal( x, [ 0, 1 ], 0, false ); - - expected = [ 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 1, 4 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], -2, false ); - - expected = [ 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 5, 8 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], 1, false ); - - expected = [ 1 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 2 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an empty view when the diagonal offset is out-of-bounds', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); - - y = diagonal( x, [ 0, 1 ], 3, false ); - - expected = [ 0 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = []; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], -3, false ); - - expected = [ 0 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = []; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], 100, false ); - - expected = [ 0 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = []; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function swaps the row-like and column-like dimensions when `dims` is reversed', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); - - y = diagonal( x, [ 1, 0 ], 1, false ); - - expected = [ 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 4, 8 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 1, 0 ], -1, false ); - - expected = [ 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 2, 6 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of the diagonals of a stack of matrices', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); - - y = diagonal( x, [ 1, 2 ], 0, false ); - - expected = [ 2, 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ [ 1, 4 ], [ 5, 8 ] ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 1, 2 ], 1, false ); - - expected = [ 2, 1 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ [ 2 ], [ 6 ] ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 1, 2 ], -1, false ); - - expected = [ 2, 1 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ [ 3 ], [ 7 ] ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function appends the diagonal dimension as the trailing dimension of the output ndarray', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ [ 1, 2, 3 ], [ 4, 5, 6 ] ], [ [ 7, 8, 9 ], [ 10, 11, 12 ] ] ] ); - - y = diagonal( x, [ 0, 2 ], 0, false ); - - expected = [ 2, 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ [ 1, 8 ], [ 4, 11 ] ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function normalizes negative dimension indices', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); - - y = diagonal( x, [ -2, -1 ], 0, false ); - - expected = [ 3 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 1, 5, 9 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a column-major ndarray when the input ndarray is column-major', function test( t ) { - var expected; - var x; - var y; - - x = ndarray( 'generic', [ 1, 4, 7, 2, 5, 8, 3, 6, 9 ], [ 3, 3 ], [ 1, 3 ], 0, 'column-major' ); - - y = diagonal( x, [ 0, 1 ], 0, false ); - - expected = 'column-major'; - t.strictEqual( getOrder( y ), expected, 'returns expected value' ); - - expected = [ 3 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 1, 5, 9 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a writable ndarray when `writable` is `true`', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); - y = diagonal( x, [ 0, 1 ], 0, true ); - - t.strictEqual( isReadOnly( y ), false, 'returns expected value' ); - t.strictEqual( getData( y ), getData( x ), 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a read-only ndarray when `writable` is `false`', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); - y = diagonal( x, [ 0, 1 ], 0, false ); - - t.strictEqual( isReadOnly( y ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function constructs the output by retaining all dimensions except the specified dimensions and appending the diagonal dimension', function test( t ) { - var expected; - var x; - var y; - - x = array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ], { - 'shape': [ 3, 2, 2 ] - }); - - y = diagonal( x, [ 1, 2 ], 0, false ); - - expected = [ 3, 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 4, 3 ]; - t.deepEqual( getStrides( y ), expected, 'returns expected value' ); - - expected = getOffset( x ); - t.strictEqual( getOffset( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function adjusts the offset to point to the first element of the requested diagonal', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); - - y = diagonal( x, [ 0, 1 ], 1, false ); - - expected = getOffset( x ) + getStride( x, 1 ); - t.strictEqual( getOffset( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], -1, false ); - - expected = getOffset( x ) + getStride( x, 0 ); - t.strictEqual( getOffset( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports input ndarrays having a non-zero buffer offset', function test( t ) { - var expected; - var x; - var y; - - x = ndarray( 'generic', [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], [ 3, 3 ], [ 3, 1 ], 1, 'row-major' ); - - y = diagonal( x, [ 0, 1 ], 0, false ); - - expected = [ 3 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 1, 5, 9 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.strictEqual( getData( y ), getData( x ), 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], 1, false ); - - expected = [ 2, 6 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], -1, false ); - - expected = [ 4, 8 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports 4D inputs with non-trailing `dims`', function test( t ) { - var expected; - var arr; - var x; - var y; - - arr = [ - [ - [ - [ 0, 1 ], - [ 2, 3 ], - [ 4, 5 ] - ], - [ - [ 6, 7 ], - [ 8, 9 ], - [ 10, 11 ] - ], - [ - [ 12, 13 ], - [ 14, 15 ], - [ 16, 17 ] - ] - ], - [ - [ - [ 18, 19 ], - [ 20, 21 ], - [ 22, 23 ] - ], - [ - [ 24, 25 ], - [ 26, 27 ], - [ 28, 29 ] - ], - [ - [ 30, 31 ], - [ 32, 33 ], - [ 34, 35 ] - ] - ] - ]; - x = array( arr ); - y = diagonal( x, [ 1, 2 ], 0, false ); - expected = [ 2, 2, 3 ]; - - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ - [ - [ 0, 8, 16 ], - [ 1, 9, 17 ] - ], - [ - [ 18, 26, 34 ], - [ 19, 27, 35 ] - ] - ]; - - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - t.strictEqual( getData( y ), getData( x ), 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports negative dimension indices combined with a non-zero `k`', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); - y = diagonal( x, [ -2, -1 ], 1, false ); - - expected = [ 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 2, 6 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ -2, -1 ], -1, false ); - - expected = [ 4, 8 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); From a829c38249ac5f8ba957519b4ccea7b5cd04ec40 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 14 May 2026 03:26:19 +0000 Subject: [PATCH 09/23] 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 a3666a6..acf301d 100644 --- a/lib/main.js +++ b/lib/main.js @@ -29,7 +29,7 @@ var getOrder = require( '@stdlib/ndarray-base-order' ); var getData = require( '@stdlib/ndarray-base-data-buffer' ); var join = require( '@stdlib/array-base-join' ); var min = require( '@stdlib/math-base-special-min' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // diff --git a/package.json b/package.json index 17c5403..27c91df 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/ndarray-base-shape": "^0.2.3", "@stdlib/ndarray-base-strides": "^0.2.3", "@stdlib/ndarray-base-to-unique-normalized-indices": "^0.1.1", - "@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 dd52d58a3a9c505fa9a810642977fdef64c160fc Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 14 May 2026 03:32:10 +0000 Subject: [PATCH 10/23] Remove files --- index.d.ts | 57 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4904 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 9e71468..0000000 --- a/index.d.ts +++ /dev/null @@ -1,57 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { Collection } from '@stdlib/types/array'; -import { typedndarray } from '@stdlib/types/ndarray'; - -/** -* Returns a view of the diagonal of a matrix (or stack of matrices). -* -* ## Notes -* -* - The order of the dimension indices contained in `dims` matters. The first element specifies the row-like dimension. The second element specifies the column-like dimension. -* - Each provided dimension index must reside on the interval `[-ndims, ndims-1]`. -* - The diagonal offset `k` is interpreted as `column - row`. Accordingly, when `k = 0`, the function returns the main diagonal; when `k > 0`, the function returns the diagonal above the main diagonal; and when `k < 0`, the function returns the diagonal below the main diagonal. -* - The returned ndarray is a **view** of the input ndarray. Accordingly, writing to the original ndarray will **mutate** the returned ndarray and vice versa. -* - The `writable` parameter **only** applies to ndarray constructors supporting **read-only** instances. -* -* @param x - input array -* @param dims - dimension indices defining the plane from which to extract the diagonal -* @param k - diagonal offset -* @param writable - boolean indicating whether the returned ndarray should be writable -* @returns ndarray view -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] ); -* // returns [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] -* -* var y = diagonal( x, [ 0, 1 ], 0, false ); -* // returns [ 1.0, 5.0, 9.0 ] -*/ -declare function diagonal = typedndarray>( x: U, dims: Collection, k: number, writable: boolean ): U; - - -// EXPORTS // - -export = diagonal; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 8e4e50f..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-to-unique-normalized-indices@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.3-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.3-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.3-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.3-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.3-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-join@v0.1.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-min@v0.2.4-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";function l(l,h,p,j){var u,v,f,b,g,c,x,y,w,E,M,R,V,q,z;if(2!==h.length)throw new RangeError(a("invalid argument. Must provide exactly two dimension indices. Value: `[%s]`.",o(h,", ")));if((f=(x=r(l)).length)<2)throw new RangeError(a("invalid argument. First argument must be an ndarray having two or more dimensions. Number of dimensions: %d.",f));if(y=n(l),null===(V=e(h,f-1)))throw new RangeError(a("invalid argument. Specified dimension index is out-of-bounds. Must be on the interval: [-%u, %u]. Value: `[%s]`.",f,f-1,o(h,", ")));if(V.length!==h.length)throw new Error(a("invalid argument. Must provide unique dimension indices. Value: `[%s]`.",o(h,", ")));for(w=y[V[0]],E=y[V[1]],M=(R=p>0?p:0)-p,g=x[V[0]]-M,c=x[V[1]]-R,(q=m(g,c))<0&&(q=0),v=t(l),q>0&&(v+=R*E+M*w),b=[],u=[],z=0;z 0`, the function returns the diagonal above the main diagonal; and when `k < 0`, the function returns the diagonal below the main diagonal.\n* - The returned ndarray is a **view** of the input ndarray. Accordingly, writing to the original ndarray will **mutate** the returned ndarray and vice versa.\n* - The `writable` parameter **only** applies to ndarray constructors supporting **read-only** instances.\n*\n* @param {ndarray} x - input array\n* @param {IntegerArray} dims - dimension indices defining the plane from which to extract the diagonal\n* @param {integer} k - diagonal offset\n* @param {boolean} writable - boolean indicating whether the returned ndarray should be writable\n* @throws {RangeError} must provide exactly two dimension indices\n* @throws {RangeError} must provide an ndarray having two or more dimensions\n* @throws {RangeError} must provide valid dimension indices\n* @throws {Error} must provide unique dimension indices\n* @returns {ndarray} ndarray view\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] );\n* // returns [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ]\n*\n* var y = diagonal( x, [ 0, 1 ], 0, false );\n* // returns [ 1.0, 5.0, 9.0 ]\n*/\nfunction diagonal( x, dims, k, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar ndims;\n\tvar shape;\n\tvar rows;\n\tvar cols;\n\tvar sh;\n\tvar st;\n\tvar sr;\n\tvar sc;\n\tvar ro;\n\tvar co;\n\tvar d;\n\tvar L;\n\tvar i;\n\n\tif ( dims.length !== 2 ) {\n\t\tthrow new RangeError( format( 'invalid argument. Must provide exactly two dimension indices. Value: `[%s]`.', join( dims, ', ' ) ) );\n\t}\n\tsh = getShape( x );\n\tndims = sh.length;\n\tif ( ndims < 2 ) {\n\t\tthrow new RangeError( format( 'invalid argument. First argument must be an ndarray having two or more dimensions. Number of dimensions: %d.', ndims ) );\n\t}\n\tst = getStrides( x );\n\n\t// Resolve dimension indices...\n\td = toUniqueNormalizedIndices( dims, ndims-1 );\n\tif ( d === null ) {\n\t\tthrow new RangeError( format( 'invalid argument. Specified dimension index is out-of-bounds. Must be on the interval: [-%u, %u]. Value: `[%s]`.', ndims, ndims-1, join( dims, ', ' ) ) );\n\t}\n\tif ( d.length !== dims.length ) {\n\t\tthrow new Error( format( 'invalid argument. Must provide unique dimension indices. Value: `[%s]`.', join( dims, ', ' ) ) );\n\t}\n\tsr = st[ d[0] ];\n\tsc = st[ d[1] ];\n\n\t// Resolve the row and column offsets corresponding to the diagonal offset `k = column - row`:\n\tco = ( k > 0 ) ? k : 0;\n\tro = co - k;\n\n\t// Compute the length of the diagonal:\n\trows = sh[ d[0] ] - ro;\n\tcols = sh[ d[1] ] - co;\n\tL = min( rows, cols );\n\tif ( L < 0 ) {\n\t\tL = 0;\n\t}\n\n\t// Adjust the offset so that we point to the first element along the specified diagonal:\n\toffset = getOffset( x );\n\tif ( L > 0 ) {\n\t\toffset += ( co*sc ) + ( ro*sr );\n\t}\n\n\t// Drop the specified dimensions and append the diagonal dimension:\n\tshape = [];\n\tstrides = [];\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tif ( i === d[0] || i === d[1] ) {\n\t\t\tcontinue;\n\t\t}\n\t\tshape.push( sh[ i ] );\n\t\tstrides.push( st[ i ] );\n\t}\n\tshape.push( L );\n\tstrides.push( sr + sc );\n\n\treturn new x.constructor( getDType( x ), getData( x ), shape, strides, offset, getOrder( x ), { // eslint-disable-line max-len\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default diagonal;\n"],"names":["diagonal","x","dims","k","writable","strides","offset","ndims","shape","rows","cols","sh","st","sr","sc","ro","co","d","L","i","length","RangeError","format","join","getShape","getStrides","toUniqueNormalizedIndices","Error","min","getOffset","push","constructor","getDType","getData","getOrder","readonly"],"mappings":";;s8BAkEA,SAASA,EAAUC,EAAGC,EAAMC,EAAGC,GAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAqB,IAAhBjB,EAAKkB,OACT,MAAM,IAAIC,WAAYC,EAAQ,+EAAgFC,EAAMrB,EAAM,QAI3H,IADAK,GADAI,EAAKa,EAAUvB,IACJmB,QACE,EACZ,MAAM,IAAIC,WAAYC,EAAQ,+GAAgHf,IAM/I,GAJAK,EAAKa,EAAYxB,GAIN,QADXgB,EAAIS,EAA2BxB,EAAMK,EAAM,IAE1C,MAAM,IAAIc,WAAYC,EAAQ,mHAAoHf,EAAOA,EAAM,EAAGgB,EAAMrB,EAAM,QAE/K,GAAKe,EAAEG,SAAWlB,EAAKkB,OACtB,MAAM,IAAIO,MAAOL,EAAQ,0EAA2EC,EAAMrB,EAAM,QA0BjH,IAxBAW,EAAKD,EAAIK,EAAE,IACXH,EAAKF,EAAIK,EAAE,IAIXF,GADAC,EAAOb,EAAI,EAAMA,EAAI,GACXA,EAGVM,EAAOE,EAAIM,EAAE,IAAOF,EACpBL,EAAOC,EAAIM,EAAE,IAAOD,GACpBE,EAAIU,EAAKnB,EAAMC,IACN,IACRQ,EAAI,GAILZ,EAASuB,EAAW5B,GACfiB,EAAI,IACRZ,GAAYU,EAAGF,EAASC,EAAGF,GAI5BL,EAAQ,GACRH,EAAU,GACJc,EAAI,EAAGA,EAAIZ,EAAOY,IAClBA,IAAMF,EAAE,IAAME,IAAMF,EAAE,KAG3BT,EAAMsB,KAAMnB,EAAIQ,IAChBd,EAAQyB,KAAMlB,EAAIO,KAKnB,OAHAX,EAAMsB,KAAMZ,GACZb,EAAQyB,KAAMjB,EAAKC,GAEZ,IAAIb,EAAE8B,YAAaC,EAAU/B,GAAKgC,EAAShC,GAAKO,EAAOH,EAASC,EAAQ4B,EAAUjC,GAAK,CAC7FkC,UAAa/B,GAEf"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index ecc38ac..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From c73741a88ca36d8503b88afa208d0951afbed1a8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 14 May 2026 03:32:46 +0000 Subject: [PATCH 11/23] Auto-generated commit --- .editorconfig | 189 - .eslintrc.js | 1 - .gitattributes | 68 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 821 --- .github/workflows/publish.yml | 261 - .github/workflows/test.yml | 101 - .github/workflows/test_bundles.yml | 213 - .github/workflows/test_coverage.yml | 142 - .github/workflows/test_install.yml | 94 - .github/workflows/test_published_package.yml | 115 - .gitignore | 204 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 52 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 41 +- SECURITY.md | 5 - benchmark/benchmark.js | 272 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 51 - docs/types/test.ts | 92 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 44 - lib/main.js | 144 - package.json | 77 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 619 --- 44 files changed, 4866 insertions(+), 4923 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 (96%) 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 da6a7c1..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2026-05-14T03:24:35.135Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 5dacce3..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/diagonal) 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 bbaa7c7..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/diagonal) 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 52ddcc8..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: '7 19 * * 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 + + ```
@@ -207,7 +198,7 @@ console.log( ndarray2array( y ) ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. 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 3a0a3bc..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,272 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var diagonal = require( './../lib' ); - - -// MAIN // - -bench( format( '%s::ndims=2,ctor=base', pkg ), function benchmark( b ) { - var values; - var v; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = diagonal( values[ i%values.length ], [ 0, 1 ], 0, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::ndims=2,ctor=non-base', pkg ), function benchmark( b ) { - var values; - var v; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - values = [ - empty( [ 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = diagonal( values[ i%values.length ], [ 0, 1 ], 0, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::ndims=3,ctor=base', pkg ), function benchmark( b ) { - var values; - var v; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = diagonal( values[ i%values.length ], [ 1, 2 ], 0, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::ndims=3,ctor=non-base', pkg ), function benchmark( b ) { - var values; - var v; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - values = [ - empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = diagonal( values[ i%values.length ], [ 1, 2 ], 0, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::ndims=4,ctor=base', pkg ), function benchmark( b ) { - var values; - var v; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = diagonal( values[ i%values.length ], [ 2, 3 ], 0, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::ndims=4,ctor=non-base', pkg ), function benchmark( b ) { - var values; - var v; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - values = [ - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = diagonal( values[ i%values.length ], [ 2, 3 ], 0, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::ndims=5,ctor=base', pkg ), function benchmark( b ) { - var values; - var v; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = diagonal( values[ i%values.length ], [ 3, 4 ], 0, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::ndims=5,ctor=non-base', pkg ), function benchmark( b ) { - var values; - var v; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - values = [ - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = diagonal( values[ i%values.length ], [ 3, 4 ], 0, false ); - if ( typeof v !== '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 437ecb7..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/diagonal" -%% click B href "https://github.com/stdlib-js/ndarray-base-diagonal/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-diagonal/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-diagonal/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-diagonal/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-diagonal/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/diagonal -[production-url]: https://github.com/stdlib-js/ndarray-base-diagonal/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-diagonal/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-diagonal/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-diagonal/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-diagonal/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-diagonal/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-diagonal/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 a7ab3b4..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import diagonal from '../docs/types/index'; -export = diagonal; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index a4a250a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var M=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var y=M(function(T,b){ -var R=require('@stdlib/ndarray-base-to-unique-normalized-indices/dist'),S=require('@stdlib/ndarray-base-dtype/dist'),V=require('@stdlib/ndarray-base-shape/dist'),D=require('@stdlib/ndarray-base-strides/dist'),N=require('@stdlib/ndarray-base-offset/dist'),O=require('@stdlib/ndarray-base-order/dist'),j=require('@stdlib/ndarray-base-data-buffer/dist'),q=require('@stdlib/array-base-join/dist'),z=require('@stdlib/math-base-special-min/dist'),g=require('@stdlib/error-tools-fmtprodmsg/dist');function F(e,r,l,E){var u,f,a,s,p,w,t,v,h,c,m,d,i,o,n;if(r.length!==2)throw new RangeError(g("invalid argument. Must provide exactly two dimension indices. Value: `[%s]`.",q(r,", ")));if(t=V(e),a=t.length,a<2)throw new RangeError(g("invalid argument. First argument must be an ndarray having two or more dimensions. Number of dimensions: %d.",a));if(v=D(e),i=R(r,a-1),i===null)throw new RangeError(g('nullHO',a,a-1,q(r,", ")));if(i.length!==r.length)throw new Error(g('nullHP',q(r,", ")));for(h=v[i[0]],c=v[i[1]],d=l>0?l:0,m=d-l,p=t[i[0]]-m,w=t[i[1]]-d,o=z(p,w),o<0&&(o=0),f=N(e),o>0&&(f+=d*c+m*h),s=[],u=[],n=0;n 0`, the function returns the diagonal above the main diagonal; and when `k < 0`, the function returns the diagonal below the main diagonal.\n* - The returned ndarray is a **view** of the input ndarray. Accordingly, writing to the original ndarray will **mutate** the returned ndarray and vice versa.\n* - The `writable` parameter **only** applies to ndarray constructors supporting **read-only** instances.\n*\n* @param {ndarray} x - input array\n* @param {IntegerArray} dims - dimension indices defining the plane from which to extract the diagonal\n* @param {integer} k - diagonal offset\n* @param {boolean} writable - boolean indicating whether the returned ndarray should be writable\n* @throws {RangeError} must provide exactly two dimension indices\n* @throws {RangeError} must provide an ndarray having two or more dimensions\n* @throws {RangeError} must provide valid dimension indices\n* @throws {Error} must provide unique dimension indices\n* @returns {ndarray} ndarray view\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] );\n* // returns [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ]\n*\n* var y = diagonal( x, [ 0, 1 ], 0, false );\n* // returns [ 1.0, 5.0, 9.0 ]\n*/\nfunction diagonal( x, dims, k, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar ndims;\n\tvar shape;\n\tvar rows;\n\tvar cols;\n\tvar sh;\n\tvar st;\n\tvar sr;\n\tvar sc;\n\tvar ro;\n\tvar co;\n\tvar d;\n\tvar L;\n\tvar i;\n\n\tif ( dims.length !== 2 ) {\n\t\tthrow new RangeError( format( 'invalid argument. Must provide exactly two dimension indices. Value: `[%s]`.', join( dims, ', ' ) ) );\n\t}\n\tsh = getShape( x );\n\tndims = sh.length;\n\tif ( ndims < 2 ) {\n\t\tthrow new RangeError( format( 'invalid argument. First argument must be an ndarray having two or more dimensions. Number of dimensions: %d.', ndims ) );\n\t}\n\tst = getStrides( x );\n\n\t// Resolve dimension indices...\n\td = toUniqueNormalizedIndices( dims, ndims-1 );\n\tif ( d === null ) {\n\t\tthrow new RangeError( format( 'invalid argument. Specified dimension index is out-of-bounds. Must be on the interval: [-%u, %u]. Value: `[%s]`.', ndims, ndims-1, join( dims, ', ' ) ) );\n\t}\n\tif ( d.length !== dims.length ) {\n\t\tthrow new Error( format( 'invalid argument. Must provide unique dimension indices. Value: `[%s]`.', join( dims, ', ' ) ) );\n\t}\n\tsr = st[ d[0] ];\n\tsc = st[ d[1] ];\n\n\t// Resolve the row and column offsets corresponding to the diagonal offset `k = column - row`:\n\tco = ( k > 0 ) ? k : 0;\n\tro = co - k;\n\n\t// Compute the length of the diagonal:\n\trows = sh[ d[0] ] - ro;\n\tcols = sh[ d[1] ] - co;\n\tL = min( rows, cols );\n\tif ( L < 0 ) {\n\t\tL = 0;\n\t}\n\n\t// Adjust the offset so that we point to the first element along the specified diagonal:\n\toffset = getOffset( x );\n\tif ( L > 0 ) {\n\t\toffset += ( co*sc ) + ( ro*sr );\n\t}\n\n\t// Drop the specified dimensions and append the diagonal dimension:\n\tshape = [];\n\tstrides = [];\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tif ( i === d[0] || i === d[1] ) {\n\t\t\tcontinue;\n\t\t}\n\t\tshape.push( sh[ i ] );\n\t\tstrides.push( st[ i ] );\n\t}\n\tshape.push( L );\n\tstrides.push( sr + sc );\n\n\treturn new x.constructor( getDType( x ), getData( x ), shape, strides, offset, getOrder( x ), { // eslint-disable-line max-len\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nmodule.exports = diagonal;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Return a view of the diagonal of a matrix (or stack of matrices).\n*\n* @module @stdlib/ndarray-base-diagonal\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var diagonal = require( '@stdlib/ndarray-base-diagonal' );\n*\n* var x = array( [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] );\n* // returns [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ]\n*\n* var y = diagonal( x, [ 0, 1 ], 0, false );\n* // returns [ 1.0, 5.0, 9.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,EAA4B,QAAS,mDAAoD,EACzFC,EAAW,QAAS,4BAA6B,EACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAa,QAAS,8BAA+B,EACrDC,EAAY,QAAS,6BAA8B,EACnDC,EAAW,QAAS,4BAA6B,EACjDC,EAAU,QAAS,kCAAmC,EACtDC,EAAO,QAAS,yBAA0B,EAC1CC,EAAM,QAAS,+BAAgC,EAC/CC,EAAS,QAAS,uBAAwB,EAmC9C,SAASC,EAAUC,EAAGC,EAAMC,EAAGC,EAAW,CACzC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAKjB,EAAK,SAAW,EACpB,MAAM,IAAI,WAAYH,EAAQ,+EAAgFF,EAAMK,EAAM,IAAK,CAAE,CAAE,EAIpI,GAFAS,EAAKnB,EAAUS,CAAE,EACjBM,EAAQI,EAAG,OACNJ,EAAQ,EACZ,MAAM,IAAI,WAAYR,EAAQ,+GAAgHQ,CAAM,CAAE,EAMvJ,GAJAK,EAAKnB,EAAYQ,CAAE,EAGnBgB,EAAI3B,EAA2BY,EAAMK,EAAM,CAAE,EACxCU,IAAM,KACV,MAAM,IAAI,WAAYlB,EAAQ,mHAAoHQ,EAAOA,EAAM,EAAGV,EAAMK,EAAM,IAAK,CAAE,CAAE,EAExL,GAAKe,EAAE,SAAWf,EAAK,OACtB,MAAM,IAAI,MAAOH,EAAQ,0EAA2EF,EAAMK,EAAM,IAAK,CAAE,CAAE,EA0B1H,IAxBAW,EAAKD,EAAIK,EAAE,CAAC,CAAE,EACdH,EAAKF,EAAIK,EAAE,CAAC,CAAE,EAGdD,EAAOb,EAAI,EAAMA,EAAI,EACrBY,EAAKC,EAAKb,EAGVM,EAAOE,EAAIM,EAAE,CAAC,CAAE,EAAIF,EACpBL,EAAOC,EAAIM,EAAE,CAAC,CAAE,EAAID,EACpBE,EAAIpB,EAAKW,EAAMC,CAAK,EACfQ,EAAI,IACRA,EAAI,GAILZ,EAASZ,EAAWO,CAAE,EACjBiB,EAAI,IACRZ,GAAYU,EAAGF,EAASC,EAAGF,GAI5BL,EAAQ,CAAC,EACTH,EAAU,CAAC,EACLc,EAAI,EAAGA,EAAIZ,EAAOY,IAClBA,IAAMF,EAAE,CAAC,GAAKE,IAAMF,EAAE,CAAC,IAG5BT,EAAM,KAAMG,EAAIQ,CAAE,CAAE,EACpBd,EAAQ,KAAMO,EAAIO,CAAE,CAAE,GAEvB,OAAAX,EAAM,KAAMU,CAAE,EACdb,EAAQ,KAAMQ,EAAKC,CAAG,EAEf,IAAIb,EAAE,YAAaV,EAAUU,CAAE,EAAGL,EAASK,CAAE,EAAGO,EAAOH,EAASC,EAAQX,EAAUM,CAAE,EAAG,CAC7F,SAAY,CAACG,CACd,CAAC,CACF,CAKAf,EAAO,QAAUW,ICzGjB,IAAIoB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "toUniqueNormalizedIndices", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "getData", "join", "min", "format", "diagonal", "x", "dims", "k", "writable", "strides", "offset", "ndims", "shape", "rows", "cols", "sh", "st", "sr", "sc", "ro", "co", "d", "L", "i", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index da74ae9..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,51 +0,0 @@ - -{{alias}}( x, dims, k, writable ) - Returns a view of the diagonal of a matrix (or stack of matrices). - - The order of the dimension indices contained in `dims` matters. The first - element specifies the row-like dimension. The second element specifies - the column-like dimension. - - Each provided dimension index must reside on the interval [-ndims, ndims-1]. - - The diagonal offset `k` is interpreted as `column - row`. Accordingly, - when `k = 0`, the function returns the main diagonal; when `k > 0`, the - function returns the diagonal above the main diagonal; and when `k < 0`, - the function returns the diagonal below the main diagonal. - - The returned ndarray is a *view* of the input ndarray. Accordingly, - writing to the original ndarray will mutate the returned ndarray and - vice versa. - - The `writable` parameter only applies to ndarray constructors supporting - read-only instances. - - Parameters - ---------- - x: ndarray - Input array. - - dims: ArrayLikeObject - Dimension indices defining the plane from which to extract the diagonal. - - k: integer - Diagonal offset. - - writable: boolean - Boolean indicating whether the returned ndarray should be writable. - - Returns - ------- - out: ndarray - Output array view. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ) - [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] - > var y = {{alias}}( x, [ 0, 1 ], 0, false ) - [ 1.0, 4.0 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 513a253..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,92 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 zeros = require( '@stdlib/ndarray-zeros' ); -import diagonal = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - - diagonal( x, [ 0, 1 ], 0, false ); // $ExpectType float64ndarray -} - -// The compiler throws an error if the function is not provided a first argument which is an ndarray... -{ - diagonal( '5', [ 0, 1 ], 0, false ); // $ExpectError - diagonal( 5, [ 0, 1 ], 0, false ); // $ExpectError - diagonal( true, [ 0, 1 ], 0, false ); // $ExpectError - diagonal( false, [ 0, 1 ], 0, false ); // $ExpectError - diagonal( null, [ 0, 1 ], 0, false ); // $ExpectError - diagonal( {}, [ 0, 1 ], 0, false ); // $ExpectError - diagonal( [ '5' ], [ 0, 1 ], 0, false ); // $ExpectError - diagonal( ( x: number ): number => x, [ 0, 1 ], 0, false ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a second argument which is an array-like object containing numbers... -{ - const x = zeros( [ 2, 2 ] ); - - diagonal( x, '5', 0, false ); // $ExpectError - diagonal( x, 5, 0, false ); // $ExpectError - diagonal( x, true, 0, false ); // $ExpectError - diagonal( x, false, 0, false ); // $ExpectError - diagonal( x, null, 0, false ); // $ExpectError - diagonal( x, {}, 0, false ); // $ExpectError - diagonal( x, [ '5' ], 0, false ); // $ExpectError - diagonal( x, ( x: number ): number => x, 0, false ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a third argument which is a number... -{ - const x = zeros( [ 2, 2 ] ); - - diagonal( x, [ 0, 1 ], '5', false ); // $ExpectError - diagonal( x, [ 0, 1 ], true, false ); // $ExpectError - diagonal( x, [ 0, 1 ], false, false ); // $ExpectError - diagonal( x, [ 0, 1 ], null, false ); // $ExpectError - diagonal( x, [ 0, 1 ], {}, false ); // $ExpectError - diagonal( x, [ 0, 1 ], [], false ); // $ExpectError - diagonal( x, [ 0, 1 ], ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a fourth argument which is a boolean... -{ - const x = zeros( [ 2, 2 ] ); - - diagonal( x, [ 0, 1 ], 0, '5' ); // $ExpectError - diagonal( x, [ 0, 1 ], 0, 5 ); // $ExpectError - diagonal( x, [ 0, 1 ], 0, null ); // $ExpectError - diagonal( x, [ 0, 1 ], 0, {} ); // $ExpectError - diagonal( x, [ 0, 1 ], 0, [] ); // $ExpectError - diagonal( x, [ 0, 1 ], 0, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = zeros( [ 2, 2 ] ); - - diagonal(); // $ExpectError - diagonal( x ); // $ExpectError - diagonal( x, [ 0, 1 ] ); // $ExpectError - diagonal( x, [ 0, 1 ], 0 ); // $ExpectError - diagonal( x, [ 0, 1 ], 0, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 742dc69..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 uniform = require( '@stdlib/random-uniform' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var diagonal = require( './../lib' ); - -// Create a stack of matrices: -var x = uniform( [ 2, 3, 3 ], -10.0, 10.0, { - 'dtype': 'float64' -}); -console.log( ndarray2array( x ) ); - -// Extract the main diagonals from the stack: -var y = diagonal( x, [ 1, 2 ], 0, false ); -console.log( ndarray2array( y ) ); - -// Extract super-diagonals from the stack: -y = diagonal( x, [ 1, 2 ], 1, false ); -console.log( ndarray2array( y ) ); - -// Extract sub-diagonals from the stack: -y = diagonal( x, [ 1, 2 ], -1, false ); -console.log( ndarray2array( y ) ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index 5ab7709..9e71468 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/array'; import { typedndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..8e4e50f --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-to-unique-normalized-indices@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.3-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.3-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.3-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.3-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.3-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-join@v0.1.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-min@v0.2.4-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";function l(l,h,p,j){var u,v,f,b,g,c,x,y,w,E,M,R,V,q,z;if(2!==h.length)throw new RangeError(a("invalid argument. Must provide exactly two dimension indices. Value: `[%s]`.",o(h,", ")));if((f=(x=r(l)).length)<2)throw new RangeError(a("invalid argument. First argument must be an ndarray having two or more dimensions. Number of dimensions: %d.",f));if(y=n(l),null===(V=e(h,f-1)))throw new RangeError(a("invalid argument. Specified dimension index is out-of-bounds. Must be on the interval: [-%u, %u]. Value: `[%s]`.",f,f-1,o(h,", ")));if(V.length!==h.length)throw new Error(a("invalid argument. Must provide unique dimension indices. Value: `[%s]`.",o(h,", ")));for(w=y[V[0]],E=y[V[1]],M=(R=p>0?p:0)-p,g=x[V[0]]-M,c=x[V[1]]-R,(q=m(g,c))<0&&(q=0),v=t(l),q>0&&(v+=R*E+M*w),b=[],u=[],z=0;z 0`, the function returns the diagonal above the main diagonal; and when `k < 0`, the function returns the diagonal below the main diagonal.\n* - The returned ndarray is a **view** of the input ndarray. Accordingly, writing to the original ndarray will **mutate** the returned ndarray and vice versa.\n* - The `writable` parameter **only** applies to ndarray constructors supporting **read-only** instances.\n*\n* @param {ndarray} x - input array\n* @param {IntegerArray} dims - dimension indices defining the plane from which to extract the diagonal\n* @param {integer} k - diagonal offset\n* @param {boolean} writable - boolean indicating whether the returned ndarray should be writable\n* @throws {RangeError} must provide exactly two dimension indices\n* @throws {RangeError} must provide an ndarray having two or more dimensions\n* @throws {RangeError} must provide valid dimension indices\n* @throws {Error} must provide unique dimension indices\n* @returns {ndarray} ndarray view\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] );\n* // returns [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ]\n*\n* var y = diagonal( x, [ 0, 1 ], 0, false );\n* // returns [ 1.0, 5.0, 9.0 ]\n*/\nfunction diagonal( x, dims, k, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar ndims;\n\tvar shape;\n\tvar rows;\n\tvar cols;\n\tvar sh;\n\tvar st;\n\tvar sr;\n\tvar sc;\n\tvar ro;\n\tvar co;\n\tvar d;\n\tvar L;\n\tvar i;\n\n\tif ( dims.length !== 2 ) {\n\t\tthrow new RangeError( format( 'invalid argument. Must provide exactly two dimension indices. Value: `[%s]`.', join( dims, ', ' ) ) );\n\t}\n\tsh = getShape( x );\n\tndims = sh.length;\n\tif ( ndims < 2 ) {\n\t\tthrow new RangeError( format( 'invalid argument. First argument must be an ndarray having two or more dimensions. Number of dimensions: %d.', ndims ) );\n\t}\n\tst = getStrides( x );\n\n\t// Resolve dimension indices...\n\td = toUniqueNormalizedIndices( dims, ndims-1 );\n\tif ( d === null ) {\n\t\tthrow new RangeError( format( 'invalid argument. Specified dimension index is out-of-bounds. Must be on the interval: [-%u, %u]. Value: `[%s]`.', ndims, ndims-1, join( dims, ', ' ) ) );\n\t}\n\tif ( d.length !== dims.length ) {\n\t\tthrow new Error( format( 'invalid argument. Must provide unique dimension indices. Value: `[%s]`.', join( dims, ', ' ) ) );\n\t}\n\tsr = st[ d[0] ];\n\tsc = st[ d[1] ];\n\n\t// Resolve the row and column offsets corresponding to the diagonal offset `k = column - row`:\n\tco = ( k > 0 ) ? k : 0;\n\tro = co - k;\n\n\t// Compute the length of the diagonal:\n\trows = sh[ d[0] ] - ro;\n\tcols = sh[ d[1] ] - co;\n\tL = min( rows, cols );\n\tif ( L < 0 ) {\n\t\tL = 0;\n\t}\n\n\t// Adjust the offset so that we point to the first element along the specified diagonal:\n\toffset = getOffset( x );\n\tif ( L > 0 ) {\n\t\toffset += ( co*sc ) + ( ro*sr );\n\t}\n\n\t// Drop the specified dimensions and append the diagonal dimension:\n\tshape = [];\n\tstrides = [];\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tif ( i === d[0] || i === d[1] ) {\n\t\t\tcontinue;\n\t\t}\n\t\tshape.push( sh[ i ] );\n\t\tstrides.push( st[ i ] );\n\t}\n\tshape.push( L );\n\tstrides.push( sr + sc );\n\n\treturn new x.constructor( getDType( x ), getData( x ), shape, strides, offset, getOrder( x ), { // eslint-disable-line max-len\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default diagonal;\n"],"names":["diagonal","x","dims","k","writable","strides","offset","ndims","shape","rows","cols","sh","st","sr","sc","ro","co","d","L","i","length","RangeError","format","join","getShape","getStrides","toUniqueNormalizedIndices","Error","min","getOffset","push","constructor","getDType","getData","getOrder","readonly"],"mappings":";;s8BAkEA,SAASA,EAAUC,EAAGC,EAAMC,EAAGC,GAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAqB,IAAhBjB,EAAKkB,OACT,MAAM,IAAIC,WAAYC,EAAQ,+EAAgFC,EAAMrB,EAAM,QAI3H,IADAK,GADAI,EAAKa,EAAUvB,IACJmB,QACE,EACZ,MAAM,IAAIC,WAAYC,EAAQ,+GAAgHf,IAM/I,GAJAK,EAAKa,EAAYxB,GAIN,QADXgB,EAAIS,EAA2BxB,EAAMK,EAAM,IAE1C,MAAM,IAAIc,WAAYC,EAAQ,mHAAoHf,EAAOA,EAAM,EAAGgB,EAAMrB,EAAM,QAE/K,GAAKe,EAAEG,SAAWlB,EAAKkB,OACtB,MAAM,IAAIO,MAAOL,EAAQ,0EAA2EC,EAAMrB,EAAM,QA0BjH,IAxBAW,EAAKD,EAAIK,EAAE,IACXH,EAAKF,EAAIK,EAAE,IAIXF,GADAC,EAAOb,EAAI,EAAMA,EAAI,GACXA,EAGVM,EAAOE,EAAIM,EAAE,IAAOF,EACpBL,EAAOC,EAAIM,EAAE,IAAOD,GACpBE,EAAIU,EAAKnB,EAAMC,IACN,IACRQ,EAAI,GAILZ,EAASuB,EAAW5B,GACfiB,EAAI,IACRZ,GAAYU,EAAGF,EAASC,EAAGF,GAI5BL,EAAQ,GACRH,EAAU,GACJc,EAAI,EAAGA,EAAIZ,EAAOY,IAClBA,IAAMF,EAAE,IAAME,IAAMF,EAAE,KAG3BT,EAAMsB,KAAMnB,EAAIQ,IAChBd,EAAQyB,KAAMlB,EAAIO,KAKnB,OAHAX,EAAMsB,KAAMZ,GACZb,EAAQyB,KAAMjB,EAAKC,GAEZ,IAAIb,EAAE8B,YAAaC,EAAU/B,GAAKgC,EAAShC,GAAKO,EAAOH,EAASC,EAAQ4B,EAAUjC,GAAK,CAC7FkC,UAAa/B,GAEf"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a541856..0000000 --- a/lib/index.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Return a view of the diagonal of a matrix (or stack of matrices). -* -* @module @stdlib/ndarray-base-diagonal -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var diagonal = require( '@stdlib/ndarray-base-diagonal' ); -* -* var x = array( [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] ); -* // returns [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] -* -* var y = diagonal( x, [ 0, 1 ], 0, false ); -* // returns [ 1.0, 5.0, 9.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 acf301d..0000000 --- a/lib/main.js +++ /dev/null @@ -1,144 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var toUniqueNormalizedIndices = require( '@stdlib/ndarray-base-to-unique-normalized-indices' ); -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); -var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var join = require( '@stdlib/array-base-join' ); -var min = require( '@stdlib/math-base-special-min' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns a view of the diagonal of a matrix (or stack of matrices). -* -* ## Notes -* -* - The order of the dimension indices contained in `dims` matters. The first element specifies the row-like dimension. The second element specifies the column-like dimension. -* - Each provided dimension index must reside on the interval `[-ndims, ndims-1]`. -* - The diagonal offset `k` is interpreted as `column - row`. Accordingly, when `k = 0`, the function returns the main diagonal; when `k > 0`, the function returns the diagonal above the main diagonal; and when `k < 0`, the function returns the diagonal below the main diagonal. -* - The returned ndarray is a **view** of the input ndarray. Accordingly, writing to the original ndarray will **mutate** the returned ndarray and vice versa. -* - The `writable` parameter **only** applies to ndarray constructors supporting **read-only** instances. -* -* @param {ndarray} x - input array -* @param {IntegerArray} dims - dimension indices defining the plane from which to extract the diagonal -* @param {integer} k - diagonal offset -* @param {boolean} writable - boolean indicating whether the returned ndarray should be writable -* @throws {RangeError} must provide exactly two dimension indices -* @throws {RangeError} must provide an ndarray having two or more dimensions -* @throws {RangeError} must provide valid dimension indices -* @throws {Error} must provide unique dimension indices -* @returns {ndarray} ndarray view -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] ); -* // returns [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] -* -* var y = diagonal( x, [ 0, 1 ], 0, false ); -* // returns [ 1.0, 5.0, 9.0 ] -*/ -function diagonal( x, dims, k, writable ) { - var strides; - var offset; - var ndims; - var shape; - var rows; - var cols; - var sh; - var st; - var sr; - var sc; - var ro; - var co; - var d; - var L; - var i; - - if ( dims.length !== 2 ) { - throw new RangeError( format( 'invalid argument. Must provide exactly two dimension indices. Value: `[%s]`.', join( dims, ', ' ) ) ); - } - sh = getShape( x ); - ndims = sh.length; - if ( ndims < 2 ) { - throw new RangeError( format( 'invalid argument. First argument must be an ndarray having two or more dimensions. Number of dimensions: %d.', ndims ) ); - } - st = getStrides( x ); - - // Resolve dimension indices... - d = toUniqueNormalizedIndices( dims, ndims-1 ); - if ( d === null ) { - throw new RangeError( format( 'invalid argument. Specified dimension index is out-of-bounds. Must be on the interval: [-%u, %u]. Value: `[%s]`.', ndims, ndims-1, join( dims, ', ' ) ) ); - } - if ( d.length !== dims.length ) { - throw new Error( format( 'invalid argument. Must provide unique dimension indices. Value: `[%s]`.', join( dims, ', ' ) ) ); - } - sr = st[ d[0] ]; - sc = st[ d[1] ]; - - // Resolve the row and column offsets corresponding to the diagonal offset `k = column - row`: - co = ( k > 0 ) ? k : 0; - ro = co - k; - - // Compute the length of the diagonal: - rows = sh[ d[0] ] - ro; - cols = sh[ d[1] ] - co; - L = min( rows, cols ); - if ( L < 0 ) { - L = 0; - } - - // Adjust the offset so that we point to the first element along the specified diagonal: - offset = getOffset( x ); - if ( L > 0 ) { - offset += ( co*sc ) + ( ro*sr ); - } - - // Drop the specified dimensions and append the diagonal dimension: - shape = []; - strides = []; - for ( i = 0; i < ndims; i++ ) { - if ( i === d[0] || i === d[1] ) { - continue; - } - shape.push( sh[ i ] ); - strides.push( st[ i ] ); - } - shape.push( L ); - strides.push( sr + sc ); - - return new x.constructor( getDType( x ), getData( x ), shape, strides, offset, getOrder( x ), { // eslint-disable-line max-len - 'readonly': !writable - }); -} - - -// EXPORTS // - -module.exports = diagonal; diff --git a/package.json b/package.json index 27c91df..1e256a2 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Return a view of the diagonal of a matrix (or stack of matrices).", "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,56 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-join": "^0.1.2", - "@stdlib/math-base-special-min": "^0.2.4", - "@stdlib/ndarray-base-data-buffer": "^0.2.3", - "@stdlib/ndarray-base-dtype": "^0.2.3", - "@stdlib/ndarray-base-offset": "^0.2.3", - "@stdlib/ndarray-base-order": "^0.2.3", - "@stdlib/ndarray-base-shape": "^0.2.3", - "@stdlib/ndarray-base-strides": "^0.2.3", - "@stdlib/ndarray-base-to-unique-normalized-indices": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.2.3", - "@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-data-buffer": "^0.2.3", - "@stdlib/ndarray-empty": "^0.3.1", - "@stdlib/ndarray-offset": "^0.2.3", - "@stdlib/ndarray-order": "^0.2.3", - "@stdlib/ndarray-shape": "^0.2.3", - "@stdlib/ndarray-stride": "^0.2.3", - "@stdlib/ndarray-strides": "^0.2.3", - "@stdlib/ndarray-to-array": "^0.2.2", - "@stdlib/random-uniform": "^0.1.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..ecc38ac --- /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 fabc8fa..0000000 --- a/test/test.js +++ /dev/null @@ -1,619 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var array = require( '@stdlib/ndarray-array' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var getStrides = require( '@stdlib/ndarray-strides' ); -var getStride = require( '@stdlib/ndarray-stride' ); -var getOffset = require( '@stdlib/ndarray-offset' ); -var getData = require( '@stdlib/ndarray-data-buffer' ); -var getOrder = require( '@stdlib/ndarray-order' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var diagonal = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof diagonal, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided exactly two dimension indices', function test( t ) { - var values; - var x; - var i; - - x = new ndarray( 'float64', new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); - - values = [ - [], - [ 0 ], - [ 0, 1, 0 ], - [ 0, 1, 0, 1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ].length + ' dimension indices' ); - } - t.end(); - - function badValue( dims ) { - return function badValue() { - diagonal( x, dims, 0, false ); - }; - } -}); - -tape( 'the function throws an error if provided an input ndarray with fewer than two dimensions', function test( t ) { - var values; - var i; - - values = [ - new ndarray( 'float64', new Float64Array( [ 5.0 ] ), [], [ 0 ], 0, 'row-major' ), - new ndarray( 'float64', new Float64Array( [ 1.0, 2.0, 3.0 ] ), [ 3 ], [ 1 ], 0, 'row-major' ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided an input ndarray with '+values[ i ].ndims+' dimensions' ); - } - t.end(); - - function badValue( x ) { - return function badValue() { - diagonal( x, [ 0, 1 ], 0, false ); - }; - } -}); - -tape( 'the function throws an error if provided out-of-bounds dimension indices', function test( t ) { - var values; - var x; - var i; - - x = new ndarray( 'float64', new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); - - values = [ - [ 0, 2 ], - [ 2, 0 ], - [ -3, 0 ], - [ 0, -3 ], - [ 10, 0 ], - [ 0, 10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided dimension indices ['+values[ i ]+']' ); - } - t.end(); - - function badValue( dims ) { - return function badValue() { - diagonal( x, dims, 0, false ); - }; - } -}); - -tape( 'the function throws an error if provided duplicate dimension indices', function test( t ) { - var values; - var x; - var i; - - x = new ndarray( 'float64', new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ), [ 2, 2, 2 ], [ 4, 2, 1 ], 0, 'row-major' ); - - values = [ - [ 0, 0 ], - [ 1, 1 ], - [ 2, 2 ], - [ 0, -3 ], - [ -2, 1 ], - [ -1, 2 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided dimension indices ['+values[ i ]+']' ); - } - t.end(); - - function badValue( dims ) { - return function badValue() { - diagonal( x, dims, 0, false ); - }; - } -}); - -tape( 'the function returns a view of the main diagonal of a square matrix', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); - - y = diagonal( x, [ 0, 1 ], 0, false ); - - expected = [ 3 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 1, 5, 9 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.strictEqual( getData( y ), getData( x ), 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of the super-diagonal of a square matrix', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); - - y = diagonal( x, [ 0, 1 ], 1, false ); - - expected = [ 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 2, 6 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], 2, false ); - - expected = [ 1 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 3 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of the sub-diagonal of a square matrix', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); - - y = diagonal( x, [ 0, 1 ], -1, false ); - - expected = [ 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 4, 8 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], -2, false ); - - expected = [ 1 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 7 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of the diagonal of a non-square matrix (M < N)', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ 1, 2, 3, 4 ], [ 5, 6, 7, 8 ] ] ); - - y = diagonal( x, [ 0, 1 ], 0, false ); - - expected = [ 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 1, 6 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], 2, false ); - - expected = [ 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 3, 8 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], -1, false ); - - expected = [ 1 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 5 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of the diagonal of a non-square matrix (M > N)', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ], [ 7, 8 ] ] ); - - y = diagonal( x, [ 0, 1 ], 0, false ); - - expected = [ 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 1, 4 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], -2, false ); - - expected = [ 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 5, 8 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], 1, false ); - - expected = [ 1 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 2 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an empty view when the diagonal offset is out-of-bounds', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); - - y = diagonal( x, [ 0, 1 ], 3, false ); - - expected = [ 0 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = []; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], -3, false ); - - expected = [ 0 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = []; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], 100, false ); - - expected = [ 0 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = []; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function swaps the row-like and column-like dimensions when `dims` is reversed', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); - - y = diagonal( x, [ 1, 0 ], 1, false ); - - expected = [ 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 4, 8 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 1, 0 ], -1, false ); - - expected = [ 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 2, 6 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of the diagonals of a stack of matrices', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); - - y = diagonal( x, [ 1, 2 ], 0, false ); - - expected = [ 2, 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ [ 1, 4 ], [ 5, 8 ] ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 1, 2 ], 1, false ); - - expected = [ 2, 1 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ [ 2 ], [ 6 ] ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 1, 2 ], -1, false ); - - expected = [ 2, 1 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ [ 3 ], [ 7 ] ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function appends the diagonal dimension as the trailing dimension of the output ndarray', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ [ 1, 2, 3 ], [ 4, 5, 6 ] ], [ [ 7, 8, 9 ], [ 10, 11, 12 ] ] ] ); - - y = diagonal( x, [ 0, 2 ], 0, false ); - - expected = [ 2, 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ [ 1, 8 ], [ 4, 11 ] ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function normalizes negative dimension indices', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); - - y = diagonal( x, [ -2, -1 ], 0, false ); - - expected = [ 3 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 1, 5, 9 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a column-major ndarray when the input ndarray is column-major', function test( t ) { - var expected; - var x; - var y; - - x = ndarray( 'generic', [ 1, 4, 7, 2, 5, 8, 3, 6, 9 ], [ 3, 3 ], [ 1, 3 ], 0, 'column-major' ); - - y = diagonal( x, [ 0, 1 ], 0, false ); - - expected = 'column-major'; - t.strictEqual( getOrder( y ), expected, 'returns expected value' ); - - expected = [ 3 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 1, 5, 9 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a writable ndarray when `writable` is `true`', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); - y = diagonal( x, [ 0, 1 ], 0, true ); - - t.strictEqual( isReadOnly( y ), false, 'returns expected value' ); - t.strictEqual( getData( y ), getData( x ), 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a read-only ndarray when `writable` is `false`', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); - y = diagonal( x, [ 0, 1 ], 0, false ); - - t.strictEqual( isReadOnly( y ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function constructs the output by retaining all dimensions except the specified dimensions and appending the diagonal dimension', function test( t ) { - var expected; - var x; - var y; - - x = array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ], { - 'shape': [ 3, 2, 2 ] - }); - - y = diagonal( x, [ 1, 2 ], 0, false ); - - expected = [ 3, 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 4, 3 ]; - t.deepEqual( getStrides( y ), expected, 'returns expected value' ); - - expected = getOffset( x ); - t.strictEqual( getOffset( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function adjusts the offset to point to the first element of the requested diagonal', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); - - y = diagonal( x, [ 0, 1 ], 1, false ); - - expected = getOffset( x ) + getStride( x, 1 ); - t.strictEqual( getOffset( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], -1, false ); - - expected = getOffset( x ) + getStride( x, 0 ); - t.strictEqual( getOffset( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports input ndarrays having a non-zero buffer offset', function test( t ) { - var expected; - var x; - var y; - - x = ndarray( 'generic', [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], [ 3, 3 ], [ 3, 1 ], 1, 'row-major' ); - - y = diagonal( x, [ 0, 1 ], 0, false ); - - expected = [ 3 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 1, 5, 9 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.strictEqual( getData( y ), getData( x ), 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], 1, false ); - - expected = [ 2, 6 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], -1, false ); - - expected = [ 4, 8 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports 4D inputs with non-trailing `dims`', function test( t ) { - var expected; - var arr; - var x; - var y; - - arr = [ - [ - [ - [ 0, 1 ], - [ 2, 3 ], - [ 4, 5 ] - ], - [ - [ 6, 7 ], - [ 8, 9 ], - [ 10, 11 ] - ], - [ - [ 12, 13 ], - [ 14, 15 ], - [ 16, 17 ] - ] - ], - [ - [ - [ 18, 19 ], - [ 20, 21 ], - [ 22, 23 ] - ], - [ - [ 24, 25 ], - [ 26, 27 ], - [ 28, 29 ] - ], - [ - [ 30, 31 ], - [ 32, 33 ], - [ 34, 35 ] - ] - ] - ]; - x = array( arr ); - y = diagonal( x, [ 1, 2 ], 0, false ); - expected = [ 2, 2, 3 ]; - - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ - [ - [ 0, 8, 16 ], - [ 1, 9, 17 ] - ], - [ - [ 18, 26, 34 ], - [ 19, 27, 35 ] - ] - ]; - - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - t.strictEqual( getData( y ), getData( x ), 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports negative dimension indices combined with a non-zero `k`', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); - y = diagonal( x, [ -2, -1 ], 1, false ); - - expected = [ 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 2, 6 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ -2, -1 ], -1, false ); - - expected = [ 4, 8 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); From 2e3a5769b4c5113922b7d30f4b0bf3a8e28755fa Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 27 Jun 2026 03:27:14 +0000 Subject: [PATCH 12/23] 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 a3666a6..acf301d 100644 --- a/lib/main.js +++ b/lib/main.js @@ -29,7 +29,7 @@ var getOrder = require( '@stdlib/ndarray-base-order' ); var getData = require( '@stdlib/ndarray-base-data-buffer' ); var join = require( '@stdlib/array-base-join' ); var min = require( '@stdlib/math-base-special-min' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // diff --git a/package.json b/package.json index 2e2a34b..3cdb2df 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/ndarray-base-shape": "^0.2.3", "@stdlib/ndarray-base-strides": "^0.2.3", "@stdlib/ndarray-base-to-unique-normalized-indices": "^0.1.1", - "@stdlib/string-format": "^0.2.3", + "@stdlib/error-tools-fmtprodmsg": "^0.2.3", "@stdlib/types": "^0.5.1", "@stdlib/error-tools-fmtprodmsg": "^0.2.3" }, From b7d361b73aabd6a3cb7a0d94b7123dabc755be77 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 27 Jun 2026 03:28:42 +0000 Subject: [PATCH 13/23] Remove files --- index.d.ts | 57 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4904 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 9e71468..0000000 --- a/index.d.ts +++ /dev/null @@ -1,57 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { Collection } from '@stdlib/types/array'; -import { typedndarray } from '@stdlib/types/ndarray'; - -/** -* Returns a view of the diagonal of a matrix (or stack of matrices). -* -* ## Notes -* -* - The order of the dimension indices contained in `dims` matters. The first element specifies the row-like dimension. The second element specifies the column-like dimension. -* - Each provided dimension index must reside on the interval `[-ndims, ndims-1]`. -* - The diagonal offset `k` is interpreted as `column - row`. Accordingly, when `k = 0`, the function returns the main diagonal; when `k > 0`, the function returns the diagonal above the main diagonal; and when `k < 0`, the function returns the diagonal below the main diagonal. -* - The returned ndarray is a **view** of the input ndarray. Accordingly, writing to the original ndarray will **mutate** the returned ndarray and vice versa. -* - The `writable` parameter **only** applies to ndarray constructors supporting **read-only** instances. -* -* @param x - input array -* @param dims - dimension indices defining the plane from which to extract the diagonal -* @param k - diagonal offset -* @param writable - boolean indicating whether the returned ndarray should be writable -* @returns ndarray view -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] ); -* // returns [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] -* -* var y = diagonal( x, [ 0, 1 ], 0, false ); -* // returns [ 1.0, 5.0, 9.0 ] -*/ -declare function diagonal = typedndarray>( x: U, dims: Collection, k: number, writable: boolean ): U; - - -// EXPORTS // - -export = diagonal; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 8e4e50f..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-to-unique-normalized-indices@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.3-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.3-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.3-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.3-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.3-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-join@v0.1.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-min@v0.2.4-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";function l(l,h,p,j){var u,v,f,b,g,c,x,y,w,E,M,R,V,q,z;if(2!==h.length)throw new RangeError(a("invalid argument. Must provide exactly two dimension indices. Value: `[%s]`.",o(h,", ")));if((f=(x=r(l)).length)<2)throw new RangeError(a("invalid argument. First argument must be an ndarray having two or more dimensions. Number of dimensions: %d.",f));if(y=n(l),null===(V=e(h,f-1)))throw new RangeError(a("invalid argument. Specified dimension index is out-of-bounds. Must be on the interval: [-%u, %u]. Value: `[%s]`.",f,f-1,o(h,", ")));if(V.length!==h.length)throw new Error(a("invalid argument. Must provide unique dimension indices. Value: `[%s]`.",o(h,", ")));for(w=y[V[0]],E=y[V[1]],M=(R=p>0?p:0)-p,g=x[V[0]]-M,c=x[V[1]]-R,(q=m(g,c))<0&&(q=0),v=t(l),q>0&&(v+=R*E+M*w),b=[],u=[],z=0;z 0`, the function returns the diagonal above the main diagonal; and when `k < 0`, the function returns the diagonal below the main diagonal.\n* - The returned ndarray is a **view** of the input ndarray. Accordingly, writing to the original ndarray will **mutate** the returned ndarray and vice versa.\n* - The `writable` parameter **only** applies to ndarray constructors supporting **read-only** instances.\n*\n* @param {ndarray} x - input array\n* @param {IntegerArray} dims - dimension indices defining the plane from which to extract the diagonal\n* @param {integer} k - diagonal offset\n* @param {boolean} writable - boolean indicating whether the returned ndarray should be writable\n* @throws {RangeError} must provide exactly two dimension indices\n* @throws {RangeError} must provide an ndarray having two or more dimensions\n* @throws {RangeError} must provide valid dimension indices\n* @throws {Error} must provide unique dimension indices\n* @returns {ndarray} ndarray view\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] );\n* // returns [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ]\n*\n* var y = diagonal( x, [ 0, 1 ], 0, false );\n* // returns [ 1.0, 5.0, 9.0 ]\n*/\nfunction diagonal( x, dims, k, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar ndims;\n\tvar shape;\n\tvar rows;\n\tvar cols;\n\tvar sh;\n\tvar st;\n\tvar sr;\n\tvar sc;\n\tvar ro;\n\tvar co;\n\tvar d;\n\tvar L;\n\tvar i;\n\n\tif ( dims.length !== 2 ) {\n\t\tthrow new RangeError( format( 'invalid argument. Must provide exactly two dimension indices. Value: `[%s]`.', join( dims, ', ' ) ) );\n\t}\n\tsh = getShape( x );\n\tndims = sh.length;\n\tif ( ndims < 2 ) {\n\t\tthrow new RangeError( format( 'invalid argument. First argument must be an ndarray having two or more dimensions. Number of dimensions: %d.', ndims ) );\n\t}\n\tst = getStrides( x );\n\n\t// Resolve dimension indices...\n\td = toUniqueNormalizedIndices( dims, ndims-1 );\n\tif ( d === null ) {\n\t\tthrow new RangeError( format( 'invalid argument. Specified dimension index is out-of-bounds. Must be on the interval: [-%u, %u]. Value: `[%s]`.', ndims, ndims-1, join( dims, ', ' ) ) );\n\t}\n\tif ( d.length !== dims.length ) {\n\t\tthrow new Error( format( 'invalid argument. Must provide unique dimension indices. Value: `[%s]`.', join( dims, ', ' ) ) );\n\t}\n\tsr = st[ d[0] ];\n\tsc = st[ d[1] ];\n\n\t// Resolve the row and column offsets corresponding to the diagonal offset `k = column - row`:\n\tco = ( k > 0 ) ? k : 0;\n\tro = co - k;\n\n\t// Compute the length of the diagonal:\n\trows = sh[ d[0] ] - ro;\n\tcols = sh[ d[1] ] - co;\n\tL = min( rows, cols );\n\tif ( L < 0 ) {\n\t\tL = 0;\n\t}\n\n\t// Adjust the offset so that we point to the first element along the specified diagonal:\n\toffset = getOffset( x );\n\tif ( L > 0 ) {\n\t\toffset += ( co*sc ) + ( ro*sr );\n\t}\n\n\t// Drop the specified dimensions and append the diagonal dimension:\n\tshape = [];\n\tstrides = [];\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tif ( i === d[0] || i === d[1] ) {\n\t\t\tcontinue;\n\t\t}\n\t\tshape.push( sh[ i ] );\n\t\tstrides.push( st[ i ] );\n\t}\n\tshape.push( L );\n\tstrides.push( sr + sc );\n\n\treturn new x.constructor( getDType( x ), getData( x ), shape, strides, offset, getOrder( x ), { // eslint-disable-line max-len\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default diagonal;\n"],"names":["diagonal","x","dims","k","writable","strides","offset","ndims","shape","rows","cols","sh","st","sr","sc","ro","co","d","L","i","length","RangeError","format","join","getShape","getStrides","toUniqueNormalizedIndices","Error","min","getOffset","push","constructor","getDType","getData","getOrder","readonly"],"mappings":";;s8BAkEA,SAASA,EAAUC,EAAGC,EAAMC,EAAGC,GAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAqB,IAAhBjB,EAAKkB,OACT,MAAM,IAAIC,WAAYC,EAAQ,+EAAgFC,EAAMrB,EAAM,QAI3H,IADAK,GADAI,EAAKa,EAAUvB,IACJmB,QACE,EACZ,MAAM,IAAIC,WAAYC,EAAQ,+GAAgHf,IAM/I,GAJAK,EAAKa,EAAYxB,GAIN,QADXgB,EAAIS,EAA2BxB,EAAMK,EAAM,IAE1C,MAAM,IAAIc,WAAYC,EAAQ,mHAAoHf,EAAOA,EAAM,EAAGgB,EAAMrB,EAAM,QAE/K,GAAKe,EAAEG,SAAWlB,EAAKkB,OACtB,MAAM,IAAIO,MAAOL,EAAQ,0EAA2EC,EAAMrB,EAAM,QA0BjH,IAxBAW,EAAKD,EAAIK,EAAE,IACXH,EAAKF,EAAIK,EAAE,IAIXF,GADAC,EAAOb,EAAI,EAAMA,EAAI,GACXA,EAGVM,EAAOE,EAAIM,EAAE,IAAOF,EACpBL,EAAOC,EAAIM,EAAE,IAAOD,GACpBE,EAAIU,EAAKnB,EAAMC,IACN,IACRQ,EAAI,GAILZ,EAASuB,EAAW5B,GACfiB,EAAI,IACRZ,GAAYU,EAAGF,EAASC,EAAGF,GAI5BL,EAAQ,GACRH,EAAU,GACJc,EAAI,EAAGA,EAAIZ,EAAOY,IAClBA,IAAMF,EAAE,IAAME,IAAMF,EAAE,KAG3BT,EAAMsB,KAAMnB,EAAIQ,IAChBd,EAAQyB,KAAMlB,EAAIO,KAKnB,OAHAX,EAAMsB,KAAMZ,GACZb,EAAQyB,KAAMjB,EAAKC,GAEZ,IAAIb,EAAE8B,YAAaC,EAAU/B,GAAKgC,EAAShC,GAAKO,EAAOH,EAASC,EAAQ4B,EAAUjC,GAAK,CAC7FkC,UAAa/B,GAEf"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index ecc38ac..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From aa4a3001a3b4a88d8da320eed2af630bc6521ea5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 27 Jun 2026 03:29:08 +0000 Subject: [PATCH 14/23] Auto-generated commit --- .editorconfig | 189 - .eslintrc.js | 1 - .gitattributes | 68 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 821 --- .github/workflows/publish.yml | 261 - .github/workflows/test.yml | 101 - .github/workflows/test_bundles.yml | 213 - .github/workflows/test_coverage.yml | 142 - .github/workflows/test_install.yml | 94 - .github/workflows/test_published_package.yml | 115 - .gitignore | 204 - .npmignore | 229 - .npmrc | 44 - CHANGELOG.md | 52 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 41 +- SECURITY.md | 5 - benchmark/benchmark.js | 272 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 51 - docs/types/test.ts | 92 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 44 - lib/main.js | 144 - package.json | 77 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 619 --- 44 files changed, 4866 insertions(+), 4936 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 (96%) 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 0fa7ca9..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2026-06-27T03:24:57.087Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 5dacce3..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/diagonal) 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 bbaa7c7..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/diagonal) 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 52ddcc8..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: '7 19 * * 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 + + ```
@@ -207,7 +198,7 @@ console.log( ndarray2array( y ) ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. 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 3a0a3bc..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,272 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var diagonal = require( './../lib' ); - - -// MAIN // - -bench( format( '%s::ndims=2,ctor=base', pkg ), function benchmark( b ) { - var values; - var v; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = diagonal( values[ i%values.length ], [ 0, 1 ], 0, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::ndims=2,ctor=non-base', pkg ), function benchmark( b ) { - var values; - var v; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - values = [ - empty( [ 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = diagonal( values[ i%values.length ], [ 0, 1 ], 0, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::ndims=3,ctor=base', pkg ), function benchmark( b ) { - var values; - var v; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = diagonal( values[ i%values.length ], [ 1, 2 ], 0, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::ndims=3,ctor=non-base', pkg ), function benchmark( b ) { - var values; - var v; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - values = [ - empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = diagonal( values[ i%values.length ], [ 1, 2 ], 0, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::ndims=4,ctor=base', pkg ), function benchmark( b ) { - var values; - var v; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = diagonal( values[ i%values.length ], [ 2, 3 ], 0, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::ndims=4,ctor=non-base', pkg ), function benchmark( b ) { - var values; - var v; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - values = [ - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = diagonal( values[ i%values.length ], [ 2, 3 ], 0, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::ndims=5,ctor=base', pkg ), function benchmark( b ) { - var values; - var v; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = diagonal( values[ i%values.length ], [ 3, 4 ], 0, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::ndims=5,ctor=non-base', pkg ), function benchmark( b ) { - var values; - var v; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - values = [ - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = diagonal( values[ i%values.length ], [ 3, 4 ], 0, false ); - if ( typeof v !== '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 437ecb7..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/diagonal" -%% click B href "https://github.com/stdlib-js/ndarray-base-diagonal/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-diagonal/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-diagonal/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-diagonal/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-diagonal/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/diagonal -[production-url]: https://github.com/stdlib-js/ndarray-base-diagonal/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-diagonal/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-diagonal/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-diagonal/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-diagonal/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-diagonal/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-diagonal/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 a7ab3b4..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import diagonal from '../docs/types/index'; -export = diagonal; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 4fab4ac..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var M=function(e,r){return function(){try{return r||e((r={exports:{}}).exports,r),r.exports}catch(t){throw (r=0, t)}};};var y=M(function(T,b){ -var R=require('@stdlib/ndarray-base-to-unique-normalized-indices/dist'),S=require('@stdlib/ndarray-base-dtype/dist'),V=require('@stdlib/ndarray-base-shape/dist'),D=require('@stdlib/ndarray-base-strides/dist'),N=require('@stdlib/ndarray-base-offset/dist'),O=require('@stdlib/ndarray-base-order/dist'),j=require('@stdlib/ndarray-base-data-buffer/dist'),q=require('@stdlib/array-base-join/dist'),z=require('@stdlib/math-base-special-min/dist'),l=require('@stdlib/error-tools-fmtprodmsg/dist');function F(e,r,t,E){var s,f,a,v,p,w,o,d,h,c,m,g,i,u,n;if(r.length!==2)throw new RangeError(l('2lXKM',q(r,", ")));if(o=V(e),a=o.length,a<2)throw new RangeError(l('2lXKN',a));if(d=D(e),i=R(r,a-1),i===null)throw new RangeError(l('2lXHO',a,a-1,q(r,", ")));if(i.length!==r.length)throw new Error(l('2lXHP',q(r,", ")));for(h=d[i[0]],c=d[i[1]],g=t>0?t:0,m=g-t,p=o[i[0]]-m,w=o[i[1]]-g,u=z(p,w),u<0&&(u=0),f=N(e),u>0&&(f+=g*c+m*h),v=[],s=[],n=0;n 0`, the function returns the diagonal above the main diagonal; and when `k < 0`, the function returns the diagonal below the main diagonal.\n* - The returned ndarray is a **view** of the input ndarray. Accordingly, writing to the original ndarray will **mutate** the returned ndarray and vice versa.\n* - The `writable` parameter **only** applies to ndarray constructors supporting **read-only** instances.\n*\n* @param {ndarray} x - input array\n* @param {IntegerArray} dims - dimension indices defining the plane from which to extract the diagonal\n* @param {integer} k - diagonal offset\n* @param {boolean} writable - boolean indicating whether the returned ndarray should be writable\n* @throws {RangeError} must provide exactly two dimension indices\n* @throws {RangeError} must provide an ndarray having two or more dimensions\n* @throws {RangeError} must provide valid dimension indices\n* @throws {Error} must provide unique dimension indices\n* @returns {ndarray} ndarray view\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] );\n* // returns [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ]\n*\n* var y = diagonal( x, [ 0, 1 ], 0, false );\n* // returns [ 1.0, 5.0, 9.0 ]\n*/\nfunction diagonal( x, dims, k, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar ndims;\n\tvar shape;\n\tvar rows;\n\tvar cols;\n\tvar sh;\n\tvar st;\n\tvar sr;\n\tvar sc;\n\tvar ro;\n\tvar co;\n\tvar d;\n\tvar L;\n\tvar i;\n\n\tif ( dims.length !== 2 ) {\n\t\tthrow new RangeError( format( 'invalid argument. Must provide exactly two dimension indices. Value: `[%s]`.', join( dims, ', ' ) ) );\n\t}\n\tsh = getShape( x );\n\tndims = sh.length;\n\tif ( ndims < 2 ) {\n\t\tthrow new RangeError( format( 'invalid argument. First argument must be an ndarray having two or more dimensions. Number of dimensions: %d.', ndims ) );\n\t}\n\tst = getStrides( x );\n\n\t// Resolve dimension indices...\n\td = toUniqueNormalizedIndices( dims, ndims-1 );\n\tif ( d === null ) {\n\t\tthrow new RangeError( format( 'invalid argument. Specified dimension index is out-of-bounds. Must be on the interval: [-%u, %u]. Value: `[%s]`.', ndims, ndims-1, join( dims, ', ' ) ) );\n\t}\n\tif ( d.length !== dims.length ) {\n\t\tthrow new Error( format( 'invalid argument. Must provide unique dimension indices. Value: `[%s]`.', join( dims, ', ' ) ) );\n\t}\n\tsr = st[ d[0] ];\n\tsc = st[ d[1] ];\n\n\t// Resolve the row and column offsets corresponding to the diagonal offset `k = column - row`:\n\tco = ( k > 0 ) ? k : 0;\n\tro = co - k;\n\n\t// Compute the length of the diagonal:\n\trows = sh[ d[0] ] - ro;\n\tcols = sh[ d[1] ] - co;\n\tL = min( rows, cols );\n\tif ( L < 0 ) {\n\t\tL = 0;\n\t}\n\n\t// Adjust the offset so that we point to the first element along the specified diagonal:\n\toffset = getOffset( x );\n\tif ( L > 0 ) {\n\t\toffset += ( co*sc ) + ( ro*sr );\n\t}\n\n\t// Drop the specified dimensions and append the diagonal dimension:\n\tshape = [];\n\tstrides = [];\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tif ( i === d[0] || i === d[1] ) {\n\t\t\tcontinue;\n\t\t}\n\t\tshape.push( sh[ i ] );\n\t\tstrides.push( st[ i ] );\n\t}\n\tshape.push( L );\n\tstrides.push( sr + sc );\n\n\treturn new x.constructor( getDType( x ), getData( x ), shape, strides, offset, getOrder( x ), { // eslint-disable-line max-len\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nmodule.exports = diagonal;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Return a view of the diagonal of a matrix (or stack of matrices).\n*\n* @module @stdlib/ndarray-base-diagonal\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var diagonal = require( '@stdlib/ndarray-base-diagonal' );\n*\n* var x = array( [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] );\n* // returns [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ]\n*\n* var y = diagonal( x, [ 0, 1 ], 0, false );\n* // returns [ 1.0, 5.0, 9.0 ]\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "iIAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAA4B,QAAS,mDAAoD,EACzFC,EAAW,QAAS,4BAA6B,EACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAa,QAAS,8BAA+B,EACrDC,EAAY,QAAS,6BAA8B,EACnDC,EAAW,QAAS,4BAA6B,EACjDC,EAAU,QAAS,kCAAmC,EACtDC,EAAO,QAAS,yBAA0B,EAC1CC,EAAM,QAAS,+BAAgC,EAC/CC,EAAS,QAAS,uBAAwB,EAmC9C,SAASC,EAAUC,EAAGC,EAAMC,EAAGC,EAAW,CACzC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAKjB,EAAK,SAAW,EACpB,MAAM,IAAI,WAAYH,EAAQ,+EAAgFF,EAAMK,EAAM,IAAK,CAAE,CAAE,EAIpI,GAFAS,EAAKnB,EAAUS,CAAE,EACjBM,EAAQI,EAAG,OACNJ,EAAQ,EACZ,MAAM,IAAI,WAAYR,EAAQ,+GAAgHQ,CAAM,CAAE,EAMvJ,GAJAK,EAAKnB,EAAYQ,CAAE,EAGnBgB,EAAI3B,EAA2BY,EAAMK,EAAM,CAAE,EACxCU,IAAM,KACV,MAAM,IAAI,WAAYlB,EAAQ,mHAAoHQ,EAAOA,EAAM,EAAGV,EAAMK,EAAM,IAAK,CAAE,CAAE,EAExL,GAAKe,EAAE,SAAWf,EAAK,OACtB,MAAM,IAAI,MAAOH,EAAQ,0EAA2EF,EAAMK,EAAM,IAAK,CAAE,CAAE,EA0B1H,IAxBAW,EAAKD,EAAIK,EAAE,CAAC,CAAE,EACdH,EAAKF,EAAIK,EAAE,CAAC,CAAE,EAGdD,EAAOb,EAAI,EAAMA,EAAI,EACrBY,EAAKC,EAAKb,EAGVM,EAAOE,EAAIM,EAAE,CAAC,CAAE,EAAIF,EACpBL,EAAOC,EAAIM,EAAE,CAAC,CAAE,EAAID,EACpBE,EAAIpB,EAAKW,EAAMC,CAAK,EACfQ,EAAI,IACRA,EAAI,GAILZ,EAASZ,EAAWO,CAAE,EACjBiB,EAAI,IACRZ,GAAYU,EAAGF,EAASC,EAAGF,GAI5BL,EAAQ,CAAC,EACTH,EAAU,CAAC,EACLc,EAAI,EAAGA,EAAIZ,EAAOY,IAClBA,IAAMF,EAAE,CAAC,GAAKE,IAAMF,EAAE,CAAC,IAG5BT,EAAM,KAAMG,EAAIQ,CAAE,CAAE,EACpBd,EAAQ,KAAMO,EAAIO,CAAE,CAAE,GAEvB,OAAAX,EAAM,KAAMU,CAAE,EACdb,EAAQ,KAAMQ,EAAKC,CAAG,EAEf,IAAIb,EAAE,YAAaV,EAAUU,CAAE,EAAGL,EAASK,CAAE,EAAGO,EAAOH,EAASC,EAAQX,EAAUM,CAAE,EAAG,CAC7F,SAAY,CAACG,CACd,CAAC,CACF,CAKAf,EAAO,QAAUW,ICzGjB,IAAIoB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "toUniqueNormalizedIndices", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "getData", "join", "min", "format", "diagonal", "x", "dims", "k", "writable", "strides", "offset", "ndims", "shape", "rows", "cols", "sh", "st", "sr", "sc", "ro", "co", "d", "L", "i", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index da74ae9..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,51 +0,0 @@ - -{{alias}}( x, dims, k, writable ) - Returns a view of the diagonal of a matrix (or stack of matrices). - - The order of the dimension indices contained in `dims` matters. The first - element specifies the row-like dimension. The second element specifies - the column-like dimension. - - Each provided dimension index must reside on the interval [-ndims, ndims-1]. - - The diagonal offset `k` is interpreted as `column - row`. Accordingly, - when `k = 0`, the function returns the main diagonal; when `k > 0`, the - function returns the diagonal above the main diagonal; and when `k < 0`, - the function returns the diagonal below the main diagonal. - - The returned ndarray is a *view* of the input ndarray. Accordingly, - writing to the original ndarray will mutate the returned ndarray and - vice versa. - - The `writable` parameter only applies to ndarray constructors supporting - read-only instances. - - Parameters - ---------- - x: ndarray - Input array. - - dims: ArrayLikeObject - Dimension indices defining the plane from which to extract the diagonal. - - k: integer - Diagonal offset. - - writable: boolean - Boolean indicating whether the returned ndarray should be writable. - - Returns - ------- - out: ndarray - Output array view. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ) - [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] - > var y = {{alias}}( x, [ 0, 1 ], 0, false ) - [ 1.0, 4.0 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 513a253..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,92 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 zeros = require( '@stdlib/ndarray-zeros' ); -import diagonal = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - - diagonal( x, [ 0, 1 ], 0, false ); // $ExpectType float64ndarray -} - -// The compiler throws an error if the function is not provided a first argument which is an ndarray... -{ - diagonal( '5', [ 0, 1 ], 0, false ); // $ExpectError - diagonal( 5, [ 0, 1 ], 0, false ); // $ExpectError - diagonal( true, [ 0, 1 ], 0, false ); // $ExpectError - diagonal( false, [ 0, 1 ], 0, false ); // $ExpectError - diagonal( null, [ 0, 1 ], 0, false ); // $ExpectError - diagonal( {}, [ 0, 1 ], 0, false ); // $ExpectError - diagonal( [ '5' ], [ 0, 1 ], 0, false ); // $ExpectError - diagonal( ( x: number ): number => x, [ 0, 1 ], 0, false ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a second argument which is an array-like object containing numbers... -{ - const x = zeros( [ 2, 2 ] ); - - diagonal( x, '5', 0, false ); // $ExpectError - diagonal( x, 5, 0, false ); // $ExpectError - diagonal( x, true, 0, false ); // $ExpectError - diagonal( x, false, 0, false ); // $ExpectError - diagonal( x, null, 0, false ); // $ExpectError - diagonal( x, {}, 0, false ); // $ExpectError - diagonal( x, [ '5' ], 0, false ); // $ExpectError - diagonal( x, ( x: number ): number => x, 0, false ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a third argument which is a number... -{ - const x = zeros( [ 2, 2 ] ); - - diagonal( x, [ 0, 1 ], '5', false ); // $ExpectError - diagonal( x, [ 0, 1 ], true, false ); // $ExpectError - diagonal( x, [ 0, 1 ], false, false ); // $ExpectError - diagonal( x, [ 0, 1 ], null, false ); // $ExpectError - diagonal( x, [ 0, 1 ], {}, false ); // $ExpectError - diagonal( x, [ 0, 1 ], [], false ); // $ExpectError - diagonal( x, [ 0, 1 ], ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a fourth argument which is a boolean... -{ - const x = zeros( [ 2, 2 ] ); - - diagonal( x, [ 0, 1 ], 0, '5' ); // $ExpectError - diagonal( x, [ 0, 1 ], 0, 5 ); // $ExpectError - diagonal( x, [ 0, 1 ], 0, null ); // $ExpectError - diagonal( x, [ 0, 1 ], 0, {} ); // $ExpectError - diagonal( x, [ 0, 1 ], 0, [] ); // $ExpectError - diagonal( x, [ 0, 1 ], 0, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = zeros( [ 2, 2 ] ); - - diagonal(); // $ExpectError - diagonal( x ); // $ExpectError - diagonal( x, [ 0, 1 ] ); // $ExpectError - diagonal( x, [ 0, 1 ], 0 ); // $ExpectError - diagonal( x, [ 0, 1 ], 0, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 742dc69..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 uniform = require( '@stdlib/random-uniform' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var diagonal = require( './../lib' ); - -// Create a stack of matrices: -var x = uniform( [ 2, 3, 3 ], -10.0, 10.0, { - 'dtype': 'float64' -}); -console.log( ndarray2array( x ) ); - -// Extract the main diagonals from the stack: -var y = diagonal( x, [ 1, 2 ], 0, false ); -console.log( ndarray2array( y ) ); - -// Extract super-diagonals from the stack: -y = diagonal( x, [ 1, 2 ], 1, false ); -console.log( ndarray2array( y ) ); - -// Extract sub-diagonals from the stack: -y = diagonal( x, [ 1, 2 ], -1, false ); -console.log( ndarray2array( y ) ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index 5ab7709..9e71468 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/array'; import { typedndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..8e4e50f --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-to-unique-normalized-indices@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.3-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.3-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.3-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.3-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.3-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-join@v0.1.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-min@v0.2.4-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";function l(l,h,p,j){var u,v,f,b,g,c,x,y,w,E,M,R,V,q,z;if(2!==h.length)throw new RangeError(a("invalid argument. Must provide exactly two dimension indices. Value: `[%s]`.",o(h,", ")));if((f=(x=r(l)).length)<2)throw new RangeError(a("invalid argument. First argument must be an ndarray having two or more dimensions. Number of dimensions: %d.",f));if(y=n(l),null===(V=e(h,f-1)))throw new RangeError(a("invalid argument. Specified dimension index is out-of-bounds. Must be on the interval: [-%u, %u]. Value: `[%s]`.",f,f-1,o(h,", ")));if(V.length!==h.length)throw new Error(a("invalid argument. Must provide unique dimension indices. Value: `[%s]`.",o(h,", ")));for(w=y[V[0]],E=y[V[1]],M=(R=p>0?p:0)-p,g=x[V[0]]-M,c=x[V[1]]-R,(q=m(g,c))<0&&(q=0),v=t(l),q>0&&(v+=R*E+M*w),b=[],u=[],z=0;z 0`, the function returns the diagonal above the main diagonal; and when `k < 0`, the function returns the diagonal below the main diagonal.\n* - The returned ndarray is a **view** of the input ndarray. Accordingly, writing to the original ndarray will **mutate** the returned ndarray and vice versa.\n* - The `writable` parameter **only** applies to ndarray constructors supporting **read-only** instances.\n*\n* @param {ndarray} x - input array\n* @param {IntegerArray} dims - dimension indices defining the plane from which to extract the diagonal\n* @param {integer} k - diagonal offset\n* @param {boolean} writable - boolean indicating whether the returned ndarray should be writable\n* @throws {RangeError} must provide exactly two dimension indices\n* @throws {RangeError} must provide an ndarray having two or more dimensions\n* @throws {RangeError} must provide valid dimension indices\n* @throws {Error} must provide unique dimension indices\n* @returns {ndarray} ndarray view\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] );\n* // returns [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ]\n*\n* var y = diagonal( x, [ 0, 1 ], 0, false );\n* // returns [ 1.0, 5.0, 9.0 ]\n*/\nfunction diagonal( x, dims, k, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar ndims;\n\tvar shape;\n\tvar rows;\n\tvar cols;\n\tvar sh;\n\tvar st;\n\tvar sr;\n\tvar sc;\n\tvar ro;\n\tvar co;\n\tvar d;\n\tvar L;\n\tvar i;\n\n\tif ( dims.length !== 2 ) {\n\t\tthrow new RangeError( format( 'invalid argument. Must provide exactly two dimension indices. Value: `[%s]`.', join( dims, ', ' ) ) );\n\t}\n\tsh = getShape( x );\n\tndims = sh.length;\n\tif ( ndims < 2 ) {\n\t\tthrow new RangeError( format( 'invalid argument. First argument must be an ndarray having two or more dimensions. Number of dimensions: %d.', ndims ) );\n\t}\n\tst = getStrides( x );\n\n\t// Resolve dimension indices...\n\td = toUniqueNormalizedIndices( dims, ndims-1 );\n\tif ( d === null ) {\n\t\tthrow new RangeError( format( 'invalid argument. Specified dimension index is out-of-bounds. Must be on the interval: [-%u, %u]. Value: `[%s]`.', ndims, ndims-1, join( dims, ', ' ) ) );\n\t}\n\tif ( d.length !== dims.length ) {\n\t\tthrow new Error( format( 'invalid argument. Must provide unique dimension indices. Value: `[%s]`.', join( dims, ', ' ) ) );\n\t}\n\tsr = st[ d[0] ];\n\tsc = st[ d[1] ];\n\n\t// Resolve the row and column offsets corresponding to the diagonal offset `k = column - row`:\n\tco = ( k > 0 ) ? k : 0;\n\tro = co - k;\n\n\t// Compute the length of the diagonal:\n\trows = sh[ d[0] ] - ro;\n\tcols = sh[ d[1] ] - co;\n\tL = min( rows, cols );\n\tif ( L < 0 ) {\n\t\tL = 0;\n\t}\n\n\t// Adjust the offset so that we point to the first element along the specified diagonal:\n\toffset = getOffset( x );\n\tif ( L > 0 ) {\n\t\toffset += ( co*sc ) + ( ro*sr );\n\t}\n\n\t// Drop the specified dimensions and append the diagonal dimension:\n\tshape = [];\n\tstrides = [];\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tif ( i === d[0] || i === d[1] ) {\n\t\t\tcontinue;\n\t\t}\n\t\tshape.push( sh[ i ] );\n\t\tstrides.push( st[ i ] );\n\t}\n\tshape.push( L );\n\tstrides.push( sr + sc );\n\n\treturn new x.constructor( getDType( x ), getData( x ), shape, strides, offset, getOrder( x ), { // eslint-disable-line max-len\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default diagonal;\n"],"names":["diagonal","x","dims","k","writable","strides","offset","ndims","shape","rows","cols","sh","st","sr","sc","ro","co","d","L","i","length","RangeError","format","join","getShape","getStrides","toUniqueNormalizedIndices","Error","min","getOffset","push","constructor","getDType","getData","getOrder","readonly"],"mappings":";;s8BAkEA,SAASA,EAAUC,EAAGC,EAAMC,EAAGC,GAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAqB,IAAhBjB,EAAKkB,OACT,MAAM,IAAIC,WAAYC,EAAQ,+EAAgFC,EAAMrB,EAAM,QAI3H,IADAK,GADAI,EAAKa,EAAUvB,IACJmB,QACE,EACZ,MAAM,IAAIC,WAAYC,EAAQ,+GAAgHf,IAM/I,GAJAK,EAAKa,EAAYxB,GAIN,QADXgB,EAAIS,EAA2BxB,EAAMK,EAAM,IAE1C,MAAM,IAAIc,WAAYC,EAAQ,mHAAoHf,EAAOA,EAAM,EAAGgB,EAAMrB,EAAM,QAE/K,GAAKe,EAAEG,SAAWlB,EAAKkB,OACtB,MAAM,IAAIO,MAAOL,EAAQ,0EAA2EC,EAAMrB,EAAM,QA0BjH,IAxBAW,EAAKD,EAAIK,EAAE,IACXH,EAAKF,EAAIK,EAAE,IAIXF,GADAC,EAAOb,EAAI,EAAMA,EAAI,GACXA,EAGVM,EAAOE,EAAIM,EAAE,IAAOF,EACpBL,EAAOC,EAAIM,EAAE,IAAOD,GACpBE,EAAIU,EAAKnB,EAAMC,IACN,IACRQ,EAAI,GAILZ,EAASuB,EAAW5B,GACfiB,EAAI,IACRZ,GAAYU,EAAGF,EAASC,EAAGF,GAI5BL,EAAQ,GACRH,EAAU,GACJc,EAAI,EAAGA,EAAIZ,EAAOY,IAClBA,IAAMF,EAAE,IAAME,IAAMF,EAAE,KAG3BT,EAAMsB,KAAMnB,EAAIQ,IAChBd,EAAQyB,KAAMlB,EAAIO,KAKnB,OAHAX,EAAMsB,KAAMZ,GACZb,EAAQyB,KAAMjB,EAAKC,GAEZ,IAAIb,EAAE8B,YAAaC,EAAU/B,GAAKgC,EAAShC,GAAKO,EAAOH,EAASC,EAAQ4B,EAAUjC,GAAK,CAC7FkC,UAAa/B,GAEf"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a541856..0000000 --- a/lib/index.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Return a view of the diagonal of a matrix (or stack of matrices). -* -* @module @stdlib/ndarray-base-diagonal -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var diagonal = require( '@stdlib/ndarray-base-diagonal' ); -* -* var x = array( [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] ); -* // returns [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] -* -* var y = diagonal( x, [ 0, 1 ], 0, false ); -* // returns [ 1.0, 5.0, 9.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 acf301d..0000000 --- a/lib/main.js +++ /dev/null @@ -1,144 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var toUniqueNormalizedIndices = require( '@stdlib/ndarray-base-to-unique-normalized-indices' ); -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); -var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var join = require( '@stdlib/array-base-join' ); -var min = require( '@stdlib/math-base-special-min' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns a view of the diagonal of a matrix (or stack of matrices). -* -* ## Notes -* -* - The order of the dimension indices contained in `dims` matters. The first element specifies the row-like dimension. The second element specifies the column-like dimension. -* - Each provided dimension index must reside on the interval `[-ndims, ndims-1]`. -* - The diagonal offset `k` is interpreted as `column - row`. Accordingly, when `k = 0`, the function returns the main diagonal; when `k > 0`, the function returns the diagonal above the main diagonal; and when `k < 0`, the function returns the diagonal below the main diagonal. -* - The returned ndarray is a **view** of the input ndarray. Accordingly, writing to the original ndarray will **mutate** the returned ndarray and vice versa. -* - The `writable` parameter **only** applies to ndarray constructors supporting **read-only** instances. -* -* @param {ndarray} x - input array -* @param {IntegerArray} dims - dimension indices defining the plane from which to extract the diagonal -* @param {integer} k - diagonal offset -* @param {boolean} writable - boolean indicating whether the returned ndarray should be writable -* @throws {RangeError} must provide exactly two dimension indices -* @throws {RangeError} must provide an ndarray having two or more dimensions -* @throws {RangeError} must provide valid dimension indices -* @throws {Error} must provide unique dimension indices -* @returns {ndarray} ndarray view -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] ); -* // returns [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] -* -* var y = diagonal( x, [ 0, 1 ], 0, false ); -* // returns [ 1.0, 5.0, 9.0 ] -*/ -function diagonal( x, dims, k, writable ) { - var strides; - var offset; - var ndims; - var shape; - var rows; - var cols; - var sh; - var st; - var sr; - var sc; - var ro; - var co; - var d; - var L; - var i; - - if ( dims.length !== 2 ) { - throw new RangeError( format( 'invalid argument. Must provide exactly two dimension indices. Value: `[%s]`.', join( dims, ', ' ) ) ); - } - sh = getShape( x ); - ndims = sh.length; - if ( ndims < 2 ) { - throw new RangeError( format( 'invalid argument. First argument must be an ndarray having two or more dimensions. Number of dimensions: %d.', ndims ) ); - } - st = getStrides( x ); - - // Resolve dimension indices... - d = toUniqueNormalizedIndices( dims, ndims-1 ); - if ( d === null ) { - throw new RangeError( format( 'invalid argument. Specified dimension index is out-of-bounds. Must be on the interval: [-%u, %u]. Value: `[%s]`.', ndims, ndims-1, join( dims, ', ' ) ) ); - } - if ( d.length !== dims.length ) { - throw new Error( format( 'invalid argument. Must provide unique dimension indices. Value: `[%s]`.', join( dims, ', ' ) ) ); - } - sr = st[ d[0] ]; - sc = st[ d[1] ]; - - // Resolve the row and column offsets corresponding to the diagonal offset `k = column - row`: - co = ( k > 0 ) ? k : 0; - ro = co - k; - - // Compute the length of the diagonal: - rows = sh[ d[0] ] - ro; - cols = sh[ d[1] ] - co; - L = min( rows, cols ); - if ( L < 0 ) { - L = 0; - } - - // Adjust the offset so that we point to the first element along the specified diagonal: - offset = getOffset( x ); - if ( L > 0 ) { - offset += ( co*sc ) + ( ro*sr ); - } - - // Drop the specified dimensions and append the diagonal dimension: - shape = []; - strides = []; - for ( i = 0; i < ndims; i++ ) { - if ( i === d[0] || i === d[1] ) { - continue; - } - shape.push( sh[ i ] ); - strides.push( st[ i ] ); - } - shape.push( L ); - strides.push( sr + sc ); - - return new x.constructor( getDType( x ), getData( x ), shape, strides, offset, getOrder( x ), { // eslint-disable-line max-len - 'readonly': !writable - }); -} - - -// EXPORTS // - -module.exports = diagonal; diff --git a/package.json b/package.json index 3cdb2df..1e256a2 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Return a view of the diagonal of a matrix (or stack of matrices).", "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,56 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-join": "^0.1.2", - "@stdlib/math-base-special-min": "^0.2.4", - "@stdlib/ndarray-base-data-buffer": "^0.2.3", - "@stdlib/ndarray-base-dtype": "^0.2.3", - "@stdlib/ndarray-base-offset": "^0.2.3", - "@stdlib/ndarray-base-order": "^0.2.3", - "@stdlib/ndarray-base-shape": "^0.2.3", - "@stdlib/ndarray-base-strides": "^0.2.3", - "@stdlib/ndarray-base-to-unique-normalized-indices": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3", - "@stdlib/types": "^0.5.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.2.3", - "@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-data-buffer": "^0.2.3", - "@stdlib/ndarray-empty": "^0.3.1", - "@stdlib/ndarray-offset": "^0.2.3", - "@stdlib/ndarray-order": "^0.2.3", - "@stdlib/ndarray-shape": "^0.2.3", - "@stdlib/ndarray-stride": "^0.2.3", - "@stdlib/ndarray-strides": "^0.2.3", - "@stdlib/ndarray-to-array": "^0.2.2", - "@stdlib/random-uniform": "^0.1.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..ecc38ac --- /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 fabc8fa..0000000 --- a/test/test.js +++ /dev/null @@ -1,619 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var array = require( '@stdlib/ndarray-array' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var getStrides = require( '@stdlib/ndarray-strides' ); -var getStride = require( '@stdlib/ndarray-stride' ); -var getOffset = require( '@stdlib/ndarray-offset' ); -var getData = require( '@stdlib/ndarray-data-buffer' ); -var getOrder = require( '@stdlib/ndarray-order' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var diagonal = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof diagonal, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided exactly two dimension indices', function test( t ) { - var values; - var x; - var i; - - x = new ndarray( 'float64', new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); - - values = [ - [], - [ 0 ], - [ 0, 1, 0 ], - [ 0, 1, 0, 1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ].length + ' dimension indices' ); - } - t.end(); - - function badValue( dims ) { - return function badValue() { - diagonal( x, dims, 0, false ); - }; - } -}); - -tape( 'the function throws an error if provided an input ndarray with fewer than two dimensions', function test( t ) { - var values; - var i; - - values = [ - new ndarray( 'float64', new Float64Array( [ 5.0 ] ), [], [ 0 ], 0, 'row-major' ), - new ndarray( 'float64', new Float64Array( [ 1.0, 2.0, 3.0 ] ), [ 3 ], [ 1 ], 0, 'row-major' ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided an input ndarray with '+values[ i ].ndims+' dimensions' ); - } - t.end(); - - function badValue( x ) { - return function badValue() { - diagonal( x, [ 0, 1 ], 0, false ); - }; - } -}); - -tape( 'the function throws an error if provided out-of-bounds dimension indices', function test( t ) { - var values; - var x; - var i; - - x = new ndarray( 'float64', new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); - - values = [ - [ 0, 2 ], - [ 2, 0 ], - [ -3, 0 ], - [ 0, -3 ], - [ 10, 0 ], - [ 0, 10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided dimension indices ['+values[ i ]+']' ); - } - t.end(); - - function badValue( dims ) { - return function badValue() { - diagonal( x, dims, 0, false ); - }; - } -}); - -tape( 'the function throws an error if provided duplicate dimension indices', function test( t ) { - var values; - var x; - var i; - - x = new ndarray( 'float64', new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ), [ 2, 2, 2 ], [ 4, 2, 1 ], 0, 'row-major' ); - - values = [ - [ 0, 0 ], - [ 1, 1 ], - [ 2, 2 ], - [ 0, -3 ], - [ -2, 1 ], - [ -1, 2 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided dimension indices ['+values[ i ]+']' ); - } - t.end(); - - function badValue( dims ) { - return function badValue() { - diagonal( x, dims, 0, false ); - }; - } -}); - -tape( 'the function returns a view of the main diagonal of a square matrix', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); - - y = diagonal( x, [ 0, 1 ], 0, false ); - - expected = [ 3 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 1, 5, 9 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.strictEqual( getData( y ), getData( x ), 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of the super-diagonal of a square matrix', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); - - y = diagonal( x, [ 0, 1 ], 1, false ); - - expected = [ 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 2, 6 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], 2, false ); - - expected = [ 1 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 3 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of the sub-diagonal of a square matrix', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); - - y = diagonal( x, [ 0, 1 ], -1, false ); - - expected = [ 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 4, 8 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], -2, false ); - - expected = [ 1 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 7 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of the diagonal of a non-square matrix (M < N)', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ 1, 2, 3, 4 ], [ 5, 6, 7, 8 ] ] ); - - y = diagonal( x, [ 0, 1 ], 0, false ); - - expected = [ 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 1, 6 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], 2, false ); - - expected = [ 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 3, 8 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], -1, false ); - - expected = [ 1 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 5 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of the diagonal of a non-square matrix (M > N)', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ], [ 7, 8 ] ] ); - - y = diagonal( x, [ 0, 1 ], 0, false ); - - expected = [ 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 1, 4 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], -2, false ); - - expected = [ 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 5, 8 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], 1, false ); - - expected = [ 1 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 2 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an empty view when the diagonal offset is out-of-bounds', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); - - y = diagonal( x, [ 0, 1 ], 3, false ); - - expected = [ 0 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = []; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], -3, false ); - - expected = [ 0 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = []; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], 100, false ); - - expected = [ 0 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = []; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function swaps the row-like and column-like dimensions when `dims` is reversed', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); - - y = diagonal( x, [ 1, 0 ], 1, false ); - - expected = [ 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 4, 8 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 1, 0 ], -1, false ); - - expected = [ 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 2, 6 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of the diagonals of a stack of matrices', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); - - y = diagonal( x, [ 1, 2 ], 0, false ); - - expected = [ 2, 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ [ 1, 4 ], [ 5, 8 ] ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 1, 2 ], 1, false ); - - expected = [ 2, 1 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ [ 2 ], [ 6 ] ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 1, 2 ], -1, false ); - - expected = [ 2, 1 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ [ 3 ], [ 7 ] ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function appends the diagonal dimension as the trailing dimension of the output ndarray', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ [ 1, 2, 3 ], [ 4, 5, 6 ] ], [ [ 7, 8, 9 ], [ 10, 11, 12 ] ] ] ); - - y = diagonal( x, [ 0, 2 ], 0, false ); - - expected = [ 2, 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ [ 1, 8 ], [ 4, 11 ] ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function normalizes negative dimension indices', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); - - y = diagonal( x, [ -2, -1 ], 0, false ); - - expected = [ 3 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 1, 5, 9 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a column-major ndarray when the input ndarray is column-major', function test( t ) { - var expected; - var x; - var y; - - x = ndarray( 'generic', [ 1, 4, 7, 2, 5, 8, 3, 6, 9 ], [ 3, 3 ], [ 1, 3 ], 0, 'column-major' ); - - y = diagonal( x, [ 0, 1 ], 0, false ); - - expected = 'column-major'; - t.strictEqual( getOrder( y ), expected, 'returns expected value' ); - - expected = [ 3 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 1, 5, 9 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a writable ndarray when `writable` is `true`', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); - y = diagonal( x, [ 0, 1 ], 0, true ); - - t.strictEqual( isReadOnly( y ), false, 'returns expected value' ); - t.strictEqual( getData( y ), getData( x ), 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a read-only ndarray when `writable` is `false`', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); - y = diagonal( x, [ 0, 1 ], 0, false ); - - t.strictEqual( isReadOnly( y ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function constructs the output by retaining all dimensions except the specified dimensions and appending the diagonal dimension', function test( t ) { - var expected; - var x; - var y; - - x = array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ], { - 'shape': [ 3, 2, 2 ] - }); - - y = diagonal( x, [ 1, 2 ], 0, false ); - - expected = [ 3, 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 4, 3 ]; - t.deepEqual( getStrides( y ), expected, 'returns expected value' ); - - expected = getOffset( x ); - t.strictEqual( getOffset( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function adjusts the offset to point to the first element of the requested diagonal', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); - - y = diagonal( x, [ 0, 1 ], 1, false ); - - expected = getOffset( x ) + getStride( x, 1 ); - t.strictEqual( getOffset( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], -1, false ); - - expected = getOffset( x ) + getStride( x, 0 ); - t.strictEqual( getOffset( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports input ndarrays having a non-zero buffer offset', function test( t ) { - var expected; - var x; - var y; - - x = ndarray( 'generic', [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], [ 3, 3 ], [ 3, 1 ], 1, 'row-major' ); - - y = diagonal( x, [ 0, 1 ], 0, false ); - - expected = [ 3 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 1, 5, 9 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.strictEqual( getData( y ), getData( x ), 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], 1, false ); - - expected = [ 2, 6 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], -1, false ); - - expected = [ 4, 8 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports 4D inputs with non-trailing `dims`', function test( t ) { - var expected; - var arr; - var x; - var y; - - arr = [ - [ - [ - [ 0, 1 ], - [ 2, 3 ], - [ 4, 5 ] - ], - [ - [ 6, 7 ], - [ 8, 9 ], - [ 10, 11 ] - ], - [ - [ 12, 13 ], - [ 14, 15 ], - [ 16, 17 ] - ] - ], - [ - [ - [ 18, 19 ], - [ 20, 21 ], - [ 22, 23 ] - ], - [ - [ 24, 25 ], - [ 26, 27 ], - [ 28, 29 ] - ], - [ - [ 30, 31 ], - [ 32, 33 ], - [ 34, 35 ] - ] - ] - ]; - x = array( arr ); - y = diagonal( x, [ 1, 2 ], 0, false ); - expected = [ 2, 2, 3 ]; - - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ - [ - [ 0, 8, 16 ], - [ 1, 9, 17 ] - ], - [ - [ 18, 26, 34 ], - [ 19, 27, 35 ] - ] - ]; - - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - t.strictEqual( getData( y ), getData( x ), 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports negative dimension indices combined with a non-zero `k`', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); - y = diagonal( x, [ -2, -1 ], 1, false ); - - expected = [ 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 2, 6 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ -2, -1 ], -1, false ); - - expected = [ 4, 8 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); From 50ef81b119550922bb76527417483fc9f6cd9de4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 9 Aug 2026 03:12:44 +0000 Subject: [PATCH 15/23] 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 a3666a6..acf301d 100644 --- a/lib/main.js +++ b/lib/main.js @@ -29,7 +29,7 @@ var getOrder = require( '@stdlib/ndarray-base-order' ); var getData = require( '@stdlib/ndarray-base-data-buffer' ); var join = require( '@stdlib/array-base-join' ); var min = require( '@stdlib/math-base-special-min' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // diff --git a/package.json b/package.json index 2e2a34b..3cdb2df 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/ndarray-base-shape": "^0.2.3", "@stdlib/ndarray-base-strides": "^0.2.3", "@stdlib/ndarray-base-to-unique-normalized-indices": "^0.1.1", - "@stdlib/string-format": "^0.2.3", + "@stdlib/error-tools-fmtprodmsg": "^0.2.3", "@stdlib/types": "^0.5.1", "@stdlib/error-tools-fmtprodmsg": "^0.2.3" }, From 6a1fcf2877a7431123d027c3ab3a3aa1b4d4ce33 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 9 Aug 2026 03:29:56 +0000 Subject: [PATCH 16/23] Remove files --- index.d.ts | 57 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4904 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 9e71468..0000000 --- a/index.d.ts +++ /dev/null @@ -1,57 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { Collection } from '@stdlib/types/array'; -import { typedndarray } from '@stdlib/types/ndarray'; - -/** -* Returns a view of the diagonal of a matrix (or stack of matrices). -* -* ## Notes -* -* - The order of the dimension indices contained in `dims` matters. The first element specifies the row-like dimension. The second element specifies the column-like dimension. -* - Each provided dimension index must reside on the interval `[-ndims, ndims-1]`. -* - The diagonal offset `k` is interpreted as `column - row`. Accordingly, when `k = 0`, the function returns the main diagonal; when `k > 0`, the function returns the diagonal above the main diagonal; and when `k < 0`, the function returns the diagonal below the main diagonal. -* - The returned ndarray is a **view** of the input ndarray. Accordingly, writing to the original ndarray will **mutate** the returned ndarray and vice versa. -* - The `writable` parameter **only** applies to ndarray constructors supporting **read-only** instances. -* -* @param x - input array -* @param dims - dimension indices defining the plane from which to extract the diagonal -* @param k - diagonal offset -* @param writable - boolean indicating whether the returned ndarray should be writable -* @returns ndarray view -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] ); -* // returns [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] -* -* var y = diagonal( x, [ 0, 1 ], 0, false ); -* // returns [ 1.0, 5.0, 9.0 ] -*/ -declare function diagonal = typedndarray>( x: U, dims: Collection, k: number, writable: boolean ): U; - - -// EXPORTS // - -export = diagonal; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 8e4e50f..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-to-unique-normalized-indices@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.3-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.3-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.3-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.3-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.3-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-join@v0.1.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-min@v0.2.4-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";function l(l,h,p,j){var u,v,f,b,g,c,x,y,w,E,M,R,V,q,z;if(2!==h.length)throw new RangeError(a("invalid argument. Must provide exactly two dimension indices. Value: `[%s]`.",o(h,", ")));if((f=(x=r(l)).length)<2)throw new RangeError(a("invalid argument. First argument must be an ndarray having two or more dimensions. Number of dimensions: %d.",f));if(y=n(l),null===(V=e(h,f-1)))throw new RangeError(a("invalid argument. Specified dimension index is out-of-bounds. Must be on the interval: [-%u, %u]. Value: `[%s]`.",f,f-1,o(h,", ")));if(V.length!==h.length)throw new Error(a("invalid argument. Must provide unique dimension indices. Value: `[%s]`.",o(h,", ")));for(w=y[V[0]],E=y[V[1]],M=(R=p>0?p:0)-p,g=x[V[0]]-M,c=x[V[1]]-R,(q=m(g,c))<0&&(q=0),v=t(l),q>0&&(v+=R*E+M*w),b=[],u=[],z=0;z 0`, the function returns the diagonal above the main diagonal; and when `k < 0`, the function returns the diagonal below the main diagonal.\n* - The returned ndarray is a **view** of the input ndarray. Accordingly, writing to the original ndarray will **mutate** the returned ndarray and vice versa.\n* - The `writable` parameter **only** applies to ndarray constructors supporting **read-only** instances.\n*\n* @param {ndarray} x - input array\n* @param {IntegerArray} dims - dimension indices defining the plane from which to extract the diagonal\n* @param {integer} k - diagonal offset\n* @param {boolean} writable - boolean indicating whether the returned ndarray should be writable\n* @throws {RangeError} must provide exactly two dimension indices\n* @throws {RangeError} must provide an ndarray having two or more dimensions\n* @throws {RangeError} must provide valid dimension indices\n* @throws {Error} must provide unique dimension indices\n* @returns {ndarray} ndarray view\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] );\n* // returns [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ]\n*\n* var y = diagonal( x, [ 0, 1 ], 0, false );\n* // returns [ 1.0, 5.0, 9.0 ]\n*/\nfunction diagonal( x, dims, k, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar ndims;\n\tvar shape;\n\tvar rows;\n\tvar cols;\n\tvar sh;\n\tvar st;\n\tvar sr;\n\tvar sc;\n\tvar ro;\n\tvar co;\n\tvar d;\n\tvar L;\n\tvar i;\n\n\tif ( dims.length !== 2 ) {\n\t\tthrow new RangeError( format( 'invalid argument. Must provide exactly two dimension indices. Value: `[%s]`.', join( dims, ', ' ) ) );\n\t}\n\tsh = getShape( x );\n\tndims = sh.length;\n\tif ( ndims < 2 ) {\n\t\tthrow new RangeError( format( 'invalid argument. First argument must be an ndarray having two or more dimensions. Number of dimensions: %d.', ndims ) );\n\t}\n\tst = getStrides( x );\n\n\t// Resolve dimension indices...\n\td = toUniqueNormalizedIndices( dims, ndims-1 );\n\tif ( d === null ) {\n\t\tthrow new RangeError( format( 'invalid argument. Specified dimension index is out-of-bounds. Must be on the interval: [-%u, %u]. Value: `[%s]`.', ndims, ndims-1, join( dims, ', ' ) ) );\n\t}\n\tif ( d.length !== dims.length ) {\n\t\tthrow new Error( format( 'invalid argument. Must provide unique dimension indices. Value: `[%s]`.', join( dims, ', ' ) ) );\n\t}\n\tsr = st[ d[0] ];\n\tsc = st[ d[1] ];\n\n\t// Resolve the row and column offsets corresponding to the diagonal offset `k = column - row`:\n\tco = ( k > 0 ) ? k : 0;\n\tro = co - k;\n\n\t// Compute the length of the diagonal:\n\trows = sh[ d[0] ] - ro;\n\tcols = sh[ d[1] ] - co;\n\tL = min( rows, cols );\n\tif ( L < 0 ) {\n\t\tL = 0;\n\t}\n\n\t// Adjust the offset so that we point to the first element along the specified diagonal:\n\toffset = getOffset( x );\n\tif ( L > 0 ) {\n\t\toffset += ( co*sc ) + ( ro*sr );\n\t}\n\n\t// Drop the specified dimensions and append the diagonal dimension:\n\tshape = [];\n\tstrides = [];\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tif ( i === d[0] || i === d[1] ) {\n\t\t\tcontinue;\n\t\t}\n\t\tshape.push( sh[ i ] );\n\t\tstrides.push( st[ i ] );\n\t}\n\tshape.push( L );\n\tstrides.push( sr + sc );\n\n\treturn new x.constructor( getDType( x ), getData( x ), shape, strides, offset, getOrder( x ), { // eslint-disable-line max-len\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default diagonal;\n"],"names":["diagonal","x","dims","k","writable","strides","offset","ndims","shape","rows","cols","sh","st","sr","sc","ro","co","d","L","i","length","RangeError","format","join","getShape","getStrides","toUniqueNormalizedIndices","Error","min","getOffset","push","constructor","getDType","getData","getOrder","readonly"],"mappings":";;s8BAkEA,SAASA,EAAUC,EAAGC,EAAMC,EAAGC,GAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAqB,IAAhBjB,EAAKkB,OACT,MAAM,IAAIC,WAAYC,EAAQ,+EAAgFC,EAAMrB,EAAM,QAI3H,IADAK,GADAI,EAAKa,EAAUvB,IACJmB,QACE,EACZ,MAAM,IAAIC,WAAYC,EAAQ,+GAAgHf,IAM/I,GAJAK,EAAKa,EAAYxB,GAIN,QADXgB,EAAIS,EAA2BxB,EAAMK,EAAM,IAE1C,MAAM,IAAIc,WAAYC,EAAQ,mHAAoHf,EAAOA,EAAM,EAAGgB,EAAMrB,EAAM,QAE/K,GAAKe,EAAEG,SAAWlB,EAAKkB,OACtB,MAAM,IAAIO,MAAOL,EAAQ,0EAA2EC,EAAMrB,EAAM,QA0BjH,IAxBAW,EAAKD,EAAIK,EAAE,IACXH,EAAKF,EAAIK,EAAE,IAIXF,GADAC,EAAOb,EAAI,EAAMA,EAAI,GACXA,EAGVM,EAAOE,EAAIM,EAAE,IAAOF,EACpBL,EAAOC,EAAIM,EAAE,IAAOD,GACpBE,EAAIU,EAAKnB,EAAMC,IACN,IACRQ,EAAI,GAILZ,EAASuB,EAAW5B,GACfiB,EAAI,IACRZ,GAAYU,EAAGF,EAASC,EAAGF,GAI5BL,EAAQ,GACRH,EAAU,GACJc,EAAI,EAAGA,EAAIZ,EAAOY,IAClBA,IAAMF,EAAE,IAAME,IAAMF,EAAE,KAG3BT,EAAMsB,KAAMnB,EAAIQ,IAChBd,EAAQyB,KAAMlB,EAAIO,KAKnB,OAHAX,EAAMsB,KAAMZ,GACZb,EAAQyB,KAAMjB,EAAKC,GAEZ,IAAIb,EAAE8B,YAAaC,EAAU/B,GAAKgC,EAAShC,GAAKO,EAAOH,EAASC,EAAQ4B,EAAUjC,GAAK,CAC7FkC,UAAa/B,GAEf"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index ecc38ac..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 10880d1498843044fe7f42c391bde6fd367e0bc6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 9 Aug 2026 03:30:25 +0000 Subject: [PATCH 17/23] Auto-generated commit --- .editorconfig | 189 - .eslintrc.js | 1 - .gitattributes | 68 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 821 --- .github/workflows/publish.yml | 261 - .github/workflows/test.yml | 101 - .github/workflows/test_bundles.yml | 213 - .github/workflows/test_coverage.yml | 142 - .github/workflows/test_install.yml | 94 - .github/workflows/test_published_package.yml | 115 - .gitignore | 204 - .npmignore | 229 - .npmrc | 44 - CHANGELOG.md | 52 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 41 +- SECURITY.md | 5 - benchmark/benchmark.js | 272 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 51 - docs/types/test.ts | 92 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 44 - lib/main.js | 144 - package.json | 77 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 619 --- 44 files changed, 4866 insertions(+), 4936 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 (96%) 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 653cdc3..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2026-08-09T03:06:21.122Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 5dacce3..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/diagonal) 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 bbaa7c7..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/diagonal) 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 52ddcc8..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: '7 19 * * 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 + + ```
@@ -207,7 +198,7 @@ console.log( ndarray2array( y ) ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. 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 3a0a3bc..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,272 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var diagonal = require( './../lib' ); - - -// MAIN // - -bench( format( '%s::ndims=2,ctor=base', pkg ), function benchmark( b ) { - var values; - var v; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = diagonal( values[ i%values.length ], [ 0, 1 ], 0, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::ndims=2,ctor=non-base', pkg ), function benchmark( b ) { - var values; - var v; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - values = [ - empty( [ 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = diagonal( values[ i%values.length ], [ 0, 1 ], 0, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::ndims=3,ctor=base', pkg ), function benchmark( b ) { - var values; - var v; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = diagonal( values[ i%values.length ], [ 1, 2 ], 0, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::ndims=3,ctor=non-base', pkg ), function benchmark( b ) { - var values; - var v; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - values = [ - empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = diagonal( values[ i%values.length ], [ 1, 2 ], 0, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::ndims=4,ctor=base', pkg ), function benchmark( b ) { - var values; - var v; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = diagonal( values[ i%values.length ], [ 2, 3 ], 0, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::ndims=4,ctor=non-base', pkg ), function benchmark( b ) { - var values; - var v; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - values = [ - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = diagonal( values[ i%values.length ], [ 2, 3 ], 0, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::ndims=5,ctor=base', pkg ), function benchmark( b ) { - var values; - var v; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = diagonal( values[ i%values.length ], [ 3, 4 ], 0, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::ndims=5,ctor=non-base', pkg ), function benchmark( b ) { - var values; - var v; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - values = [ - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = diagonal( values[ i%values.length ], [ 3, 4 ], 0, false ); - if ( typeof v !== '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 437ecb7..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/diagonal" -%% click B href "https://github.com/stdlib-js/ndarray-base-diagonal/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-diagonal/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-diagonal/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-diagonal/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-diagonal/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/diagonal -[production-url]: https://github.com/stdlib-js/ndarray-base-diagonal/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-diagonal/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-diagonal/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-diagonal/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-diagonal/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-diagonal/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-diagonal/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 a7ab3b4..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import diagonal from '../docs/types/index'; -export = diagonal; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 4fab4ac..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var M=function(e,r){return function(){try{return r||e((r={exports:{}}).exports,r),r.exports}catch(t){throw (r=0, t)}};};var y=M(function(T,b){ -var R=require('@stdlib/ndarray-base-to-unique-normalized-indices/dist'),S=require('@stdlib/ndarray-base-dtype/dist'),V=require('@stdlib/ndarray-base-shape/dist'),D=require('@stdlib/ndarray-base-strides/dist'),N=require('@stdlib/ndarray-base-offset/dist'),O=require('@stdlib/ndarray-base-order/dist'),j=require('@stdlib/ndarray-base-data-buffer/dist'),q=require('@stdlib/array-base-join/dist'),z=require('@stdlib/math-base-special-min/dist'),l=require('@stdlib/error-tools-fmtprodmsg/dist');function F(e,r,t,E){var s,f,a,v,p,w,o,d,h,c,m,g,i,u,n;if(r.length!==2)throw new RangeError(l('2lXKM',q(r,", ")));if(o=V(e),a=o.length,a<2)throw new RangeError(l('2lXKN',a));if(d=D(e),i=R(r,a-1),i===null)throw new RangeError(l('2lXHO',a,a-1,q(r,", ")));if(i.length!==r.length)throw new Error(l('2lXHP',q(r,", ")));for(h=d[i[0]],c=d[i[1]],g=t>0?t:0,m=g-t,p=o[i[0]]-m,w=o[i[1]]-g,u=z(p,w),u<0&&(u=0),f=N(e),u>0&&(f+=g*c+m*h),v=[],s=[],n=0;n 0`, the function returns the diagonal above the main diagonal; and when `k < 0`, the function returns the diagonal below the main diagonal.\n* - The returned ndarray is a **view** of the input ndarray. Accordingly, writing to the original ndarray will **mutate** the returned ndarray and vice versa.\n* - The `writable` parameter **only** applies to ndarray constructors supporting **read-only** instances.\n*\n* @param {ndarray} x - input array\n* @param {IntegerArray} dims - dimension indices defining the plane from which to extract the diagonal\n* @param {integer} k - diagonal offset\n* @param {boolean} writable - boolean indicating whether the returned ndarray should be writable\n* @throws {RangeError} must provide exactly two dimension indices\n* @throws {RangeError} must provide an ndarray having two or more dimensions\n* @throws {RangeError} must provide valid dimension indices\n* @throws {Error} must provide unique dimension indices\n* @returns {ndarray} ndarray view\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] );\n* // returns [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ]\n*\n* var y = diagonal( x, [ 0, 1 ], 0, false );\n* // returns [ 1.0, 5.0, 9.0 ]\n*/\nfunction diagonal( x, dims, k, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar ndims;\n\tvar shape;\n\tvar rows;\n\tvar cols;\n\tvar sh;\n\tvar st;\n\tvar sr;\n\tvar sc;\n\tvar ro;\n\tvar co;\n\tvar d;\n\tvar L;\n\tvar i;\n\n\tif ( dims.length !== 2 ) {\n\t\tthrow new RangeError( format( 'invalid argument. Must provide exactly two dimension indices. Value: `[%s]`.', join( dims, ', ' ) ) );\n\t}\n\tsh = getShape( x );\n\tndims = sh.length;\n\tif ( ndims < 2 ) {\n\t\tthrow new RangeError( format( 'invalid argument. First argument must be an ndarray having two or more dimensions. Number of dimensions: %d.', ndims ) );\n\t}\n\tst = getStrides( x );\n\n\t// Resolve dimension indices...\n\td = toUniqueNormalizedIndices( dims, ndims-1 );\n\tif ( d === null ) {\n\t\tthrow new RangeError( format( 'invalid argument. Specified dimension index is out-of-bounds. Must be on the interval: [-%u, %u]. Value: `[%s]`.', ndims, ndims-1, join( dims, ', ' ) ) );\n\t}\n\tif ( d.length !== dims.length ) {\n\t\tthrow new Error( format( 'invalid argument. Must provide unique dimension indices. Value: `[%s]`.', join( dims, ', ' ) ) );\n\t}\n\tsr = st[ d[0] ];\n\tsc = st[ d[1] ];\n\n\t// Resolve the row and column offsets corresponding to the diagonal offset `k = column - row`:\n\tco = ( k > 0 ) ? k : 0;\n\tro = co - k;\n\n\t// Compute the length of the diagonal:\n\trows = sh[ d[0] ] - ro;\n\tcols = sh[ d[1] ] - co;\n\tL = min( rows, cols );\n\tif ( L < 0 ) {\n\t\tL = 0;\n\t}\n\n\t// Adjust the offset so that we point to the first element along the specified diagonal:\n\toffset = getOffset( x );\n\tif ( L > 0 ) {\n\t\toffset += ( co*sc ) + ( ro*sr );\n\t}\n\n\t// Drop the specified dimensions and append the diagonal dimension:\n\tshape = [];\n\tstrides = [];\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tif ( i === d[0] || i === d[1] ) {\n\t\t\tcontinue;\n\t\t}\n\t\tshape.push( sh[ i ] );\n\t\tstrides.push( st[ i ] );\n\t}\n\tshape.push( L );\n\tstrides.push( sr + sc );\n\n\treturn new x.constructor( getDType( x ), getData( x ), shape, strides, offset, getOrder( x ), { // eslint-disable-line max-len\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nmodule.exports = diagonal;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Return a view of the diagonal of a matrix (or stack of matrices).\n*\n* @module @stdlib/ndarray-base-diagonal\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var diagonal = require( '@stdlib/ndarray-base-diagonal' );\n*\n* var x = array( [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] );\n* // returns [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ]\n*\n* var y = diagonal( x, [ 0, 1 ], 0, false );\n* // returns [ 1.0, 5.0, 9.0 ]\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "iIAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAA4B,QAAS,mDAAoD,EACzFC,EAAW,QAAS,4BAA6B,EACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAa,QAAS,8BAA+B,EACrDC,EAAY,QAAS,6BAA8B,EACnDC,EAAW,QAAS,4BAA6B,EACjDC,EAAU,QAAS,kCAAmC,EACtDC,EAAO,QAAS,yBAA0B,EAC1CC,EAAM,QAAS,+BAAgC,EAC/CC,EAAS,QAAS,uBAAwB,EAmC9C,SAASC,EAAUC,EAAGC,EAAMC,EAAGC,EAAW,CACzC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAKjB,EAAK,SAAW,EACpB,MAAM,IAAI,WAAYH,EAAQ,+EAAgFF,EAAMK,EAAM,IAAK,CAAE,CAAE,EAIpI,GAFAS,EAAKnB,EAAUS,CAAE,EACjBM,EAAQI,EAAG,OACNJ,EAAQ,EACZ,MAAM,IAAI,WAAYR,EAAQ,+GAAgHQ,CAAM,CAAE,EAMvJ,GAJAK,EAAKnB,EAAYQ,CAAE,EAGnBgB,EAAI3B,EAA2BY,EAAMK,EAAM,CAAE,EACxCU,IAAM,KACV,MAAM,IAAI,WAAYlB,EAAQ,mHAAoHQ,EAAOA,EAAM,EAAGV,EAAMK,EAAM,IAAK,CAAE,CAAE,EAExL,GAAKe,EAAE,SAAWf,EAAK,OACtB,MAAM,IAAI,MAAOH,EAAQ,0EAA2EF,EAAMK,EAAM,IAAK,CAAE,CAAE,EA0B1H,IAxBAW,EAAKD,EAAIK,EAAE,CAAC,CAAE,EACdH,EAAKF,EAAIK,EAAE,CAAC,CAAE,EAGdD,EAAOb,EAAI,EAAMA,EAAI,EACrBY,EAAKC,EAAKb,EAGVM,EAAOE,EAAIM,EAAE,CAAC,CAAE,EAAIF,EACpBL,EAAOC,EAAIM,EAAE,CAAC,CAAE,EAAID,EACpBE,EAAIpB,EAAKW,EAAMC,CAAK,EACfQ,EAAI,IACRA,EAAI,GAILZ,EAASZ,EAAWO,CAAE,EACjBiB,EAAI,IACRZ,GAAYU,EAAGF,EAASC,EAAGF,GAI5BL,EAAQ,CAAC,EACTH,EAAU,CAAC,EACLc,EAAI,EAAGA,EAAIZ,EAAOY,IAClBA,IAAMF,EAAE,CAAC,GAAKE,IAAMF,EAAE,CAAC,IAG5BT,EAAM,KAAMG,EAAIQ,CAAE,CAAE,EACpBd,EAAQ,KAAMO,EAAIO,CAAE,CAAE,GAEvB,OAAAX,EAAM,KAAMU,CAAE,EACdb,EAAQ,KAAMQ,EAAKC,CAAG,EAEf,IAAIb,EAAE,YAAaV,EAAUU,CAAE,EAAGL,EAASK,CAAE,EAAGO,EAAOH,EAASC,EAAQX,EAAUM,CAAE,EAAG,CAC7F,SAAY,CAACG,CACd,CAAC,CACF,CAKAf,EAAO,QAAUW,ICzGjB,IAAIoB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "toUniqueNormalizedIndices", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "getData", "join", "min", "format", "diagonal", "x", "dims", "k", "writable", "strides", "offset", "ndims", "shape", "rows", "cols", "sh", "st", "sr", "sc", "ro", "co", "d", "L", "i", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index da74ae9..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,51 +0,0 @@ - -{{alias}}( x, dims, k, writable ) - Returns a view of the diagonal of a matrix (or stack of matrices). - - The order of the dimension indices contained in `dims` matters. The first - element specifies the row-like dimension. The second element specifies - the column-like dimension. - - Each provided dimension index must reside on the interval [-ndims, ndims-1]. - - The diagonal offset `k` is interpreted as `column - row`. Accordingly, - when `k = 0`, the function returns the main diagonal; when `k > 0`, the - function returns the diagonal above the main diagonal; and when `k < 0`, - the function returns the diagonal below the main diagonal. - - The returned ndarray is a *view* of the input ndarray. Accordingly, - writing to the original ndarray will mutate the returned ndarray and - vice versa. - - The `writable` parameter only applies to ndarray constructors supporting - read-only instances. - - Parameters - ---------- - x: ndarray - Input array. - - dims: ArrayLikeObject - Dimension indices defining the plane from which to extract the diagonal. - - k: integer - Diagonal offset. - - writable: boolean - Boolean indicating whether the returned ndarray should be writable. - - Returns - ------- - out: ndarray - Output array view. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ) - [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] - > var y = {{alias}}( x, [ 0, 1 ], 0, false ) - [ 1.0, 4.0 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 513a253..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,92 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 zeros = require( '@stdlib/ndarray-zeros' ); -import diagonal = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - - diagonal( x, [ 0, 1 ], 0, false ); // $ExpectType float64ndarray -} - -// The compiler throws an error if the function is not provided a first argument which is an ndarray... -{ - diagonal( '5', [ 0, 1 ], 0, false ); // $ExpectError - diagonal( 5, [ 0, 1 ], 0, false ); // $ExpectError - diagonal( true, [ 0, 1 ], 0, false ); // $ExpectError - diagonal( false, [ 0, 1 ], 0, false ); // $ExpectError - diagonal( null, [ 0, 1 ], 0, false ); // $ExpectError - diagonal( {}, [ 0, 1 ], 0, false ); // $ExpectError - diagonal( [ '5' ], [ 0, 1 ], 0, false ); // $ExpectError - diagonal( ( x: number ): number => x, [ 0, 1 ], 0, false ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a second argument which is an array-like object containing numbers... -{ - const x = zeros( [ 2, 2 ] ); - - diagonal( x, '5', 0, false ); // $ExpectError - diagonal( x, 5, 0, false ); // $ExpectError - diagonal( x, true, 0, false ); // $ExpectError - diagonal( x, false, 0, false ); // $ExpectError - diagonal( x, null, 0, false ); // $ExpectError - diagonal( x, {}, 0, false ); // $ExpectError - diagonal( x, [ '5' ], 0, false ); // $ExpectError - diagonal( x, ( x: number ): number => x, 0, false ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a third argument which is a number... -{ - const x = zeros( [ 2, 2 ] ); - - diagonal( x, [ 0, 1 ], '5', false ); // $ExpectError - diagonal( x, [ 0, 1 ], true, false ); // $ExpectError - diagonal( x, [ 0, 1 ], false, false ); // $ExpectError - diagonal( x, [ 0, 1 ], null, false ); // $ExpectError - diagonal( x, [ 0, 1 ], {}, false ); // $ExpectError - diagonal( x, [ 0, 1 ], [], false ); // $ExpectError - diagonal( x, [ 0, 1 ], ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a fourth argument which is a boolean... -{ - const x = zeros( [ 2, 2 ] ); - - diagonal( x, [ 0, 1 ], 0, '5' ); // $ExpectError - diagonal( x, [ 0, 1 ], 0, 5 ); // $ExpectError - diagonal( x, [ 0, 1 ], 0, null ); // $ExpectError - diagonal( x, [ 0, 1 ], 0, {} ); // $ExpectError - diagonal( x, [ 0, 1 ], 0, [] ); // $ExpectError - diagonal( x, [ 0, 1 ], 0, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = zeros( [ 2, 2 ] ); - - diagonal(); // $ExpectError - diagonal( x ); // $ExpectError - diagonal( x, [ 0, 1 ] ); // $ExpectError - diagonal( x, [ 0, 1 ], 0 ); // $ExpectError - diagonal( x, [ 0, 1 ], 0, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 742dc69..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 uniform = require( '@stdlib/random-uniform' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var diagonal = require( './../lib' ); - -// Create a stack of matrices: -var x = uniform( [ 2, 3, 3 ], -10.0, 10.0, { - 'dtype': 'float64' -}); -console.log( ndarray2array( x ) ); - -// Extract the main diagonals from the stack: -var y = diagonal( x, [ 1, 2 ], 0, false ); -console.log( ndarray2array( y ) ); - -// Extract super-diagonals from the stack: -y = diagonal( x, [ 1, 2 ], 1, false ); -console.log( ndarray2array( y ) ); - -// Extract sub-diagonals from the stack: -y = diagonal( x, [ 1, 2 ], -1, false ); -console.log( ndarray2array( y ) ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index 5ab7709..9e71468 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/array'; import { typedndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..8e4e50f --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-to-unique-normalized-indices@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.3-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.3-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.3-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.3-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.3-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-join@v0.1.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-min@v0.2.4-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";function l(l,h,p,j){var u,v,f,b,g,c,x,y,w,E,M,R,V,q,z;if(2!==h.length)throw new RangeError(a("invalid argument. Must provide exactly two dimension indices. Value: `[%s]`.",o(h,", ")));if((f=(x=r(l)).length)<2)throw new RangeError(a("invalid argument. First argument must be an ndarray having two or more dimensions. Number of dimensions: %d.",f));if(y=n(l),null===(V=e(h,f-1)))throw new RangeError(a("invalid argument. Specified dimension index is out-of-bounds. Must be on the interval: [-%u, %u]. Value: `[%s]`.",f,f-1,o(h,", ")));if(V.length!==h.length)throw new Error(a("invalid argument. Must provide unique dimension indices. Value: `[%s]`.",o(h,", ")));for(w=y[V[0]],E=y[V[1]],M=(R=p>0?p:0)-p,g=x[V[0]]-M,c=x[V[1]]-R,(q=m(g,c))<0&&(q=0),v=t(l),q>0&&(v+=R*E+M*w),b=[],u=[],z=0;z 0`, the function returns the diagonal above the main diagonal; and when `k < 0`, the function returns the diagonal below the main diagonal.\n* - The returned ndarray is a **view** of the input ndarray. Accordingly, writing to the original ndarray will **mutate** the returned ndarray and vice versa.\n* - The `writable` parameter **only** applies to ndarray constructors supporting **read-only** instances.\n*\n* @param {ndarray} x - input array\n* @param {IntegerArray} dims - dimension indices defining the plane from which to extract the diagonal\n* @param {integer} k - diagonal offset\n* @param {boolean} writable - boolean indicating whether the returned ndarray should be writable\n* @throws {RangeError} must provide exactly two dimension indices\n* @throws {RangeError} must provide an ndarray having two or more dimensions\n* @throws {RangeError} must provide valid dimension indices\n* @throws {Error} must provide unique dimension indices\n* @returns {ndarray} ndarray view\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] );\n* // returns [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ]\n*\n* var y = diagonal( x, [ 0, 1 ], 0, false );\n* // returns [ 1.0, 5.0, 9.0 ]\n*/\nfunction diagonal( x, dims, k, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar ndims;\n\tvar shape;\n\tvar rows;\n\tvar cols;\n\tvar sh;\n\tvar st;\n\tvar sr;\n\tvar sc;\n\tvar ro;\n\tvar co;\n\tvar d;\n\tvar L;\n\tvar i;\n\n\tif ( dims.length !== 2 ) {\n\t\tthrow new RangeError( format( 'invalid argument. Must provide exactly two dimension indices. Value: `[%s]`.', join( dims, ', ' ) ) );\n\t}\n\tsh = getShape( x );\n\tndims = sh.length;\n\tif ( ndims < 2 ) {\n\t\tthrow new RangeError( format( 'invalid argument. First argument must be an ndarray having two or more dimensions. Number of dimensions: %d.', ndims ) );\n\t}\n\tst = getStrides( x );\n\n\t// Resolve dimension indices...\n\td = toUniqueNormalizedIndices( dims, ndims-1 );\n\tif ( d === null ) {\n\t\tthrow new RangeError( format( 'invalid argument. Specified dimension index is out-of-bounds. Must be on the interval: [-%u, %u]. Value: `[%s]`.', ndims, ndims-1, join( dims, ', ' ) ) );\n\t}\n\tif ( d.length !== dims.length ) {\n\t\tthrow new Error( format( 'invalid argument. Must provide unique dimension indices. Value: `[%s]`.', join( dims, ', ' ) ) );\n\t}\n\tsr = st[ d[0] ];\n\tsc = st[ d[1] ];\n\n\t// Resolve the row and column offsets corresponding to the diagonal offset `k = column - row`:\n\tco = ( k > 0 ) ? k : 0;\n\tro = co - k;\n\n\t// Compute the length of the diagonal:\n\trows = sh[ d[0] ] - ro;\n\tcols = sh[ d[1] ] - co;\n\tL = min( rows, cols );\n\tif ( L < 0 ) {\n\t\tL = 0;\n\t}\n\n\t// Adjust the offset so that we point to the first element along the specified diagonal:\n\toffset = getOffset( x );\n\tif ( L > 0 ) {\n\t\toffset += ( co*sc ) + ( ro*sr );\n\t}\n\n\t// Drop the specified dimensions and append the diagonal dimension:\n\tshape = [];\n\tstrides = [];\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tif ( i === d[0] || i === d[1] ) {\n\t\t\tcontinue;\n\t\t}\n\t\tshape.push( sh[ i ] );\n\t\tstrides.push( st[ i ] );\n\t}\n\tshape.push( L );\n\tstrides.push( sr + sc );\n\n\treturn new x.constructor( getDType( x ), getData( x ), shape, strides, offset, getOrder( x ), { // eslint-disable-line max-len\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default diagonal;\n"],"names":["diagonal","x","dims","k","writable","strides","offset","ndims","shape","rows","cols","sh","st","sr","sc","ro","co","d","L","i","length","RangeError","format","join","getShape","getStrides","toUniqueNormalizedIndices","Error","min","getOffset","push","constructor","getDType","getData","getOrder","readonly"],"mappings":";;s8BAkEA,SAASA,EAAUC,EAAGC,EAAMC,EAAGC,GAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAqB,IAAhBjB,EAAKkB,OACT,MAAM,IAAIC,WAAYC,EAAQ,+EAAgFC,EAAMrB,EAAM,QAI3H,IADAK,GADAI,EAAKa,EAAUvB,IACJmB,QACE,EACZ,MAAM,IAAIC,WAAYC,EAAQ,+GAAgHf,IAM/I,GAJAK,EAAKa,EAAYxB,GAIN,QADXgB,EAAIS,EAA2BxB,EAAMK,EAAM,IAE1C,MAAM,IAAIc,WAAYC,EAAQ,mHAAoHf,EAAOA,EAAM,EAAGgB,EAAMrB,EAAM,QAE/K,GAAKe,EAAEG,SAAWlB,EAAKkB,OACtB,MAAM,IAAIO,MAAOL,EAAQ,0EAA2EC,EAAMrB,EAAM,QA0BjH,IAxBAW,EAAKD,EAAIK,EAAE,IACXH,EAAKF,EAAIK,EAAE,IAIXF,GADAC,EAAOb,EAAI,EAAMA,EAAI,GACXA,EAGVM,EAAOE,EAAIM,EAAE,IAAOF,EACpBL,EAAOC,EAAIM,EAAE,IAAOD,GACpBE,EAAIU,EAAKnB,EAAMC,IACN,IACRQ,EAAI,GAILZ,EAASuB,EAAW5B,GACfiB,EAAI,IACRZ,GAAYU,EAAGF,EAASC,EAAGF,GAI5BL,EAAQ,GACRH,EAAU,GACJc,EAAI,EAAGA,EAAIZ,EAAOY,IAClBA,IAAMF,EAAE,IAAME,IAAMF,EAAE,KAG3BT,EAAMsB,KAAMnB,EAAIQ,IAChBd,EAAQyB,KAAMlB,EAAIO,KAKnB,OAHAX,EAAMsB,KAAMZ,GACZb,EAAQyB,KAAMjB,EAAKC,GAEZ,IAAIb,EAAE8B,YAAaC,EAAU/B,GAAKgC,EAAShC,GAAKO,EAAOH,EAASC,EAAQ4B,EAAUjC,GAAK,CAC7FkC,UAAa/B,GAEf"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a541856..0000000 --- a/lib/index.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Return a view of the diagonal of a matrix (or stack of matrices). -* -* @module @stdlib/ndarray-base-diagonal -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var diagonal = require( '@stdlib/ndarray-base-diagonal' ); -* -* var x = array( [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] ); -* // returns [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] -* -* var y = diagonal( x, [ 0, 1 ], 0, false ); -* // returns [ 1.0, 5.0, 9.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 acf301d..0000000 --- a/lib/main.js +++ /dev/null @@ -1,144 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var toUniqueNormalizedIndices = require( '@stdlib/ndarray-base-to-unique-normalized-indices' ); -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); -var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var join = require( '@stdlib/array-base-join' ); -var min = require( '@stdlib/math-base-special-min' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns a view of the diagonal of a matrix (or stack of matrices). -* -* ## Notes -* -* - The order of the dimension indices contained in `dims` matters. The first element specifies the row-like dimension. The second element specifies the column-like dimension. -* - Each provided dimension index must reside on the interval `[-ndims, ndims-1]`. -* - The diagonal offset `k` is interpreted as `column - row`. Accordingly, when `k = 0`, the function returns the main diagonal; when `k > 0`, the function returns the diagonal above the main diagonal; and when `k < 0`, the function returns the diagonal below the main diagonal. -* - The returned ndarray is a **view** of the input ndarray. Accordingly, writing to the original ndarray will **mutate** the returned ndarray and vice versa. -* - The `writable` parameter **only** applies to ndarray constructors supporting **read-only** instances. -* -* @param {ndarray} x - input array -* @param {IntegerArray} dims - dimension indices defining the plane from which to extract the diagonal -* @param {integer} k - diagonal offset -* @param {boolean} writable - boolean indicating whether the returned ndarray should be writable -* @throws {RangeError} must provide exactly two dimension indices -* @throws {RangeError} must provide an ndarray having two or more dimensions -* @throws {RangeError} must provide valid dimension indices -* @throws {Error} must provide unique dimension indices -* @returns {ndarray} ndarray view -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] ); -* // returns [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] -* -* var y = diagonal( x, [ 0, 1 ], 0, false ); -* // returns [ 1.0, 5.0, 9.0 ] -*/ -function diagonal( x, dims, k, writable ) { - var strides; - var offset; - var ndims; - var shape; - var rows; - var cols; - var sh; - var st; - var sr; - var sc; - var ro; - var co; - var d; - var L; - var i; - - if ( dims.length !== 2 ) { - throw new RangeError( format( 'invalid argument. Must provide exactly two dimension indices. Value: `[%s]`.', join( dims, ', ' ) ) ); - } - sh = getShape( x ); - ndims = sh.length; - if ( ndims < 2 ) { - throw new RangeError( format( 'invalid argument. First argument must be an ndarray having two or more dimensions. Number of dimensions: %d.', ndims ) ); - } - st = getStrides( x ); - - // Resolve dimension indices... - d = toUniqueNormalizedIndices( dims, ndims-1 ); - if ( d === null ) { - throw new RangeError( format( 'invalid argument. Specified dimension index is out-of-bounds. Must be on the interval: [-%u, %u]. Value: `[%s]`.', ndims, ndims-1, join( dims, ', ' ) ) ); - } - if ( d.length !== dims.length ) { - throw new Error( format( 'invalid argument. Must provide unique dimension indices. Value: `[%s]`.', join( dims, ', ' ) ) ); - } - sr = st[ d[0] ]; - sc = st[ d[1] ]; - - // Resolve the row and column offsets corresponding to the diagonal offset `k = column - row`: - co = ( k > 0 ) ? k : 0; - ro = co - k; - - // Compute the length of the diagonal: - rows = sh[ d[0] ] - ro; - cols = sh[ d[1] ] - co; - L = min( rows, cols ); - if ( L < 0 ) { - L = 0; - } - - // Adjust the offset so that we point to the first element along the specified diagonal: - offset = getOffset( x ); - if ( L > 0 ) { - offset += ( co*sc ) + ( ro*sr ); - } - - // Drop the specified dimensions and append the diagonal dimension: - shape = []; - strides = []; - for ( i = 0; i < ndims; i++ ) { - if ( i === d[0] || i === d[1] ) { - continue; - } - shape.push( sh[ i ] ); - strides.push( st[ i ] ); - } - shape.push( L ); - strides.push( sr + sc ); - - return new x.constructor( getDType( x ), getData( x ), shape, strides, offset, getOrder( x ), { // eslint-disable-line max-len - 'readonly': !writable - }); -} - - -// EXPORTS // - -module.exports = diagonal; diff --git a/package.json b/package.json index 3cdb2df..1e256a2 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Return a view of the diagonal of a matrix (or stack of matrices).", "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,56 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-join": "^0.1.2", - "@stdlib/math-base-special-min": "^0.2.4", - "@stdlib/ndarray-base-data-buffer": "^0.2.3", - "@stdlib/ndarray-base-dtype": "^0.2.3", - "@stdlib/ndarray-base-offset": "^0.2.3", - "@stdlib/ndarray-base-order": "^0.2.3", - "@stdlib/ndarray-base-shape": "^0.2.3", - "@stdlib/ndarray-base-strides": "^0.2.3", - "@stdlib/ndarray-base-to-unique-normalized-indices": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3", - "@stdlib/types": "^0.5.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.2.3", - "@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-data-buffer": "^0.2.3", - "@stdlib/ndarray-empty": "^0.3.1", - "@stdlib/ndarray-offset": "^0.2.3", - "@stdlib/ndarray-order": "^0.2.3", - "@stdlib/ndarray-shape": "^0.2.3", - "@stdlib/ndarray-stride": "^0.2.3", - "@stdlib/ndarray-strides": "^0.2.3", - "@stdlib/ndarray-to-array": "^0.2.2", - "@stdlib/random-uniform": "^0.1.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..ecc38ac --- /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 fabc8fa..0000000 --- a/test/test.js +++ /dev/null @@ -1,619 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var array = require( '@stdlib/ndarray-array' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var getStrides = require( '@stdlib/ndarray-strides' ); -var getStride = require( '@stdlib/ndarray-stride' ); -var getOffset = require( '@stdlib/ndarray-offset' ); -var getData = require( '@stdlib/ndarray-data-buffer' ); -var getOrder = require( '@stdlib/ndarray-order' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var diagonal = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof diagonal, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided exactly two dimension indices', function test( t ) { - var values; - var x; - var i; - - x = new ndarray( 'float64', new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); - - values = [ - [], - [ 0 ], - [ 0, 1, 0 ], - [ 0, 1, 0, 1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ].length + ' dimension indices' ); - } - t.end(); - - function badValue( dims ) { - return function badValue() { - diagonal( x, dims, 0, false ); - }; - } -}); - -tape( 'the function throws an error if provided an input ndarray with fewer than two dimensions', function test( t ) { - var values; - var i; - - values = [ - new ndarray( 'float64', new Float64Array( [ 5.0 ] ), [], [ 0 ], 0, 'row-major' ), - new ndarray( 'float64', new Float64Array( [ 1.0, 2.0, 3.0 ] ), [ 3 ], [ 1 ], 0, 'row-major' ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided an input ndarray with '+values[ i ].ndims+' dimensions' ); - } - t.end(); - - function badValue( x ) { - return function badValue() { - diagonal( x, [ 0, 1 ], 0, false ); - }; - } -}); - -tape( 'the function throws an error if provided out-of-bounds dimension indices', function test( t ) { - var values; - var x; - var i; - - x = new ndarray( 'float64', new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); - - values = [ - [ 0, 2 ], - [ 2, 0 ], - [ -3, 0 ], - [ 0, -3 ], - [ 10, 0 ], - [ 0, 10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided dimension indices ['+values[ i ]+']' ); - } - t.end(); - - function badValue( dims ) { - return function badValue() { - diagonal( x, dims, 0, false ); - }; - } -}); - -tape( 'the function throws an error if provided duplicate dimension indices', function test( t ) { - var values; - var x; - var i; - - x = new ndarray( 'float64', new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ), [ 2, 2, 2 ], [ 4, 2, 1 ], 0, 'row-major' ); - - values = [ - [ 0, 0 ], - [ 1, 1 ], - [ 2, 2 ], - [ 0, -3 ], - [ -2, 1 ], - [ -1, 2 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided dimension indices ['+values[ i ]+']' ); - } - t.end(); - - function badValue( dims ) { - return function badValue() { - diagonal( x, dims, 0, false ); - }; - } -}); - -tape( 'the function returns a view of the main diagonal of a square matrix', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); - - y = diagonal( x, [ 0, 1 ], 0, false ); - - expected = [ 3 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 1, 5, 9 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.strictEqual( getData( y ), getData( x ), 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of the super-diagonal of a square matrix', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); - - y = diagonal( x, [ 0, 1 ], 1, false ); - - expected = [ 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 2, 6 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], 2, false ); - - expected = [ 1 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 3 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of the sub-diagonal of a square matrix', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); - - y = diagonal( x, [ 0, 1 ], -1, false ); - - expected = [ 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 4, 8 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], -2, false ); - - expected = [ 1 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 7 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of the diagonal of a non-square matrix (M < N)', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ 1, 2, 3, 4 ], [ 5, 6, 7, 8 ] ] ); - - y = diagonal( x, [ 0, 1 ], 0, false ); - - expected = [ 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 1, 6 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], 2, false ); - - expected = [ 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 3, 8 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], -1, false ); - - expected = [ 1 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 5 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of the diagonal of a non-square matrix (M > N)', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ], [ 7, 8 ] ] ); - - y = diagonal( x, [ 0, 1 ], 0, false ); - - expected = [ 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 1, 4 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], -2, false ); - - expected = [ 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 5, 8 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], 1, false ); - - expected = [ 1 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 2 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an empty view when the diagonal offset is out-of-bounds', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); - - y = diagonal( x, [ 0, 1 ], 3, false ); - - expected = [ 0 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = []; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], -3, false ); - - expected = [ 0 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = []; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], 100, false ); - - expected = [ 0 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = []; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function swaps the row-like and column-like dimensions when `dims` is reversed', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); - - y = diagonal( x, [ 1, 0 ], 1, false ); - - expected = [ 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 4, 8 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 1, 0 ], -1, false ); - - expected = [ 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 2, 6 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of the diagonals of a stack of matrices', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); - - y = diagonal( x, [ 1, 2 ], 0, false ); - - expected = [ 2, 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ [ 1, 4 ], [ 5, 8 ] ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 1, 2 ], 1, false ); - - expected = [ 2, 1 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ [ 2 ], [ 6 ] ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 1, 2 ], -1, false ); - - expected = [ 2, 1 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ [ 3 ], [ 7 ] ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function appends the diagonal dimension as the trailing dimension of the output ndarray', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ [ 1, 2, 3 ], [ 4, 5, 6 ] ], [ [ 7, 8, 9 ], [ 10, 11, 12 ] ] ] ); - - y = diagonal( x, [ 0, 2 ], 0, false ); - - expected = [ 2, 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ [ 1, 8 ], [ 4, 11 ] ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function normalizes negative dimension indices', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); - - y = diagonal( x, [ -2, -1 ], 0, false ); - - expected = [ 3 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 1, 5, 9 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a column-major ndarray when the input ndarray is column-major', function test( t ) { - var expected; - var x; - var y; - - x = ndarray( 'generic', [ 1, 4, 7, 2, 5, 8, 3, 6, 9 ], [ 3, 3 ], [ 1, 3 ], 0, 'column-major' ); - - y = diagonal( x, [ 0, 1 ], 0, false ); - - expected = 'column-major'; - t.strictEqual( getOrder( y ), expected, 'returns expected value' ); - - expected = [ 3 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 1, 5, 9 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a writable ndarray when `writable` is `true`', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); - y = diagonal( x, [ 0, 1 ], 0, true ); - - t.strictEqual( isReadOnly( y ), false, 'returns expected value' ); - t.strictEqual( getData( y ), getData( x ), 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a read-only ndarray when `writable` is `false`', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); - y = diagonal( x, [ 0, 1 ], 0, false ); - - t.strictEqual( isReadOnly( y ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function constructs the output by retaining all dimensions except the specified dimensions and appending the diagonal dimension', function test( t ) { - var expected; - var x; - var y; - - x = array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ], { - 'shape': [ 3, 2, 2 ] - }); - - y = diagonal( x, [ 1, 2 ], 0, false ); - - expected = [ 3, 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 4, 3 ]; - t.deepEqual( getStrides( y ), expected, 'returns expected value' ); - - expected = getOffset( x ); - t.strictEqual( getOffset( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function adjusts the offset to point to the first element of the requested diagonal', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); - - y = diagonal( x, [ 0, 1 ], 1, false ); - - expected = getOffset( x ) + getStride( x, 1 ); - t.strictEqual( getOffset( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], -1, false ); - - expected = getOffset( x ) + getStride( x, 0 ); - t.strictEqual( getOffset( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports input ndarrays having a non-zero buffer offset', function test( t ) { - var expected; - var x; - var y; - - x = ndarray( 'generic', [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], [ 3, 3 ], [ 3, 1 ], 1, 'row-major' ); - - y = diagonal( x, [ 0, 1 ], 0, false ); - - expected = [ 3 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 1, 5, 9 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.strictEqual( getData( y ), getData( x ), 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], 1, false ); - - expected = [ 2, 6 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], -1, false ); - - expected = [ 4, 8 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports 4D inputs with non-trailing `dims`', function test( t ) { - var expected; - var arr; - var x; - var y; - - arr = [ - [ - [ - [ 0, 1 ], - [ 2, 3 ], - [ 4, 5 ] - ], - [ - [ 6, 7 ], - [ 8, 9 ], - [ 10, 11 ] - ], - [ - [ 12, 13 ], - [ 14, 15 ], - [ 16, 17 ] - ] - ], - [ - [ - [ 18, 19 ], - [ 20, 21 ], - [ 22, 23 ] - ], - [ - [ 24, 25 ], - [ 26, 27 ], - [ 28, 29 ] - ], - [ - [ 30, 31 ], - [ 32, 33 ], - [ 34, 35 ] - ] - ] - ]; - x = array( arr ); - y = diagonal( x, [ 1, 2 ], 0, false ); - expected = [ 2, 2, 3 ]; - - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ - [ - [ 0, 8, 16 ], - [ 1, 9, 17 ] - ], - [ - [ 18, 26, 34 ], - [ 19, 27, 35 ] - ] - ]; - - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - t.strictEqual( getData( y ), getData( x ), 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports negative dimension indices combined with a non-zero `k`', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); - y = diagonal( x, [ -2, -1 ], 1, false ); - - expected = [ 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 2, 6 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ -2, -1 ], -1, false ); - - expected = [ 4, 8 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); From 468d218ce464d540ee98cb2624709b8bea76e0e5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 14 Aug 2026 03:38:34 +0000 Subject: [PATCH 18/23] 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 a3666a6..acf301d 100644 --- a/lib/main.js +++ b/lib/main.js @@ -29,7 +29,7 @@ var getOrder = require( '@stdlib/ndarray-base-order' ); var getData = require( '@stdlib/ndarray-base-data-buffer' ); var join = require( '@stdlib/array-base-join' ); var min = require( '@stdlib/math-base-special-min' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // diff --git a/package.json b/package.json index 2e2a34b..3cdb2df 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/ndarray-base-shape": "^0.2.3", "@stdlib/ndarray-base-strides": "^0.2.3", "@stdlib/ndarray-base-to-unique-normalized-indices": "^0.1.1", - "@stdlib/string-format": "^0.2.3", + "@stdlib/error-tools-fmtprodmsg": "^0.2.3", "@stdlib/types": "^0.5.1", "@stdlib/error-tools-fmtprodmsg": "^0.2.3" }, From 937285183ab9ca33c6877ecf4e64f51cad86ff9c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 14 Aug 2026 03:55:39 +0000 Subject: [PATCH 19/23] Remove files --- index.d.ts | 57 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4904 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 9e71468..0000000 --- a/index.d.ts +++ /dev/null @@ -1,57 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { Collection } from '@stdlib/types/array'; -import { typedndarray } from '@stdlib/types/ndarray'; - -/** -* Returns a view of the diagonal of a matrix (or stack of matrices). -* -* ## Notes -* -* - The order of the dimension indices contained in `dims` matters. The first element specifies the row-like dimension. The second element specifies the column-like dimension. -* - Each provided dimension index must reside on the interval `[-ndims, ndims-1]`. -* - The diagonal offset `k` is interpreted as `column - row`. Accordingly, when `k = 0`, the function returns the main diagonal; when `k > 0`, the function returns the diagonal above the main diagonal; and when `k < 0`, the function returns the diagonal below the main diagonal. -* - The returned ndarray is a **view** of the input ndarray. Accordingly, writing to the original ndarray will **mutate** the returned ndarray and vice versa. -* - The `writable` parameter **only** applies to ndarray constructors supporting **read-only** instances. -* -* @param x - input array -* @param dims - dimension indices defining the plane from which to extract the diagonal -* @param k - diagonal offset -* @param writable - boolean indicating whether the returned ndarray should be writable -* @returns ndarray view -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] ); -* // returns [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] -* -* var y = diagonal( x, [ 0, 1 ], 0, false ); -* // returns [ 1.0, 5.0, 9.0 ] -*/ -declare function diagonal = typedndarray>( x: U, dims: Collection, k: number, writable: boolean ): U; - - -// EXPORTS // - -export = diagonal; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 8e4e50f..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-to-unique-normalized-indices@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.3-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.3-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.3-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.3-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.3-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-join@v0.1.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-min@v0.2.4-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";function l(l,h,p,j){var u,v,f,b,g,c,x,y,w,E,M,R,V,q,z;if(2!==h.length)throw new RangeError(a("invalid argument. Must provide exactly two dimension indices. Value: `[%s]`.",o(h,", ")));if((f=(x=r(l)).length)<2)throw new RangeError(a("invalid argument. First argument must be an ndarray having two or more dimensions. Number of dimensions: %d.",f));if(y=n(l),null===(V=e(h,f-1)))throw new RangeError(a("invalid argument. Specified dimension index is out-of-bounds. Must be on the interval: [-%u, %u]. Value: `[%s]`.",f,f-1,o(h,", ")));if(V.length!==h.length)throw new Error(a("invalid argument. Must provide unique dimension indices. Value: `[%s]`.",o(h,", ")));for(w=y[V[0]],E=y[V[1]],M=(R=p>0?p:0)-p,g=x[V[0]]-M,c=x[V[1]]-R,(q=m(g,c))<0&&(q=0),v=t(l),q>0&&(v+=R*E+M*w),b=[],u=[],z=0;z 0`, the function returns the diagonal above the main diagonal; and when `k < 0`, the function returns the diagonal below the main diagonal.\n* - The returned ndarray is a **view** of the input ndarray. Accordingly, writing to the original ndarray will **mutate** the returned ndarray and vice versa.\n* - The `writable` parameter **only** applies to ndarray constructors supporting **read-only** instances.\n*\n* @param {ndarray} x - input array\n* @param {IntegerArray} dims - dimension indices defining the plane from which to extract the diagonal\n* @param {integer} k - diagonal offset\n* @param {boolean} writable - boolean indicating whether the returned ndarray should be writable\n* @throws {RangeError} must provide exactly two dimension indices\n* @throws {RangeError} must provide an ndarray having two or more dimensions\n* @throws {RangeError} must provide valid dimension indices\n* @throws {Error} must provide unique dimension indices\n* @returns {ndarray} ndarray view\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] );\n* // returns [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ]\n*\n* var y = diagonal( x, [ 0, 1 ], 0, false );\n* // returns [ 1.0, 5.0, 9.0 ]\n*/\nfunction diagonal( x, dims, k, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar ndims;\n\tvar shape;\n\tvar rows;\n\tvar cols;\n\tvar sh;\n\tvar st;\n\tvar sr;\n\tvar sc;\n\tvar ro;\n\tvar co;\n\tvar d;\n\tvar L;\n\tvar i;\n\n\tif ( dims.length !== 2 ) {\n\t\tthrow new RangeError( format( 'invalid argument. Must provide exactly two dimension indices. Value: `[%s]`.', join( dims, ', ' ) ) );\n\t}\n\tsh = getShape( x );\n\tndims = sh.length;\n\tif ( ndims < 2 ) {\n\t\tthrow new RangeError( format( 'invalid argument. First argument must be an ndarray having two or more dimensions. Number of dimensions: %d.', ndims ) );\n\t}\n\tst = getStrides( x );\n\n\t// Resolve dimension indices...\n\td = toUniqueNormalizedIndices( dims, ndims-1 );\n\tif ( d === null ) {\n\t\tthrow new RangeError( format( 'invalid argument. Specified dimension index is out-of-bounds. Must be on the interval: [-%u, %u]. Value: `[%s]`.', ndims, ndims-1, join( dims, ', ' ) ) );\n\t}\n\tif ( d.length !== dims.length ) {\n\t\tthrow new Error( format( 'invalid argument. Must provide unique dimension indices. Value: `[%s]`.', join( dims, ', ' ) ) );\n\t}\n\tsr = st[ d[0] ];\n\tsc = st[ d[1] ];\n\n\t// Resolve the row and column offsets corresponding to the diagonal offset `k = column - row`:\n\tco = ( k > 0 ) ? k : 0;\n\tro = co - k;\n\n\t// Compute the length of the diagonal:\n\trows = sh[ d[0] ] - ro;\n\tcols = sh[ d[1] ] - co;\n\tL = min( rows, cols );\n\tif ( L < 0 ) {\n\t\tL = 0;\n\t}\n\n\t// Adjust the offset so that we point to the first element along the specified diagonal:\n\toffset = getOffset( x );\n\tif ( L > 0 ) {\n\t\toffset += ( co*sc ) + ( ro*sr );\n\t}\n\n\t// Drop the specified dimensions and append the diagonal dimension:\n\tshape = [];\n\tstrides = [];\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tif ( i === d[0] || i === d[1] ) {\n\t\t\tcontinue;\n\t\t}\n\t\tshape.push( sh[ i ] );\n\t\tstrides.push( st[ i ] );\n\t}\n\tshape.push( L );\n\tstrides.push( sr + sc );\n\n\treturn new x.constructor( getDType( x ), getData( x ), shape, strides, offset, getOrder( x ), { // eslint-disable-line max-len\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default diagonal;\n"],"names":["diagonal","x","dims","k","writable","strides","offset","ndims","shape","rows","cols","sh","st","sr","sc","ro","co","d","L","i","length","RangeError","format","join","getShape","getStrides","toUniqueNormalizedIndices","Error","min","getOffset","push","constructor","getDType","getData","getOrder","readonly"],"mappings":";;s8BAkEA,SAASA,EAAUC,EAAGC,EAAMC,EAAGC,GAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAqB,IAAhBjB,EAAKkB,OACT,MAAM,IAAIC,WAAYC,EAAQ,+EAAgFC,EAAMrB,EAAM,QAI3H,IADAK,GADAI,EAAKa,EAAUvB,IACJmB,QACE,EACZ,MAAM,IAAIC,WAAYC,EAAQ,+GAAgHf,IAM/I,GAJAK,EAAKa,EAAYxB,GAIN,QADXgB,EAAIS,EAA2BxB,EAAMK,EAAM,IAE1C,MAAM,IAAIc,WAAYC,EAAQ,mHAAoHf,EAAOA,EAAM,EAAGgB,EAAMrB,EAAM,QAE/K,GAAKe,EAAEG,SAAWlB,EAAKkB,OACtB,MAAM,IAAIO,MAAOL,EAAQ,0EAA2EC,EAAMrB,EAAM,QA0BjH,IAxBAW,EAAKD,EAAIK,EAAE,IACXH,EAAKF,EAAIK,EAAE,IAIXF,GADAC,EAAOb,EAAI,EAAMA,EAAI,GACXA,EAGVM,EAAOE,EAAIM,EAAE,IAAOF,EACpBL,EAAOC,EAAIM,EAAE,IAAOD,GACpBE,EAAIU,EAAKnB,EAAMC,IACN,IACRQ,EAAI,GAILZ,EAASuB,EAAW5B,GACfiB,EAAI,IACRZ,GAAYU,EAAGF,EAASC,EAAGF,GAI5BL,EAAQ,GACRH,EAAU,GACJc,EAAI,EAAGA,EAAIZ,EAAOY,IAClBA,IAAMF,EAAE,IAAME,IAAMF,EAAE,KAG3BT,EAAMsB,KAAMnB,EAAIQ,IAChBd,EAAQyB,KAAMlB,EAAIO,KAKnB,OAHAX,EAAMsB,KAAMZ,GACZb,EAAQyB,KAAMjB,EAAKC,GAEZ,IAAIb,EAAE8B,YAAaC,EAAU/B,GAAKgC,EAAShC,GAAKO,EAAOH,EAASC,EAAQ4B,EAAUjC,GAAK,CAC7FkC,UAAa/B,GAEf"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index ecc38ac..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 1b4c286a59cadd4d79f3c4f57ef5df2f670f4c99 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 14 Aug 2026 03:56:05 +0000 Subject: [PATCH 20/23] Auto-generated commit --- .editorconfig | 189 - .eslintrc.js | 1 - .gitattributes | 68 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 821 --- .github/workflows/publish.yml | 261 - .github/workflows/test.yml | 101 - .github/workflows/test_bundles.yml | 213 - .github/workflows/test_coverage.yml | 142 - .github/workflows/test_install.yml | 94 - .github/workflows/test_published_package.yml | 115 - .gitignore | 205 - .npmignore | 229 - .npmrc | 44 - CHANGELOG.md | 52 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 41 +- SECURITY.md | 5 - benchmark/benchmark.js | 272 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 51 - docs/types/test.ts | 92 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 44 - lib/main.js | 144 - package.json | 77 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 619 --- 44 files changed, 4866 insertions(+), 4937 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 (96%) 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 355dffa..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2026-08-14T03:28:49.397Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 5dacce3..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/diagonal) 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 bbaa7c7..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/diagonal) 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 52ddcc8..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: '7 19 * * 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 + + ```
@@ -207,7 +198,7 @@ console.log( ndarray2array( y ) ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. 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 3a0a3bc..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,272 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var diagonal = require( './../lib' ); - - -// MAIN // - -bench( format( '%s::ndims=2,ctor=base', pkg ), function benchmark( b ) { - var values; - var v; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = diagonal( values[ i%values.length ], [ 0, 1 ], 0, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::ndims=2,ctor=non-base', pkg ), function benchmark( b ) { - var values; - var v; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - values = [ - empty( [ 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = diagonal( values[ i%values.length ], [ 0, 1 ], 0, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::ndims=3,ctor=base', pkg ), function benchmark( b ) { - var values; - var v; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = diagonal( values[ i%values.length ], [ 1, 2 ], 0, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::ndims=3,ctor=non-base', pkg ), function benchmark( b ) { - var values; - var v; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - values = [ - empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = diagonal( values[ i%values.length ], [ 1, 2 ], 0, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::ndims=4,ctor=base', pkg ), function benchmark( b ) { - var values; - var v; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = diagonal( values[ i%values.length ], [ 2, 3 ], 0, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::ndims=4,ctor=non-base', pkg ), function benchmark( b ) { - var values; - var v; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - values = [ - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = diagonal( values[ i%values.length ], [ 2, 3 ], 0, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::ndims=5,ctor=base', pkg ), function benchmark( b ) { - var values; - var v; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = diagonal( values[ i%values.length ], [ 3, 4 ], 0, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::ndims=5,ctor=non-base', pkg ), function benchmark( b ) { - var values; - var v; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - values = [ - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = diagonal( values[ i%values.length ], [ 3, 4 ], 0, false ); - if ( typeof v !== '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 437ecb7..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/diagonal" -%% click B href "https://github.com/stdlib-js/ndarray-base-diagonal/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-diagonal/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-diagonal/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-diagonal/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-diagonal/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/diagonal -[production-url]: https://github.com/stdlib-js/ndarray-base-diagonal/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-diagonal/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-diagonal/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-diagonal/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-diagonal/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-diagonal/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-diagonal/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 a7ab3b4..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import diagonal from '../docs/types/index'; -export = diagonal; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 4fab4ac..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var M=function(e,r){return function(){try{return r||e((r={exports:{}}).exports,r),r.exports}catch(t){throw (r=0, t)}};};var y=M(function(T,b){ -var R=require('@stdlib/ndarray-base-to-unique-normalized-indices/dist'),S=require('@stdlib/ndarray-base-dtype/dist'),V=require('@stdlib/ndarray-base-shape/dist'),D=require('@stdlib/ndarray-base-strides/dist'),N=require('@stdlib/ndarray-base-offset/dist'),O=require('@stdlib/ndarray-base-order/dist'),j=require('@stdlib/ndarray-base-data-buffer/dist'),q=require('@stdlib/array-base-join/dist'),z=require('@stdlib/math-base-special-min/dist'),l=require('@stdlib/error-tools-fmtprodmsg/dist');function F(e,r,t,E){var s,f,a,v,p,w,o,d,h,c,m,g,i,u,n;if(r.length!==2)throw new RangeError(l('2lXKM',q(r,", ")));if(o=V(e),a=o.length,a<2)throw new RangeError(l('2lXKN',a));if(d=D(e),i=R(r,a-1),i===null)throw new RangeError(l('2lXHO',a,a-1,q(r,", ")));if(i.length!==r.length)throw new Error(l('2lXHP',q(r,", ")));for(h=d[i[0]],c=d[i[1]],g=t>0?t:0,m=g-t,p=o[i[0]]-m,w=o[i[1]]-g,u=z(p,w),u<0&&(u=0),f=N(e),u>0&&(f+=g*c+m*h),v=[],s=[],n=0;n 0`, the function returns the diagonal above the main diagonal; and when `k < 0`, the function returns the diagonal below the main diagonal.\n* - The returned ndarray is a **view** of the input ndarray. Accordingly, writing to the original ndarray will **mutate** the returned ndarray and vice versa.\n* - The `writable` parameter **only** applies to ndarray constructors supporting **read-only** instances.\n*\n* @param {ndarray} x - input array\n* @param {IntegerArray} dims - dimension indices defining the plane from which to extract the diagonal\n* @param {integer} k - diagonal offset\n* @param {boolean} writable - boolean indicating whether the returned ndarray should be writable\n* @throws {RangeError} must provide exactly two dimension indices\n* @throws {RangeError} must provide an ndarray having two or more dimensions\n* @throws {RangeError} must provide valid dimension indices\n* @throws {Error} must provide unique dimension indices\n* @returns {ndarray} ndarray view\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] );\n* // returns [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ]\n*\n* var y = diagonal( x, [ 0, 1 ], 0, false );\n* // returns [ 1.0, 5.0, 9.0 ]\n*/\nfunction diagonal( x, dims, k, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar ndims;\n\tvar shape;\n\tvar rows;\n\tvar cols;\n\tvar sh;\n\tvar st;\n\tvar sr;\n\tvar sc;\n\tvar ro;\n\tvar co;\n\tvar d;\n\tvar L;\n\tvar i;\n\n\tif ( dims.length !== 2 ) {\n\t\tthrow new RangeError( format( 'invalid argument. Must provide exactly two dimension indices. Value: `[%s]`.', join( dims, ', ' ) ) );\n\t}\n\tsh = getShape( x );\n\tndims = sh.length;\n\tif ( ndims < 2 ) {\n\t\tthrow new RangeError( format( 'invalid argument. First argument must be an ndarray having two or more dimensions. Number of dimensions: %d.', ndims ) );\n\t}\n\tst = getStrides( x );\n\n\t// Resolve dimension indices...\n\td = toUniqueNormalizedIndices( dims, ndims-1 );\n\tif ( d === null ) {\n\t\tthrow new RangeError( format( 'invalid argument. Specified dimension index is out-of-bounds. Must be on the interval: [-%u, %u]. Value: `[%s]`.', ndims, ndims-1, join( dims, ', ' ) ) );\n\t}\n\tif ( d.length !== dims.length ) {\n\t\tthrow new Error( format( 'invalid argument. Must provide unique dimension indices. Value: `[%s]`.', join( dims, ', ' ) ) );\n\t}\n\tsr = st[ d[0] ];\n\tsc = st[ d[1] ];\n\n\t// Resolve the row and column offsets corresponding to the diagonal offset `k = column - row`:\n\tco = ( k > 0 ) ? k : 0;\n\tro = co - k;\n\n\t// Compute the length of the diagonal:\n\trows = sh[ d[0] ] - ro;\n\tcols = sh[ d[1] ] - co;\n\tL = min( rows, cols );\n\tif ( L < 0 ) {\n\t\tL = 0;\n\t}\n\n\t// Adjust the offset so that we point to the first element along the specified diagonal:\n\toffset = getOffset( x );\n\tif ( L > 0 ) {\n\t\toffset += ( co*sc ) + ( ro*sr );\n\t}\n\n\t// Drop the specified dimensions and append the diagonal dimension:\n\tshape = [];\n\tstrides = [];\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tif ( i === d[0] || i === d[1] ) {\n\t\t\tcontinue;\n\t\t}\n\t\tshape.push( sh[ i ] );\n\t\tstrides.push( st[ i ] );\n\t}\n\tshape.push( L );\n\tstrides.push( sr + sc );\n\n\treturn new x.constructor( getDType( x ), getData( x ), shape, strides, offset, getOrder( x ), { // eslint-disable-line max-len\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nmodule.exports = diagonal;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Return a view of the diagonal of a matrix (or stack of matrices).\n*\n* @module @stdlib/ndarray-base-diagonal\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var diagonal = require( '@stdlib/ndarray-base-diagonal' );\n*\n* var x = array( [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] );\n* // returns [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ]\n*\n* var y = diagonal( x, [ 0, 1 ], 0, false );\n* // returns [ 1.0, 5.0, 9.0 ]\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "iIAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAA4B,QAAS,mDAAoD,EACzFC,EAAW,QAAS,4BAA6B,EACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAa,QAAS,8BAA+B,EACrDC,EAAY,QAAS,6BAA8B,EACnDC,EAAW,QAAS,4BAA6B,EACjDC,EAAU,QAAS,kCAAmC,EACtDC,EAAO,QAAS,yBAA0B,EAC1CC,EAAM,QAAS,+BAAgC,EAC/CC,EAAS,QAAS,uBAAwB,EAmC9C,SAASC,EAAUC,EAAGC,EAAMC,EAAGC,EAAW,CACzC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAKjB,EAAK,SAAW,EACpB,MAAM,IAAI,WAAYH,EAAQ,+EAAgFF,EAAMK,EAAM,IAAK,CAAE,CAAE,EAIpI,GAFAS,EAAKnB,EAAUS,CAAE,EACjBM,EAAQI,EAAG,OACNJ,EAAQ,EACZ,MAAM,IAAI,WAAYR,EAAQ,+GAAgHQ,CAAM,CAAE,EAMvJ,GAJAK,EAAKnB,EAAYQ,CAAE,EAGnBgB,EAAI3B,EAA2BY,EAAMK,EAAM,CAAE,EACxCU,IAAM,KACV,MAAM,IAAI,WAAYlB,EAAQ,mHAAoHQ,EAAOA,EAAM,EAAGV,EAAMK,EAAM,IAAK,CAAE,CAAE,EAExL,GAAKe,EAAE,SAAWf,EAAK,OACtB,MAAM,IAAI,MAAOH,EAAQ,0EAA2EF,EAAMK,EAAM,IAAK,CAAE,CAAE,EA0B1H,IAxBAW,EAAKD,EAAIK,EAAE,CAAC,CAAE,EACdH,EAAKF,EAAIK,EAAE,CAAC,CAAE,EAGdD,EAAOb,EAAI,EAAMA,EAAI,EACrBY,EAAKC,EAAKb,EAGVM,EAAOE,EAAIM,EAAE,CAAC,CAAE,EAAIF,EACpBL,EAAOC,EAAIM,EAAE,CAAC,CAAE,EAAID,EACpBE,EAAIpB,EAAKW,EAAMC,CAAK,EACfQ,EAAI,IACRA,EAAI,GAILZ,EAASZ,EAAWO,CAAE,EACjBiB,EAAI,IACRZ,GAAYU,EAAGF,EAASC,EAAGF,GAI5BL,EAAQ,CAAC,EACTH,EAAU,CAAC,EACLc,EAAI,EAAGA,EAAIZ,EAAOY,IAClBA,IAAMF,EAAE,CAAC,GAAKE,IAAMF,EAAE,CAAC,IAG5BT,EAAM,KAAMG,EAAIQ,CAAE,CAAE,EACpBd,EAAQ,KAAMO,EAAIO,CAAE,CAAE,GAEvB,OAAAX,EAAM,KAAMU,CAAE,EACdb,EAAQ,KAAMQ,EAAKC,CAAG,EAEf,IAAIb,EAAE,YAAaV,EAAUU,CAAE,EAAGL,EAASK,CAAE,EAAGO,EAAOH,EAASC,EAAQX,EAAUM,CAAE,EAAG,CAC7F,SAAY,CAACG,CACd,CAAC,CACF,CAKAf,EAAO,QAAUW,ICzGjB,IAAIoB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "toUniqueNormalizedIndices", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "getData", "join", "min", "format", "diagonal", "x", "dims", "k", "writable", "strides", "offset", "ndims", "shape", "rows", "cols", "sh", "st", "sr", "sc", "ro", "co", "d", "L", "i", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index da74ae9..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,51 +0,0 @@ - -{{alias}}( x, dims, k, writable ) - Returns a view of the diagonal of a matrix (or stack of matrices). - - The order of the dimension indices contained in `dims` matters. The first - element specifies the row-like dimension. The second element specifies - the column-like dimension. - - Each provided dimension index must reside on the interval [-ndims, ndims-1]. - - The diagonal offset `k` is interpreted as `column - row`. Accordingly, - when `k = 0`, the function returns the main diagonal; when `k > 0`, the - function returns the diagonal above the main diagonal; and when `k < 0`, - the function returns the diagonal below the main diagonal. - - The returned ndarray is a *view* of the input ndarray. Accordingly, - writing to the original ndarray will mutate the returned ndarray and - vice versa. - - The `writable` parameter only applies to ndarray constructors supporting - read-only instances. - - Parameters - ---------- - x: ndarray - Input array. - - dims: ArrayLikeObject - Dimension indices defining the plane from which to extract the diagonal. - - k: integer - Diagonal offset. - - writable: boolean - Boolean indicating whether the returned ndarray should be writable. - - Returns - ------- - out: ndarray - Output array view. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ) - [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] - > var y = {{alias}}( x, [ 0, 1 ], 0, false ) - [ 1.0, 4.0 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 513a253..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,92 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 zeros = require( '@stdlib/ndarray-zeros' ); -import diagonal = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - - diagonal( x, [ 0, 1 ], 0, false ); // $ExpectType float64ndarray -} - -// The compiler throws an error if the function is not provided a first argument which is an ndarray... -{ - diagonal( '5', [ 0, 1 ], 0, false ); // $ExpectError - diagonal( 5, [ 0, 1 ], 0, false ); // $ExpectError - diagonal( true, [ 0, 1 ], 0, false ); // $ExpectError - diagonal( false, [ 0, 1 ], 0, false ); // $ExpectError - diagonal( null, [ 0, 1 ], 0, false ); // $ExpectError - diagonal( {}, [ 0, 1 ], 0, false ); // $ExpectError - diagonal( [ '5' ], [ 0, 1 ], 0, false ); // $ExpectError - diagonal( ( x: number ): number => x, [ 0, 1 ], 0, false ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a second argument which is an array-like object containing numbers... -{ - const x = zeros( [ 2, 2 ] ); - - diagonal( x, '5', 0, false ); // $ExpectError - diagonal( x, 5, 0, false ); // $ExpectError - diagonal( x, true, 0, false ); // $ExpectError - diagonal( x, false, 0, false ); // $ExpectError - diagonal( x, null, 0, false ); // $ExpectError - diagonal( x, {}, 0, false ); // $ExpectError - diagonal( x, [ '5' ], 0, false ); // $ExpectError - diagonal( x, ( x: number ): number => x, 0, false ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a third argument which is a number... -{ - const x = zeros( [ 2, 2 ] ); - - diagonal( x, [ 0, 1 ], '5', false ); // $ExpectError - diagonal( x, [ 0, 1 ], true, false ); // $ExpectError - diagonal( x, [ 0, 1 ], false, false ); // $ExpectError - diagonal( x, [ 0, 1 ], null, false ); // $ExpectError - diagonal( x, [ 0, 1 ], {}, false ); // $ExpectError - diagonal( x, [ 0, 1 ], [], false ); // $ExpectError - diagonal( x, [ 0, 1 ], ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a fourth argument which is a boolean... -{ - const x = zeros( [ 2, 2 ] ); - - diagonal( x, [ 0, 1 ], 0, '5' ); // $ExpectError - diagonal( x, [ 0, 1 ], 0, 5 ); // $ExpectError - diagonal( x, [ 0, 1 ], 0, null ); // $ExpectError - diagonal( x, [ 0, 1 ], 0, {} ); // $ExpectError - diagonal( x, [ 0, 1 ], 0, [] ); // $ExpectError - diagonal( x, [ 0, 1 ], 0, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = zeros( [ 2, 2 ] ); - - diagonal(); // $ExpectError - diagonal( x ); // $ExpectError - diagonal( x, [ 0, 1 ] ); // $ExpectError - diagonal( x, [ 0, 1 ], 0 ); // $ExpectError - diagonal( x, [ 0, 1 ], 0, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 742dc69..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 uniform = require( '@stdlib/random-uniform' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var diagonal = require( './../lib' ); - -// Create a stack of matrices: -var x = uniform( [ 2, 3, 3 ], -10.0, 10.0, { - 'dtype': 'float64' -}); -console.log( ndarray2array( x ) ); - -// Extract the main diagonals from the stack: -var y = diagonal( x, [ 1, 2 ], 0, false ); -console.log( ndarray2array( y ) ); - -// Extract super-diagonals from the stack: -y = diagonal( x, [ 1, 2 ], 1, false ); -console.log( ndarray2array( y ) ); - -// Extract sub-diagonals from the stack: -y = diagonal( x, [ 1, 2 ], -1, false ); -console.log( ndarray2array( y ) ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index 5ab7709..9e71468 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/array'; import { typedndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..8e4e50f --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-to-unique-normalized-indices@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.3-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.3-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.3-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.3-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.3-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-join@v0.1.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-min@v0.2.4-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";function l(l,h,p,j){var u,v,f,b,g,c,x,y,w,E,M,R,V,q,z;if(2!==h.length)throw new RangeError(a("invalid argument. Must provide exactly two dimension indices. Value: `[%s]`.",o(h,", ")));if((f=(x=r(l)).length)<2)throw new RangeError(a("invalid argument. First argument must be an ndarray having two or more dimensions. Number of dimensions: %d.",f));if(y=n(l),null===(V=e(h,f-1)))throw new RangeError(a("invalid argument. Specified dimension index is out-of-bounds. Must be on the interval: [-%u, %u]. Value: `[%s]`.",f,f-1,o(h,", ")));if(V.length!==h.length)throw new Error(a("invalid argument. Must provide unique dimension indices. Value: `[%s]`.",o(h,", ")));for(w=y[V[0]],E=y[V[1]],M=(R=p>0?p:0)-p,g=x[V[0]]-M,c=x[V[1]]-R,(q=m(g,c))<0&&(q=0),v=t(l),q>0&&(v+=R*E+M*w),b=[],u=[],z=0;z 0`, the function returns the diagonal above the main diagonal; and when `k < 0`, the function returns the diagonal below the main diagonal.\n* - The returned ndarray is a **view** of the input ndarray. Accordingly, writing to the original ndarray will **mutate** the returned ndarray and vice versa.\n* - The `writable` parameter **only** applies to ndarray constructors supporting **read-only** instances.\n*\n* @param {ndarray} x - input array\n* @param {IntegerArray} dims - dimension indices defining the plane from which to extract the diagonal\n* @param {integer} k - diagonal offset\n* @param {boolean} writable - boolean indicating whether the returned ndarray should be writable\n* @throws {RangeError} must provide exactly two dimension indices\n* @throws {RangeError} must provide an ndarray having two or more dimensions\n* @throws {RangeError} must provide valid dimension indices\n* @throws {Error} must provide unique dimension indices\n* @returns {ndarray} ndarray view\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] );\n* // returns [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ]\n*\n* var y = diagonal( x, [ 0, 1 ], 0, false );\n* // returns [ 1.0, 5.0, 9.0 ]\n*/\nfunction diagonal( x, dims, k, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar ndims;\n\tvar shape;\n\tvar rows;\n\tvar cols;\n\tvar sh;\n\tvar st;\n\tvar sr;\n\tvar sc;\n\tvar ro;\n\tvar co;\n\tvar d;\n\tvar L;\n\tvar i;\n\n\tif ( dims.length !== 2 ) {\n\t\tthrow new RangeError( format( 'invalid argument. Must provide exactly two dimension indices. Value: `[%s]`.', join( dims, ', ' ) ) );\n\t}\n\tsh = getShape( x );\n\tndims = sh.length;\n\tif ( ndims < 2 ) {\n\t\tthrow new RangeError( format( 'invalid argument. First argument must be an ndarray having two or more dimensions. Number of dimensions: %d.', ndims ) );\n\t}\n\tst = getStrides( x );\n\n\t// Resolve dimension indices...\n\td = toUniqueNormalizedIndices( dims, ndims-1 );\n\tif ( d === null ) {\n\t\tthrow new RangeError( format( 'invalid argument. Specified dimension index is out-of-bounds. Must be on the interval: [-%u, %u]. Value: `[%s]`.', ndims, ndims-1, join( dims, ', ' ) ) );\n\t}\n\tif ( d.length !== dims.length ) {\n\t\tthrow new Error( format( 'invalid argument. Must provide unique dimension indices. Value: `[%s]`.', join( dims, ', ' ) ) );\n\t}\n\tsr = st[ d[0] ];\n\tsc = st[ d[1] ];\n\n\t// Resolve the row and column offsets corresponding to the diagonal offset `k = column - row`:\n\tco = ( k > 0 ) ? k : 0;\n\tro = co - k;\n\n\t// Compute the length of the diagonal:\n\trows = sh[ d[0] ] - ro;\n\tcols = sh[ d[1] ] - co;\n\tL = min( rows, cols );\n\tif ( L < 0 ) {\n\t\tL = 0;\n\t}\n\n\t// Adjust the offset so that we point to the first element along the specified diagonal:\n\toffset = getOffset( x );\n\tif ( L > 0 ) {\n\t\toffset += ( co*sc ) + ( ro*sr );\n\t}\n\n\t// Drop the specified dimensions and append the diagonal dimension:\n\tshape = [];\n\tstrides = [];\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tif ( i === d[0] || i === d[1] ) {\n\t\t\tcontinue;\n\t\t}\n\t\tshape.push( sh[ i ] );\n\t\tstrides.push( st[ i ] );\n\t}\n\tshape.push( L );\n\tstrides.push( sr + sc );\n\n\treturn new x.constructor( getDType( x ), getData( x ), shape, strides, offset, getOrder( x ), { // eslint-disable-line max-len\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default diagonal;\n"],"names":["diagonal","x","dims","k","writable","strides","offset","ndims","shape","rows","cols","sh","st","sr","sc","ro","co","d","L","i","length","RangeError","format","join","getShape","getStrides","toUniqueNormalizedIndices","Error","min","getOffset","push","constructor","getDType","getData","getOrder","readonly"],"mappings":";;s8BAkEA,SAASA,EAAUC,EAAGC,EAAMC,EAAGC,GAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAqB,IAAhBjB,EAAKkB,OACT,MAAM,IAAIC,WAAYC,EAAQ,+EAAgFC,EAAMrB,EAAM,QAI3H,IADAK,GADAI,EAAKa,EAAUvB,IACJmB,QACE,EACZ,MAAM,IAAIC,WAAYC,EAAQ,+GAAgHf,IAM/I,GAJAK,EAAKa,EAAYxB,GAIN,QADXgB,EAAIS,EAA2BxB,EAAMK,EAAM,IAE1C,MAAM,IAAIc,WAAYC,EAAQ,mHAAoHf,EAAOA,EAAM,EAAGgB,EAAMrB,EAAM,QAE/K,GAAKe,EAAEG,SAAWlB,EAAKkB,OACtB,MAAM,IAAIO,MAAOL,EAAQ,0EAA2EC,EAAMrB,EAAM,QA0BjH,IAxBAW,EAAKD,EAAIK,EAAE,IACXH,EAAKF,EAAIK,EAAE,IAIXF,GADAC,EAAOb,EAAI,EAAMA,EAAI,GACXA,EAGVM,EAAOE,EAAIM,EAAE,IAAOF,EACpBL,EAAOC,EAAIM,EAAE,IAAOD,GACpBE,EAAIU,EAAKnB,EAAMC,IACN,IACRQ,EAAI,GAILZ,EAASuB,EAAW5B,GACfiB,EAAI,IACRZ,GAAYU,EAAGF,EAASC,EAAGF,GAI5BL,EAAQ,GACRH,EAAU,GACJc,EAAI,EAAGA,EAAIZ,EAAOY,IAClBA,IAAMF,EAAE,IAAME,IAAMF,EAAE,KAG3BT,EAAMsB,KAAMnB,EAAIQ,IAChBd,EAAQyB,KAAMlB,EAAIO,KAKnB,OAHAX,EAAMsB,KAAMZ,GACZb,EAAQyB,KAAMjB,EAAKC,GAEZ,IAAIb,EAAE8B,YAAaC,EAAU/B,GAAKgC,EAAShC,GAAKO,EAAOH,EAASC,EAAQ4B,EAAUjC,GAAK,CAC7FkC,UAAa/B,GAEf"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a541856..0000000 --- a/lib/index.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Return a view of the diagonal of a matrix (or stack of matrices). -* -* @module @stdlib/ndarray-base-diagonal -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var diagonal = require( '@stdlib/ndarray-base-diagonal' ); -* -* var x = array( [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] ); -* // returns [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] -* -* var y = diagonal( x, [ 0, 1 ], 0, false ); -* // returns [ 1.0, 5.0, 9.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 acf301d..0000000 --- a/lib/main.js +++ /dev/null @@ -1,144 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var toUniqueNormalizedIndices = require( '@stdlib/ndarray-base-to-unique-normalized-indices' ); -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); -var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var join = require( '@stdlib/array-base-join' ); -var min = require( '@stdlib/math-base-special-min' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns a view of the diagonal of a matrix (or stack of matrices). -* -* ## Notes -* -* - The order of the dimension indices contained in `dims` matters. The first element specifies the row-like dimension. The second element specifies the column-like dimension. -* - Each provided dimension index must reside on the interval `[-ndims, ndims-1]`. -* - The diagonal offset `k` is interpreted as `column - row`. Accordingly, when `k = 0`, the function returns the main diagonal; when `k > 0`, the function returns the diagonal above the main diagonal; and when `k < 0`, the function returns the diagonal below the main diagonal. -* - The returned ndarray is a **view** of the input ndarray. Accordingly, writing to the original ndarray will **mutate** the returned ndarray and vice versa. -* - The `writable` parameter **only** applies to ndarray constructors supporting **read-only** instances. -* -* @param {ndarray} x - input array -* @param {IntegerArray} dims - dimension indices defining the plane from which to extract the diagonal -* @param {integer} k - diagonal offset -* @param {boolean} writable - boolean indicating whether the returned ndarray should be writable -* @throws {RangeError} must provide exactly two dimension indices -* @throws {RangeError} must provide an ndarray having two or more dimensions -* @throws {RangeError} must provide valid dimension indices -* @throws {Error} must provide unique dimension indices -* @returns {ndarray} ndarray view -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] ); -* // returns [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] -* -* var y = diagonal( x, [ 0, 1 ], 0, false ); -* // returns [ 1.0, 5.0, 9.0 ] -*/ -function diagonal( x, dims, k, writable ) { - var strides; - var offset; - var ndims; - var shape; - var rows; - var cols; - var sh; - var st; - var sr; - var sc; - var ro; - var co; - var d; - var L; - var i; - - if ( dims.length !== 2 ) { - throw new RangeError( format( 'invalid argument. Must provide exactly two dimension indices. Value: `[%s]`.', join( dims, ', ' ) ) ); - } - sh = getShape( x ); - ndims = sh.length; - if ( ndims < 2 ) { - throw new RangeError( format( 'invalid argument. First argument must be an ndarray having two or more dimensions. Number of dimensions: %d.', ndims ) ); - } - st = getStrides( x ); - - // Resolve dimension indices... - d = toUniqueNormalizedIndices( dims, ndims-1 ); - if ( d === null ) { - throw new RangeError( format( 'invalid argument. Specified dimension index is out-of-bounds. Must be on the interval: [-%u, %u]. Value: `[%s]`.', ndims, ndims-1, join( dims, ', ' ) ) ); - } - if ( d.length !== dims.length ) { - throw new Error( format( 'invalid argument. Must provide unique dimension indices. Value: `[%s]`.', join( dims, ', ' ) ) ); - } - sr = st[ d[0] ]; - sc = st[ d[1] ]; - - // Resolve the row and column offsets corresponding to the diagonal offset `k = column - row`: - co = ( k > 0 ) ? k : 0; - ro = co - k; - - // Compute the length of the diagonal: - rows = sh[ d[0] ] - ro; - cols = sh[ d[1] ] - co; - L = min( rows, cols ); - if ( L < 0 ) { - L = 0; - } - - // Adjust the offset so that we point to the first element along the specified diagonal: - offset = getOffset( x ); - if ( L > 0 ) { - offset += ( co*sc ) + ( ro*sr ); - } - - // Drop the specified dimensions and append the diagonal dimension: - shape = []; - strides = []; - for ( i = 0; i < ndims; i++ ) { - if ( i === d[0] || i === d[1] ) { - continue; - } - shape.push( sh[ i ] ); - strides.push( st[ i ] ); - } - shape.push( L ); - strides.push( sr + sc ); - - return new x.constructor( getDType( x ), getData( x ), shape, strides, offset, getOrder( x ), { // eslint-disable-line max-len - 'readonly': !writable - }); -} - - -// EXPORTS // - -module.exports = diagonal; diff --git a/package.json b/package.json index 3cdb2df..1e256a2 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Return a view of the diagonal of a matrix (or stack of matrices).", "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,56 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-join": "^0.1.2", - "@stdlib/math-base-special-min": "^0.2.4", - "@stdlib/ndarray-base-data-buffer": "^0.2.3", - "@stdlib/ndarray-base-dtype": "^0.2.3", - "@stdlib/ndarray-base-offset": "^0.2.3", - "@stdlib/ndarray-base-order": "^0.2.3", - "@stdlib/ndarray-base-shape": "^0.2.3", - "@stdlib/ndarray-base-strides": "^0.2.3", - "@stdlib/ndarray-base-to-unique-normalized-indices": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3", - "@stdlib/types": "^0.5.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.2.3", - "@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-data-buffer": "^0.2.3", - "@stdlib/ndarray-empty": "^0.3.1", - "@stdlib/ndarray-offset": "^0.2.3", - "@stdlib/ndarray-order": "^0.2.3", - "@stdlib/ndarray-shape": "^0.2.3", - "@stdlib/ndarray-stride": "^0.2.3", - "@stdlib/ndarray-strides": "^0.2.3", - "@stdlib/ndarray-to-array": "^0.2.2", - "@stdlib/random-uniform": "^0.1.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..ecc38ac --- /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 fabc8fa..0000000 --- a/test/test.js +++ /dev/null @@ -1,619 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var array = require( '@stdlib/ndarray-array' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var getStrides = require( '@stdlib/ndarray-strides' ); -var getStride = require( '@stdlib/ndarray-stride' ); -var getOffset = require( '@stdlib/ndarray-offset' ); -var getData = require( '@stdlib/ndarray-data-buffer' ); -var getOrder = require( '@stdlib/ndarray-order' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var diagonal = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof diagonal, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided exactly two dimension indices', function test( t ) { - var values; - var x; - var i; - - x = new ndarray( 'float64', new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); - - values = [ - [], - [ 0 ], - [ 0, 1, 0 ], - [ 0, 1, 0, 1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ].length + ' dimension indices' ); - } - t.end(); - - function badValue( dims ) { - return function badValue() { - diagonal( x, dims, 0, false ); - }; - } -}); - -tape( 'the function throws an error if provided an input ndarray with fewer than two dimensions', function test( t ) { - var values; - var i; - - values = [ - new ndarray( 'float64', new Float64Array( [ 5.0 ] ), [], [ 0 ], 0, 'row-major' ), - new ndarray( 'float64', new Float64Array( [ 1.0, 2.0, 3.0 ] ), [ 3 ], [ 1 ], 0, 'row-major' ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided an input ndarray with '+values[ i ].ndims+' dimensions' ); - } - t.end(); - - function badValue( x ) { - return function badValue() { - diagonal( x, [ 0, 1 ], 0, false ); - }; - } -}); - -tape( 'the function throws an error if provided out-of-bounds dimension indices', function test( t ) { - var values; - var x; - var i; - - x = new ndarray( 'float64', new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); - - values = [ - [ 0, 2 ], - [ 2, 0 ], - [ -3, 0 ], - [ 0, -3 ], - [ 10, 0 ], - [ 0, 10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided dimension indices ['+values[ i ]+']' ); - } - t.end(); - - function badValue( dims ) { - return function badValue() { - diagonal( x, dims, 0, false ); - }; - } -}); - -tape( 'the function throws an error if provided duplicate dimension indices', function test( t ) { - var values; - var x; - var i; - - x = new ndarray( 'float64', new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ), [ 2, 2, 2 ], [ 4, 2, 1 ], 0, 'row-major' ); - - values = [ - [ 0, 0 ], - [ 1, 1 ], - [ 2, 2 ], - [ 0, -3 ], - [ -2, 1 ], - [ -1, 2 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided dimension indices ['+values[ i ]+']' ); - } - t.end(); - - function badValue( dims ) { - return function badValue() { - diagonal( x, dims, 0, false ); - }; - } -}); - -tape( 'the function returns a view of the main diagonal of a square matrix', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); - - y = diagonal( x, [ 0, 1 ], 0, false ); - - expected = [ 3 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 1, 5, 9 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.strictEqual( getData( y ), getData( x ), 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of the super-diagonal of a square matrix', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); - - y = diagonal( x, [ 0, 1 ], 1, false ); - - expected = [ 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 2, 6 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], 2, false ); - - expected = [ 1 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 3 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of the sub-diagonal of a square matrix', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); - - y = diagonal( x, [ 0, 1 ], -1, false ); - - expected = [ 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 4, 8 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], -2, false ); - - expected = [ 1 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 7 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of the diagonal of a non-square matrix (M < N)', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ 1, 2, 3, 4 ], [ 5, 6, 7, 8 ] ] ); - - y = diagonal( x, [ 0, 1 ], 0, false ); - - expected = [ 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 1, 6 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], 2, false ); - - expected = [ 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 3, 8 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], -1, false ); - - expected = [ 1 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 5 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of the diagonal of a non-square matrix (M > N)', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ], [ 7, 8 ] ] ); - - y = diagonal( x, [ 0, 1 ], 0, false ); - - expected = [ 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 1, 4 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], -2, false ); - - expected = [ 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 5, 8 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], 1, false ); - - expected = [ 1 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 2 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an empty view when the diagonal offset is out-of-bounds', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); - - y = diagonal( x, [ 0, 1 ], 3, false ); - - expected = [ 0 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = []; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], -3, false ); - - expected = [ 0 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = []; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], 100, false ); - - expected = [ 0 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = []; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function swaps the row-like and column-like dimensions when `dims` is reversed', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); - - y = diagonal( x, [ 1, 0 ], 1, false ); - - expected = [ 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 4, 8 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 1, 0 ], -1, false ); - - expected = [ 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 2, 6 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of the diagonals of a stack of matrices', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); - - y = diagonal( x, [ 1, 2 ], 0, false ); - - expected = [ 2, 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ [ 1, 4 ], [ 5, 8 ] ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 1, 2 ], 1, false ); - - expected = [ 2, 1 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ [ 2 ], [ 6 ] ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 1, 2 ], -1, false ); - - expected = [ 2, 1 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ [ 3 ], [ 7 ] ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function appends the diagonal dimension as the trailing dimension of the output ndarray', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ [ 1, 2, 3 ], [ 4, 5, 6 ] ], [ [ 7, 8, 9 ], [ 10, 11, 12 ] ] ] ); - - y = diagonal( x, [ 0, 2 ], 0, false ); - - expected = [ 2, 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ [ 1, 8 ], [ 4, 11 ] ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function normalizes negative dimension indices', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); - - y = diagonal( x, [ -2, -1 ], 0, false ); - - expected = [ 3 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 1, 5, 9 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a column-major ndarray when the input ndarray is column-major', function test( t ) { - var expected; - var x; - var y; - - x = ndarray( 'generic', [ 1, 4, 7, 2, 5, 8, 3, 6, 9 ], [ 3, 3 ], [ 1, 3 ], 0, 'column-major' ); - - y = diagonal( x, [ 0, 1 ], 0, false ); - - expected = 'column-major'; - t.strictEqual( getOrder( y ), expected, 'returns expected value' ); - - expected = [ 3 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 1, 5, 9 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a writable ndarray when `writable` is `true`', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); - y = diagonal( x, [ 0, 1 ], 0, true ); - - t.strictEqual( isReadOnly( y ), false, 'returns expected value' ); - t.strictEqual( getData( y ), getData( x ), 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a read-only ndarray when `writable` is `false`', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); - y = diagonal( x, [ 0, 1 ], 0, false ); - - t.strictEqual( isReadOnly( y ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function constructs the output by retaining all dimensions except the specified dimensions and appending the diagonal dimension', function test( t ) { - var expected; - var x; - var y; - - x = array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ], { - 'shape': [ 3, 2, 2 ] - }); - - y = diagonal( x, [ 1, 2 ], 0, false ); - - expected = [ 3, 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 4, 3 ]; - t.deepEqual( getStrides( y ), expected, 'returns expected value' ); - - expected = getOffset( x ); - t.strictEqual( getOffset( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function adjusts the offset to point to the first element of the requested diagonal', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); - - y = diagonal( x, [ 0, 1 ], 1, false ); - - expected = getOffset( x ) + getStride( x, 1 ); - t.strictEqual( getOffset( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], -1, false ); - - expected = getOffset( x ) + getStride( x, 0 ); - t.strictEqual( getOffset( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports input ndarrays having a non-zero buffer offset', function test( t ) { - var expected; - var x; - var y; - - x = ndarray( 'generic', [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], [ 3, 3 ], [ 3, 1 ], 1, 'row-major' ); - - y = diagonal( x, [ 0, 1 ], 0, false ); - - expected = [ 3 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 1, 5, 9 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.strictEqual( getData( y ), getData( x ), 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], 1, false ); - - expected = [ 2, 6 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], -1, false ); - - expected = [ 4, 8 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports 4D inputs with non-trailing `dims`', function test( t ) { - var expected; - var arr; - var x; - var y; - - arr = [ - [ - [ - [ 0, 1 ], - [ 2, 3 ], - [ 4, 5 ] - ], - [ - [ 6, 7 ], - [ 8, 9 ], - [ 10, 11 ] - ], - [ - [ 12, 13 ], - [ 14, 15 ], - [ 16, 17 ] - ] - ], - [ - [ - [ 18, 19 ], - [ 20, 21 ], - [ 22, 23 ] - ], - [ - [ 24, 25 ], - [ 26, 27 ], - [ 28, 29 ] - ], - [ - [ 30, 31 ], - [ 32, 33 ], - [ 34, 35 ] - ] - ] - ]; - x = array( arr ); - y = diagonal( x, [ 1, 2 ], 0, false ); - expected = [ 2, 2, 3 ]; - - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ - [ - [ 0, 8, 16 ], - [ 1, 9, 17 ] - ], - [ - [ 18, 26, 34 ], - [ 19, 27, 35 ] - ] - ]; - - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - t.strictEqual( getData( y ), getData( x ), 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports negative dimension indices combined with a non-zero `k`', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); - y = diagonal( x, [ -2, -1 ], 1, false ); - - expected = [ 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 2, 6 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ -2, -1 ], -1, false ); - - expected = [ 4, 8 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); From ec32fae15966d3ba16cba62a16daa8dda8d629d9 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 15 Aug 2026 02:33:04 +0000 Subject: [PATCH 21/23] 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 a3666a6..acf301d 100644 --- a/lib/main.js +++ b/lib/main.js @@ -29,7 +29,7 @@ var getOrder = require( '@stdlib/ndarray-base-order' ); var getData = require( '@stdlib/ndarray-base-data-buffer' ); var join = require( '@stdlib/array-base-join' ); var min = require( '@stdlib/math-base-special-min' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // diff --git a/package.json b/package.json index 2e2a34b..3cdb2df 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/ndarray-base-shape": "^0.2.3", "@stdlib/ndarray-base-strides": "^0.2.3", "@stdlib/ndarray-base-to-unique-normalized-indices": "^0.1.1", - "@stdlib/string-format": "^0.2.3", + "@stdlib/error-tools-fmtprodmsg": "^0.2.3", "@stdlib/types": "^0.5.1", "@stdlib/error-tools-fmtprodmsg": "^0.2.3" }, From d9ecffc3f60b14e1bc42f8b91f7c5b277240d4ca Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 15 Aug 2026 02:36:34 +0000 Subject: [PATCH 22/23] Remove files --- index.d.ts | 57 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4904 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 9e71468..0000000 --- a/index.d.ts +++ /dev/null @@ -1,57 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { Collection } from '@stdlib/types/array'; -import { typedndarray } from '@stdlib/types/ndarray'; - -/** -* Returns a view of the diagonal of a matrix (or stack of matrices). -* -* ## Notes -* -* - The order of the dimension indices contained in `dims` matters. The first element specifies the row-like dimension. The second element specifies the column-like dimension. -* - Each provided dimension index must reside on the interval `[-ndims, ndims-1]`. -* - The diagonal offset `k` is interpreted as `column - row`. Accordingly, when `k = 0`, the function returns the main diagonal; when `k > 0`, the function returns the diagonal above the main diagonal; and when `k < 0`, the function returns the diagonal below the main diagonal. -* - The returned ndarray is a **view** of the input ndarray. Accordingly, writing to the original ndarray will **mutate** the returned ndarray and vice versa. -* - The `writable` parameter **only** applies to ndarray constructors supporting **read-only** instances. -* -* @param x - input array -* @param dims - dimension indices defining the plane from which to extract the diagonal -* @param k - diagonal offset -* @param writable - boolean indicating whether the returned ndarray should be writable -* @returns ndarray view -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] ); -* // returns [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] -* -* var y = diagonal( x, [ 0, 1 ], 0, false ); -* // returns [ 1.0, 5.0, 9.0 ] -*/ -declare function diagonal = typedndarray>( x: U, dims: Collection, k: number, writable: boolean ): U; - - -// EXPORTS // - -export = diagonal; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 8e4e50f..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-to-unique-normalized-indices@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.3-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.3-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.3-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.3-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.3-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-join@v0.1.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-min@v0.2.4-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";function l(l,h,p,j){var u,v,f,b,g,c,x,y,w,E,M,R,V,q,z;if(2!==h.length)throw new RangeError(a("invalid argument. Must provide exactly two dimension indices. Value: `[%s]`.",o(h,", ")));if((f=(x=r(l)).length)<2)throw new RangeError(a("invalid argument. First argument must be an ndarray having two or more dimensions. Number of dimensions: %d.",f));if(y=n(l),null===(V=e(h,f-1)))throw new RangeError(a("invalid argument. Specified dimension index is out-of-bounds. Must be on the interval: [-%u, %u]. Value: `[%s]`.",f,f-1,o(h,", ")));if(V.length!==h.length)throw new Error(a("invalid argument. Must provide unique dimension indices. Value: `[%s]`.",o(h,", ")));for(w=y[V[0]],E=y[V[1]],M=(R=p>0?p:0)-p,g=x[V[0]]-M,c=x[V[1]]-R,(q=m(g,c))<0&&(q=0),v=t(l),q>0&&(v+=R*E+M*w),b=[],u=[],z=0;z 0`, the function returns the diagonal above the main diagonal; and when `k < 0`, the function returns the diagonal below the main diagonal.\n* - The returned ndarray is a **view** of the input ndarray. Accordingly, writing to the original ndarray will **mutate** the returned ndarray and vice versa.\n* - The `writable` parameter **only** applies to ndarray constructors supporting **read-only** instances.\n*\n* @param {ndarray} x - input array\n* @param {IntegerArray} dims - dimension indices defining the plane from which to extract the diagonal\n* @param {integer} k - diagonal offset\n* @param {boolean} writable - boolean indicating whether the returned ndarray should be writable\n* @throws {RangeError} must provide exactly two dimension indices\n* @throws {RangeError} must provide an ndarray having two or more dimensions\n* @throws {RangeError} must provide valid dimension indices\n* @throws {Error} must provide unique dimension indices\n* @returns {ndarray} ndarray view\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] );\n* // returns [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ]\n*\n* var y = diagonal( x, [ 0, 1 ], 0, false );\n* // returns [ 1.0, 5.0, 9.0 ]\n*/\nfunction diagonal( x, dims, k, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar ndims;\n\tvar shape;\n\tvar rows;\n\tvar cols;\n\tvar sh;\n\tvar st;\n\tvar sr;\n\tvar sc;\n\tvar ro;\n\tvar co;\n\tvar d;\n\tvar L;\n\tvar i;\n\n\tif ( dims.length !== 2 ) {\n\t\tthrow new RangeError( format( 'invalid argument. Must provide exactly two dimension indices. Value: `[%s]`.', join( dims, ', ' ) ) );\n\t}\n\tsh = getShape( x );\n\tndims = sh.length;\n\tif ( ndims < 2 ) {\n\t\tthrow new RangeError( format( 'invalid argument. First argument must be an ndarray having two or more dimensions. Number of dimensions: %d.', ndims ) );\n\t}\n\tst = getStrides( x );\n\n\t// Resolve dimension indices...\n\td = toUniqueNormalizedIndices( dims, ndims-1 );\n\tif ( d === null ) {\n\t\tthrow new RangeError( format( 'invalid argument. Specified dimension index is out-of-bounds. Must be on the interval: [-%u, %u]. Value: `[%s]`.', ndims, ndims-1, join( dims, ', ' ) ) );\n\t}\n\tif ( d.length !== dims.length ) {\n\t\tthrow new Error( format( 'invalid argument. Must provide unique dimension indices. Value: `[%s]`.', join( dims, ', ' ) ) );\n\t}\n\tsr = st[ d[0] ];\n\tsc = st[ d[1] ];\n\n\t// Resolve the row and column offsets corresponding to the diagonal offset `k = column - row`:\n\tco = ( k > 0 ) ? k : 0;\n\tro = co - k;\n\n\t// Compute the length of the diagonal:\n\trows = sh[ d[0] ] - ro;\n\tcols = sh[ d[1] ] - co;\n\tL = min( rows, cols );\n\tif ( L < 0 ) {\n\t\tL = 0;\n\t}\n\n\t// Adjust the offset so that we point to the first element along the specified diagonal:\n\toffset = getOffset( x );\n\tif ( L > 0 ) {\n\t\toffset += ( co*sc ) + ( ro*sr );\n\t}\n\n\t// Drop the specified dimensions and append the diagonal dimension:\n\tshape = [];\n\tstrides = [];\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tif ( i === d[0] || i === d[1] ) {\n\t\t\tcontinue;\n\t\t}\n\t\tshape.push( sh[ i ] );\n\t\tstrides.push( st[ i ] );\n\t}\n\tshape.push( L );\n\tstrides.push( sr + sc );\n\n\treturn new x.constructor( getDType( x ), getData( x ), shape, strides, offset, getOrder( x ), { // eslint-disable-line max-len\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default diagonal;\n"],"names":["diagonal","x","dims","k","writable","strides","offset","ndims","shape","rows","cols","sh","st","sr","sc","ro","co","d","L","i","length","RangeError","format","join","getShape","getStrides","toUniqueNormalizedIndices","Error","min","getOffset","push","constructor","getDType","getData","getOrder","readonly"],"mappings":";;s8BAkEA,SAASA,EAAUC,EAAGC,EAAMC,EAAGC,GAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAqB,IAAhBjB,EAAKkB,OACT,MAAM,IAAIC,WAAYC,EAAQ,+EAAgFC,EAAMrB,EAAM,QAI3H,IADAK,GADAI,EAAKa,EAAUvB,IACJmB,QACE,EACZ,MAAM,IAAIC,WAAYC,EAAQ,+GAAgHf,IAM/I,GAJAK,EAAKa,EAAYxB,GAIN,QADXgB,EAAIS,EAA2BxB,EAAMK,EAAM,IAE1C,MAAM,IAAIc,WAAYC,EAAQ,mHAAoHf,EAAOA,EAAM,EAAGgB,EAAMrB,EAAM,QAE/K,GAAKe,EAAEG,SAAWlB,EAAKkB,OACtB,MAAM,IAAIO,MAAOL,EAAQ,0EAA2EC,EAAMrB,EAAM,QA0BjH,IAxBAW,EAAKD,EAAIK,EAAE,IACXH,EAAKF,EAAIK,EAAE,IAIXF,GADAC,EAAOb,EAAI,EAAMA,EAAI,GACXA,EAGVM,EAAOE,EAAIM,EAAE,IAAOF,EACpBL,EAAOC,EAAIM,EAAE,IAAOD,GACpBE,EAAIU,EAAKnB,EAAMC,IACN,IACRQ,EAAI,GAILZ,EAASuB,EAAW5B,GACfiB,EAAI,IACRZ,GAAYU,EAAGF,EAASC,EAAGF,GAI5BL,EAAQ,GACRH,EAAU,GACJc,EAAI,EAAGA,EAAIZ,EAAOY,IAClBA,IAAMF,EAAE,IAAME,IAAMF,EAAE,KAG3BT,EAAMsB,KAAMnB,EAAIQ,IAChBd,EAAQyB,KAAMlB,EAAIO,KAKnB,OAHAX,EAAMsB,KAAMZ,GACZb,EAAQyB,KAAMjB,EAAKC,GAEZ,IAAIb,EAAE8B,YAAaC,EAAU/B,GAAKgC,EAAShC,GAAKO,EAAOH,EAASC,EAAQ4B,EAAUjC,GAAK,CAC7FkC,UAAa/B,GAEf"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index ecc38ac..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From ceada77c6ea8a677e4e771ccbfc95144f7cae10a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 15 Aug 2026 02:37:31 +0000 Subject: [PATCH 23/23] Auto-generated commit --- .editorconfig | 189 - .eslintrc.js | 1 - .gitattributes | 68 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 821 --- .github/workflows/publish.yml | 261 - .github/workflows/test.yml | 101 - .github/workflows/test_bundles.yml | 213 - .github/workflows/test_coverage.yml | 142 - .github/workflows/test_install.yml | 94 - .github/workflows/test_published_package.yml | 115 - .gitignore | 205 - .npmignore | 229 - .npmrc | 44 - CHANGELOG.md | 52 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 41 +- SECURITY.md | 5 - benchmark/benchmark.js | 272 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 51 - docs/types/test.ts | 92 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 44 - lib/main.js | 144 - package.json | 77 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 619 --- 44 files changed, 4866 insertions(+), 4937 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 (96%) 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 71444dd..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2026-08-15T02:30:50.087Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 5dacce3..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/diagonal) 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 bbaa7c7..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/diagonal) 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 52ddcc8..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: '7 19 * * 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 + + ```
@@ -207,7 +198,7 @@ console.log( ndarray2array( y ) ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. 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 3a0a3bc..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,272 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var diagonal = require( './../lib' ); - - -// MAIN // - -bench( format( '%s::ndims=2,ctor=base', pkg ), function benchmark( b ) { - var values; - var v; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = diagonal( values[ i%values.length ], [ 0, 1 ], 0, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::ndims=2,ctor=non-base', pkg ), function benchmark( b ) { - var values; - var v; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - values = [ - empty( [ 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = diagonal( values[ i%values.length ], [ 0, 1 ], 0, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::ndims=3,ctor=base', pkg ), function benchmark( b ) { - var values; - var v; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = diagonal( values[ i%values.length ], [ 1, 2 ], 0, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::ndims=3,ctor=non-base', pkg ), function benchmark( b ) { - var values; - var v; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - values = [ - empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = diagonal( values[ i%values.length ], [ 1, 2 ], 0, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::ndims=4,ctor=base', pkg ), function benchmark( b ) { - var values; - var v; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = diagonal( values[ i%values.length ], [ 2, 3 ], 0, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::ndims=4,ctor=non-base', pkg ), function benchmark( b ) { - var values; - var v; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - values = [ - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = diagonal( values[ i%values.length ], [ 2, 3 ], 0, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::ndims=5,ctor=base', pkg ), function benchmark( b ) { - var values; - var v; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = diagonal( values[ i%values.length ], [ 3, 4 ], 0, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::ndims=5,ctor=non-base', pkg ), function benchmark( b ) { - var values; - var v; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - values = [ - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = diagonal( values[ i%values.length ], [ 3, 4 ], 0, false ); - if ( typeof v !== '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 437ecb7..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/diagonal" -%% click B href "https://github.com/stdlib-js/ndarray-base-diagonal/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-diagonal/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-diagonal/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-diagonal/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-diagonal/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/diagonal -[production-url]: https://github.com/stdlib-js/ndarray-base-diagonal/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-diagonal/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-diagonal/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-diagonal/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-diagonal/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-diagonal/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-diagonal/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 a7ab3b4..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import diagonal from '../docs/types/index'; -export = diagonal; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 4fab4ac..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var M=function(e,r){return function(){try{return r||e((r={exports:{}}).exports,r),r.exports}catch(t){throw (r=0, t)}};};var y=M(function(T,b){ -var R=require('@stdlib/ndarray-base-to-unique-normalized-indices/dist'),S=require('@stdlib/ndarray-base-dtype/dist'),V=require('@stdlib/ndarray-base-shape/dist'),D=require('@stdlib/ndarray-base-strides/dist'),N=require('@stdlib/ndarray-base-offset/dist'),O=require('@stdlib/ndarray-base-order/dist'),j=require('@stdlib/ndarray-base-data-buffer/dist'),q=require('@stdlib/array-base-join/dist'),z=require('@stdlib/math-base-special-min/dist'),l=require('@stdlib/error-tools-fmtprodmsg/dist');function F(e,r,t,E){var s,f,a,v,p,w,o,d,h,c,m,g,i,u,n;if(r.length!==2)throw new RangeError(l('2lXKM',q(r,", ")));if(o=V(e),a=o.length,a<2)throw new RangeError(l('2lXKN',a));if(d=D(e),i=R(r,a-1),i===null)throw new RangeError(l('2lXHO',a,a-1,q(r,", ")));if(i.length!==r.length)throw new Error(l('2lXHP',q(r,", ")));for(h=d[i[0]],c=d[i[1]],g=t>0?t:0,m=g-t,p=o[i[0]]-m,w=o[i[1]]-g,u=z(p,w),u<0&&(u=0),f=N(e),u>0&&(f+=g*c+m*h),v=[],s=[],n=0;n 0`, the function returns the diagonal above the main diagonal; and when `k < 0`, the function returns the diagonal below the main diagonal.\n* - The returned ndarray is a **view** of the input ndarray. Accordingly, writing to the original ndarray will **mutate** the returned ndarray and vice versa.\n* - The `writable` parameter **only** applies to ndarray constructors supporting **read-only** instances.\n*\n* @param {ndarray} x - input array\n* @param {IntegerArray} dims - dimension indices defining the plane from which to extract the diagonal\n* @param {integer} k - diagonal offset\n* @param {boolean} writable - boolean indicating whether the returned ndarray should be writable\n* @throws {RangeError} must provide exactly two dimension indices\n* @throws {RangeError} must provide an ndarray having two or more dimensions\n* @throws {RangeError} must provide valid dimension indices\n* @throws {Error} must provide unique dimension indices\n* @returns {ndarray} ndarray view\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] );\n* // returns [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ]\n*\n* var y = diagonal( x, [ 0, 1 ], 0, false );\n* // returns [ 1.0, 5.0, 9.0 ]\n*/\nfunction diagonal( x, dims, k, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar ndims;\n\tvar shape;\n\tvar rows;\n\tvar cols;\n\tvar sh;\n\tvar st;\n\tvar sr;\n\tvar sc;\n\tvar ro;\n\tvar co;\n\tvar d;\n\tvar L;\n\tvar i;\n\n\tif ( dims.length !== 2 ) {\n\t\tthrow new RangeError( format( 'invalid argument. Must provide exactly two dimension indices. Value: `[%s]`.', join( dims, ', ' ) ) );\n\t}\n\tsh = getShape( x );\n\tndims = sh.length;\n\tif ( ndims < 2 ) {\n\t\tthrow new RangeError( format( 'invalid argument. First argument must be an ndarray having two or more dimensions. Number of dimensions: %d.', ndims ) );\n\t}\n\tst = getStrides( x );\n\n\t// Resolve dimension indices...\n\td = toUniqueNormalizedIndices( dims, ndims-1 );\n\tif ( d === null ) {\n\t\tthrow new RangeError( format( 'invalid argument. Specified dimension index is out-of-bounds. Must be on the interval: [-%u, %u]. Value: `[%s]`.', ndims, ndims-1, join( dims, ', ' ) ) );\n\t}\n\tif ( d.length !== dims.length ) {\n\t\tthrow new Error( format( 'invalid argument. Must provide unique dimension indices. Value: `[%s]`.', join( dims, ', ' ) ) );\n\t}\n\tsr = st[ d[0] ];\n\tsc = st[ d[1] ];\n\n\t// Resolve the row and column offsets corresponding to the diagonal offset `k = column - row`:\n\tco = ( k > 0 ) ? k : 0;\n\tro = co - k;\n\n\t// Compute the length of the diagonal:\n\trows = sh[ d[0] ] - ro;\n\tcols = sh[ d[1] ] - co;\n\tL = min( rows, cols );\n\tif ( L < 0 ) {\n\t\tL = 0;\n\t}\n\n\t// Adjust the offset so that we point to the first element along the specified diagonal:\n\toffset = getOffset( x );\n\tif ( L > 0 ) {\n\t\toffset += ( co*sc ) + ( ro*sr );\n\t}\n\n\t// Drop the specified dimensions and append the diagonal dimension:\n\tshape = [];\n\tstrides = [];\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tif ( i === d[0] || i === d[1] ) {\n\t\t\tcontinue;\n\t\t}\n\t\tshape.push( sh[ i ] );\n\t\tstrides.push( st[ i ] );\n\t}\n\tshape.push( L );\n\tstrides.push( sr + sc );\n\n\treturn new x.constructor( getDType( x ), getData( x ), shape, strides, offset, getOrder( x ), { // eslint-disable-line max-len\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nmodule.exports = diagonal;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Return a view of the diagonal of a matrix (or stack of matrices).\n*\n* @module @stdlib/ndarray-base-diagonal\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var diagonal = require( '@stdlib/ndarray-base-diagonal' );\n*\n* var x = array( [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] );\n* // returns [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ]\n*\n* var y = diagonal( x, [ 0, 1 ], 0, false );\n* // returns [ 1.0, 5.0, 9.0 ]\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "iIAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAA4B,QAAS,mDAAoD,EACzFC,EAAW,QAAS,4BAA6B,EACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAa,QAAS,8BAA+B,EACrDC,EAAY,QAAS,6BAA8B,EACnDC,EAAW,QAAS,4BAA6B,EACjDC,EAAU,QAAS,kCAAmC,EACtDC,EAAO,QAAS,yBAA0B,EAC1CC,EAAM,QAAS,+BAAgC,EAC/CC,EAAS,QAAS,uBAAwB,EAmC9C,SAASC,EAAUC,EAAGC,EAAMC,EAAGC,EAAW,CACzC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAKjB,EAAK,SAAW,EACpB,MAAM,IAAI,WAAYH,EAAQ,+EAAgFF,EAAMK,EAAM,IAAK,CAAE,CAAE,EAIpI,GAFAS,EAAKnB,EAAUS,CAAE,EACjBM,EAAQI,EAAG,OACNJ,EAAQ,EACZ,MAAM,IAAI,WAAYR,EAAQ,+GAAgHQ,CAAM,CAAE,EAMvJ,GAJAK,EAAKnB,EAAYQ,CAAE,EAGnBgB,EAAI3B,EAA2BY,EAAMK,EAAM,CAAE,EACxCU,IAAM,KACV,MAAM,IAAI,WAAYlB,EAAQ,mHAAoHQ,EAAOA,EAAM,EAAGV,EAAMK,EAAM,IAAK,CAAE,CAAE,EAExL,GAAKe,EAAE,SAAWf,EAAK,OACtB,MAAM,IAAI,MAAOH,EAAQ,0EAA2EF,EAAMK,EAAM,IAAK,CAAE,CAAE,EA0B1H,IAxBAW,EAAKD,EAAIK,EAAE,CAAC,CAAE,EACdH,EAAKF,EAAIK,EAAE,CAAC,CAAE,EAGdD,EAAOb,EAAI,EAAMA,EAAI,EACrBY,EAAKC,EAAKb,EAGVM,EAAOE,EAAIM,EAAE,CAAC,CAAE,EAAIF,EACpBL,EAAOC,EAAIM,EAAE,CAAC,CAAE,EAAID,EACpBE,EAAIpB,EAAKW,EAAMC,CAAK,EACfQ,EAAI,IACRA,EAAI,GAILZ,EAASZ,EAAWO,CAAE,EACjBiB,EAAI,IACRZ,GAAYU,EAAGF,EAASC,EAAGF,GAI5BL,EAAQ,CAAC,EACTH,EAAU,CAAC,EACLc,EAAI,EAAGA,EAAIZ,EAAOY,IAClBA,IAAMF,EAAE,CAAC,GAAKE,IAAMF,EAAE,CAAC,IAG5BT,EAAM,KAAMG,EAAIQ,CAAE,CAAE,EACpBd,EAAQ,KAAMO,EAAIO,CAAE,CAAE,GAEvB,OAAAX,EAAM,KAAMU,CAAE,EACdb,EAAQ,KAAMQ,EAAKC,CAAG,EAEf,IAAIb,EAAE,YAAaV,EAAUU,CAAE,EAAGL,EAASK,CAAE,EAAGO,EAAOH,EAASC,EAAQX,EAAUM,CAAE,EAAG,CAC7F,SAAY,CAACG,CACd,CAAC,CACF,CAKAf,EAAO,QAAUW,ICzGjB,IAAIoB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "toUniqueNormalizedIndices", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "getData", "join", "min", "format", "diagonal", "x", "dims", "k", "writable", "strides", "offset", "ndims", "shape", "rows", "cols", "sh", "st", "sr", "sc", "ro", "co", "d", "L", "i", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index da74ae9..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,51 +0,0 @@ - -{{alias}}( x, dims, k, writable ) - Returns a view of the diagonal of a matrix (or stack of matrices). - - The order of the dimension indices contained in `dims` matters. The first - element specifies the row-like dimension. The second element specifies - the column-like dimension. - - Each provided dimension index must reside on the interval [-ndims, ndims-1]. - - The diagonal offset `k` is interpreted as `column - row`. Accordingly, - when `k = 0`, the function returns the main diagonal; when `k > 0`, the - function returns the diagonal above the main diagonal; and when `k < 0`, - the function returns the diagonal below the main diagonal. - - The returned ndarray is a *view* of the input ndarray. Accordingly, - writing to the original ndarray will mutate the returned ndarray and - vice versa. - - The `writable` parameter only applies to ndarray constructors supporting - read-only instances. - - Parameters - ---------- - x: ndarray - Input array. - - dims: ArrayLikeObject - Dimension indices defining the plane from which to extract the diagonal. - - k: integer - Diagonal offset. - - writable: boolean - Boolean indicating whether the returned ndarray should be writable. - - Returns - ------- - out: ndarray - Output array view. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ) - [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] - > var y = {{alias}}( x, [ 0, 1 ], 0, false ) - [ 1.0, 4.0 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 513a253..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,92 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 zeros = require( '@stdlib/ndarray-zeros' ); -import diagonal = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - - diagonal( x, [ 0, 1 ], 0, false ); // $ExpectType float64ndarray -} - -// The compiler throws an error if the function is not provided a first argument which is an ndarray... -{ - diagonal( '5', [ 0, 1 ], 0, false ); // $ExpectError - diagonal( 5, [ 0, 1 ], 0, false ); // $ExpectError - diagonal( true, [ 0, 1 ], 0, false ); // $ExpectError - diagonal( false, [ 0, 1 ], 0, false ); // $ExpectError - diagonal( null, [ 0, 1 ], 0, false ); // $ExpectError - diagonal( {}, [ 0, 1 ], 0, false ); // $ExpectError - diagonal( [ '5' ], [ 0, 1 ], 0, false ); // $ExpectError - diagonal( ( x: number ): number => x, [ 0, 1 ], 0, false ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a second argument which is an array-like object containing numbers... -{ - const x = zeros( [ 2, 2 ] ); - - diagonal( x, '5', 0, false ); // $ExpectError - diagonal( x, 5, 0, false ); // $ExpectError - diagonal( x, true, 0, false ); // $ExpectError - diagonal( x, false, 0, false ); // $ExpectError - diagonal( x, null, 0, false ); // $ExpectError - diagonal( x, {}, 0, false ); // $ExpectError - diagonal( x, [ '5' ], 0, false ); // $ExpectError - diagonal( x, ( x: number ): number => x, 0, false ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a third argument which is a number... -{ - const x = zeros( [ 2, 2 ] ); - - diagonal( x, [ 0, 1 ], '5', false ); // $ExpectError - diagonal( x, [ 0, 1 ], true, false ); // $ExpectError - diagonal( x, [ 0, 1 ], false, false ); // $ExpectError - diagonal( x, [ 0, 1 ], null, false ); // $ExpectError - diagonal( x, [ 0, 1 ], {}, false ); // $ExpectError - diagonal( x, [ 0, 1 ], [], false ); // $ExpectError - diagonal( x, [ 0, 1 ], ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a fourth argument which is a boolean... -{ - const x = zeros( [ 2, 2 ] ); - - diagonal( x, [ 0, 1 ], 0, '5' ); // $ExpectError - diagonal( x, [ 0, 1 ], 0, 5 ); // $ExpectError - diagonal( x, [ 0, 1 ], 0, null ); // $ExpectError - diagonal( x, [ 0, 1 ], 0, {} ); // $ExpectError - diagonal( x, [ 0, 1 ], 0, [] ); // $ExpectError - diagonal( x, [ 0, 1 ], 0, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = zeros( [ 2, 2 ] ); - - diagonal(); // $ExpectError - diagonal( x ); // $ExpectError - diagonal( x, [ 0, 1 ] ); // $ExpectError - diagonal( x, [ 0, 1 ], 0 ); // $ExpectError - diagonal( x, [ 0, 1 ], 0, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 742dc69..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 uniform = require( '@stdlib/random-uniform' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var diagonal = require( './../lib' ); - -// Create a stack of matrices: -var x = uniform( [ 2, 3, 3 ], -10.0, 10.0, { - 'dtype': 'float64' -}); -console.log( ndarray2array( x ) ); - -// Extract the main diagonals from the stack: -var y = diagonal( x, [ 1, 2 ], 0, false ); -console.log( ndarray2array( y ) ); - -// Extract super-diagonals from the stack: -y = diagonal( x, [ 1, 2 ], 1, false ); -console.log( ndarray2array( y ) ); - -// Extract sub-diagonals from the stack: -y = diagonal( x, [ 1, 2 ], -1, false ); -console.log( ndarray2array( y ) ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index 5ab7709..9e71468 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/array'; import { typedndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..8e4e50f --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-to-unique-normalized-indices@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.3-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.3-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.3-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.3-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.3-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-join@v0.1.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-min@v0.2.4-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";function l(l,h,p,j){var u,v,f,b,g,c,x,y,w,E,M,R,V,q,z;if(2!==h.length)throw new RangeError(a("invalid argument. Must provide exactly two dimension indices. Value: `[%s]`.",o(h,", ")));if((f=(x=r(l)).length)<2)throw new RangeError(a("invalid argument. First argument must be an ndarray having two or more dimensions. Number of dimensions: %d.",f));if(y=n(l),null===(V=e(h,f-1)))throw new RangeError(a("invalid argument. Specified dimension index is out-of-bounds. Must be on the interval: [-%u, %u]. Value: `[%s]`.",f,f-1,o(h,", ")));if(V.length!==h.length)throw new Error(a("invalid argument. Must provide unique dimension indices. Value: `[%s]`.",o(h,", ")));for(w=y[V[0]],E=y[V[1]],M=(R=p>0?p:0)-p,g=x[V[0]]-M,c=x[V[1]]-R,(q=m(g,c))<0&&(q=0),v=t(l),q>0&&(v+=R*E+M*w),b=[],u=[],z=0;z 0`, the function returns the diagonal above the main diagonal; and when `k < 0`, the function returns the diagonal below the main diagonal.\n* - The returned ndarray is a **view** of the input ndarray. Accordingly, writing to the original ndarray will **mutate** the returned ndarray and vice versa.\n* - The `writable` parameter **only** applies to ndarray constructors supporting **read-only** instances.\n*\n* @param {ndarray} x - input array\n* @param {IntegerArray} dims - dimension indices defining the plane from which to extract the diagonal\n* @param {integer} k - diagonal offset\n* @param {boolean} writable - boolean indicating whether the returned ndarray should be writable\n* @throws {RangeError} must provide exactly two dimension indices\n* @throws {RangeError} must provide an ndarray having two or more dimensions\n* @throws {RangeError} must provide valid dimension indices\n* @throws {Error} must provide unique dimension indices\n* @returns {ndarray} ndarray view\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] );\n* // returns [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ]\n*\n* var y = diagonal( x, [ 0, 1 ], 0, false );\n* // returns [ 1.0, 5.0, 9.0 ]\n*/\nfunction diagonal( x, dims, k, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar ndims;\n\tvar shape;\n\tvar rows;\n\tvar cols;\n\tvar sh;\n\tvar st;\n\tvar sr;\n\tvar sc;\n\tvar ro;\n\tvar co;\n\tvar d;\n\tvar L;\n\tvar i;\n\n\tif ( dims.length !== 2 ) {\n\t\tthrow new RangeError( format( 'invalid argument. Must provide exactly two dimension indices. Value: `[%s]`.', join( dims, ', ' ) ) );\n\t}\n\tsh = getShape( x );\n\tndims = sh.length;\n\tif ( ndims < 2 ) {\n\t\tthrow new RangeError( format( 'invalid argument. First argument must be an ndarray having two or more dimensions. Number of dimensions: %d.', ndims ) );\n\t}\n\tst = getStrides( x );\n\n\t// Resolve dimension indices...\n\td = toUniqueNormalizedIndices( dims, ndims-1 );\n\tif ( d === null ) {\n\t\tthrow new RangeError( format( 'invalid argument. Specified dimension index is out-of-bounds. Must be on the interval: [-%u, %u]. Value: `[%s]`.', ndims, ndims-1, join( dims, ', ' ) ) );\n\t}\n\tif ( d.length !== dims.length ) {\n\t\tthrow new Error( format( 'invalid argument. Must provide unique dimension indices. Value: `[%s]`.', join( dims, ', ' ) ) );\n\t}\n\tsr = st[ d[0] ];\n\tsc = st[ d[1] ];\n\n\t// Resolve the row and column offsets corresponding to the diagonal offset `k = column - row`:\n\tco = ( k > 0 ) ? k : 0;\n\tro = co - k;\n\n\t// Compute the length of the diagonal:\n\trows = sh[ d[0] ] - ro;\n\tcols = sh[ d[1] ] - co;\n\tL = min( rows, cols );\n\tif ( L < 0 ) {\n\t\tL = 0;\n\t}\n\n\t// Adjust the offset so that we point to the first element along the specified diagonal:\n\toffset = getOffset( x );\n\tif ( L > 0 ) {\n\t\toffset += ( co*sc ) + ( ro*sr );\n\t}\n\n\t// Drop the specified dimensions and append the diagonal dimension:\n\tshape = [];\n\tstrides = [];\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tif ( i === d[0] || i === d[1] ) {\n\t\t\tcontinue;\n\t\t}\n\t\tshape.push( sh[ i ] );\n\t\tstrides.push( st[ i ] );\n\t}\n\tshape.push( L );\n\tstrides.push( sr + sc );\n\n\treturn new x.constructor( getDType( x ), getData( x ), shape, strides, offset, getOrder( x ), { // eslint-disable-line max-len\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default diagonal;\n"],"names":["diagonal","x","dims","k","writable","strides","offset","ndims","shape","rows","cols","sh","st","sr","sc","ro","co","d","L","i","length","RangeError","format","join","getShape","getStrides","toUniqueNormalizedIndices","Error","min","getOffset","push","constructor","getDType","getData","getOrder","readonly"],"mappings":";;s8BAkEA,SAASA,EAAUC,EAAGC,EAAMC,EAAGC,GAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAqB,IAAhBjB,EAAKkB,OACT,MAAM,IAAIC,WAAYC,EAAQ,+EAAgFC,EAAMrB,EAAM,QAI3H,IADAK,GADAI,EAAKa,EAAUvB,IACJmB,QACE,EACZ,MAAM,IAAIC,WAAYC,EAAQ,+GAAgHf,IAM/I,GAJAK,EAAKa,EAAYxB,GAIN,QADXgB,EAAIS,EAA2BxB,EAAMK,EAAM,IAE1C,MAAM,IAAIc,WAAYC,EAAQ,mHAAoHf,EAAOA,EAAM,EAAGgB,EAAMrB,EAAM,QAE/K,GAAKe,EAAEG,SAAWlB,EAAKkB,OACtB,MAAM,IAAIO,MAAOL,EAAQ,0EAA2EC,EAAMrB,EAAM,QA0BjH,IAxBAW,EAAKD,EAAIK,EAAE,IACXH,EAAKF,EAAIK,EAAE,IAIXF,GADAC,EAAOb,EAAI,EAAMA,EAAI,GACXA,EAGVM,EAAOE,EAAIM,EAAE,IAAOF,EACpBL,EAAOC,EAAIM,EAAE,IAAOD,GACpBE,EAAIU,EAAKnB,EAAMC,IACN,IACRQ,EAAI,GAILZ,EAASuB,EAAW5B,GACfiB,EAAI,IACRZ,GAAYU,EAAGF,EAASC,EAAGF,GAI5BL,EAAQ,GACRH,EAAU,GACJc,EAAI,EAAGA,EAAIZ,EAAOY,IAClBA,IAAMF,EAAE,IAAME,IAAMF,EAAE,KAG3BT,EAAMsB,KAAMnB,EAAIQ,IAChBd,EAAQyB,KAAMlB,EAAIO,KAKnB,OAHAX,EAAMsB,KAAMZ,GACZb,EAAQyB,KAAMjB,EAAKC,GAEZ,IAAIb,EAAE8B,YAAaC,EAAU/B,GAAKgC,EAAShC,GAAKO,EAAOH,EAASC,EAAQ4B,EAAUjC,GAAK,CAC7FkC,UAAa/B,GAEf"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a541856..0000000 --- a/lib/index.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Return a view of the diagonal of a matrix (or stack of matrices). -* -* @module @stdlib/ndarray-base-diagonal -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var diagonal = require( '@stdlib/ndarray-base-diagonal' ); -* -* var x = array( [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] ); -* // returns [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] -* -* var y = diagonal( x, [ 0, 1 ], 0, false ); -* // returns [ 1.0, 5.0, 9.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 acf301d..0000000 --- a/lib/main.js +++ /dev/null @@ -1,144 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var toUniqueNormalizedIndices = require( '@stdlib/ndarray-base-to-unique-normalized-indices' ); -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); -var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var join = require( '@stdlib/array-base-join' ); -var min = require( '@stdlib/math-base-special-min' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns a view of the diagonal of a matrix (or stack of matrices). -* -* ## Notes -* -* - The order of the dimension indices contained in `dims` matters. The first element specifies the row-like dimension. The second element specifies the column-like dimension. -* - Each provided dimension index must reside on the interval `[-ndims, ndims-1]`. -* - The diagonal offset `k` is interpreted as `column - row`. Accordingly, when `k = 0`, the function returns the main diagonal; when `k > 0`, the function returns the diagonal above the main diagonal; and when `k < 0`, the function returns the diagonal below the main diagonal. -* - The returned ndarray is a **view** of the input ndarray. Accordingly, writing to the original ndarray will **mutate** the returned ndarray and vice versa. -* - The `writable` parameter **only** applies to ndarray constructors supporting **read-only** instances. -* -* @param {ndarray} x - input array -* @param {IntegerArray} dims - dimension indices defining the plane from which to extract the diagonal -* @param {integer} k - diagonal offset -* @param {boolean} writable - boolean indicating whether the returned ndarray should be writable -* @throws {RangeError} must provide exactly two dimension indices -* @throws {RangeError} must provide an ndarray having two or more dimensions -* @throws {RangeError} must provide valid dimension indices -* @throws {Error} must provide unique dimension indices -* @returns {ndarray} ndarray view -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] ); -* // returns [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] -* -* var y = diagonal( x, [ 0, 1 ], 0, false ); -* // returns [ 1.0, 5.0, 9.0 ] -*/ -function diagonal( x, dims, k, writable ) { - var strides; - var offset; - var ndims; - var shape; - var rows; - var cols; - var sh; - var st; - var sr; - var sc; - var ro; - var co; - var d; - var L; - var i; - - if ( dims.length !== 2 ) { - throw new RangeError( format( 'invalid argument. Must provide exactly two dimension indices. Value: `[%s]`.', join( dims, ', ' ) ) ); - } - sh = getShape( x ); - ndims = sh.length; - if ( ndims < 2 ) { - throw new RangeError( format( 'invalid argument. First argument must be an ndarray having two or more dimensions. Number of dimensions: %d.', ndims ) ); - } - st = getStrides( x ); - - // Resolve dimension indices... - d = toUniqueNormalizedIndices( dims, ndims-1 ); - if ( d === null ) { - throw new RangeError( format( 'invalid argument. Specified dimension index is out-of-bounds. Must be on the interval: [-%u, %u]. Value: `[%s]`.', ndims, ndims-1, join( dims, ', ' ) ) ); - } - if ( d.length !== dims.length ) { - throw new Error( format( 'invalid argument. Must provide unique dimension indices. Value: `[%s]`.', join( dims, ', ' ) ) ); - } - sr = st[ d[0] ]; - sc = st[ d[1] ]; - - // Resolve the row and column offsets corresponding to the diagonal offset `k = column - row`: - co = ( k > 0 ) ? k : 0; - ro = co - k; - - // Compute the length of the diagonal: - rows = sh[ d[0] ] - ro; - cols = sh[ d[1] ] - co; - L = min( rows, cols ); - if ( L < 0 ) { - L = 0; - } - - // Adjust the offset so that we point to the first element along the specified diagonal: - offset = getOffset( x ); - if ( L > 0 ) { - offset += ( co*sc ) + ( ro*sr ); - } - - // Drop the specified dimensions and append the diagonal dimension: - shape = []; - strides = []; - for ( i = 0; i < ndims; i++ ) { - if ( i === d[0] || i === d[1] ) { - continue; - } - shape.push( sh[ i ] ); - strides.push( st[ i ] ); - } - shape.push( L ); - strides.push( sr + sc ); - - return new x.constructor( getDType( x ), getData( x ), shape, strides, offset, getOrder( x ), { // eslint-disable-line max-len - 'readonly': !writable - }); -} - - -// EXPORTS // - -module.exports = diagonal; diff --git a/package.json b/package.json index 3cdb2df..1e256a2 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Return a view of the diagonal of a matrix (or stack of matrices).", "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,56 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-join": "^0.1.2", - "@stdlib/math-base-special-min": "^0.2.4", - "@stdlib/ndarray-base-data-buffer": "^0.2.3", - "@stdlib/ndarray-base-dtype": "^0.2.3", - "@stdlib/ndarray-base-offset": "^0.2.3", - "@stdlib/ndarray-base-order": "^0.2.3", - "@stdlib/ndarray-base-shape": "^0.2.3", - "@stdlib/ndarray-base-strides": "^0.2.3", - "@stdlib/ndarray-base-to-unique-normalized-indices": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3", - "@stdlib/types": "^0.5.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.2.3", - "@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-data-buffer": "^0.2.3", - "@stdlib/ndarray-empty": "^0.3.1", - "@stdlib/ndarray-offset": "^0.2.3", - "@stdlib/ndarray-order": "^0.2.3", - "@stdlib/ndarray-shape": "^0.2.3", - "@stdlib/ndarray-stride": "^0.2.3", - "@stdlib/ndarray-strides": "^0.2.3", - "@stdlib/ndarray-to-array": "^0.2.2", - "@stdlib/random-uniform": "^0.1.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..ecc38ac --- /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 fabc8fa..0000000 --- a/test/test.js +++ /dev/null @@ -1,619 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var array = require( '@stdlib/ndarray-array' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var getStrides = require( '@stdlib/ndarray-strides' ); -var getStride = require( '@stdlib/ndarray-stride' ); -var getOffset = require( '@stdlib/ndarray-offset' ); -var getData = require( '@stdlib/ndarray-data-buffer' ); -var getOrder = require( '@stdlib/ndarray-order' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var diagonal = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof diagonal, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided exactly two dimension indices', function test( t ) { - var values; - var x; - var i; - - x = new ndarray( 'float64', new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); - - values = [ - [], - [ 0 ], - [ 0, 1, 0 ], - [ 0, 1, 0, 1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ].length + ' dimension indices' ); - } - t.end(); - - function badValue( dims ) { - return function badValue() { - diagonal( x, dims, 0, false ); - }; - } -}); - -tape( 'the function throws an error if provided an input ndarray with fewer than two dimensions', function test( t ) { - var values; - var i; - - values = [ - new ndarray( 'float64', new Float64Array( [ 5.0 ] ), [], [ 0 ], 0, 'row-major' ), - new ndarray( 'float64', new Float64Array( [ 1.0, 2.0, 3.0 ] ), [ 3 ], [ 1 ], 0, 'row-major' ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided an input ndarray with '+values[ i ].ndims+' dimensions' ); - } - t.end(); - - function badValue( x ) { - return function badValue() { - diagonal( x, [ 0, 1 ], 0, false ); - }; - } -}); - -tape( 'the function throws an error if provided out-of-bounds dimension indices', function test( t ) { - var values; - var x; - var i; - - x = new ndarray( 'float64', new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); - - values = [ - [ 0, 2 ], - [ 2, 0 ], - [ -3, 0 ], - [ 0, -3 ], - [ 10, 0 ], - [ 0, 10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided dimension indices ['+values[ i ]+']' ); - } - t.end(); - - function badValue( dims ) { - return function badValue() { - diagonal( x, dims, 0, false ); - }; - } -}); - -tape( 'the function throws an error if provided duplicate dimension indices', function test( t ) { - var values; - var x; - var i; - - x = new ndarray( 'float64', new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ), [ 2, 2, 2 ], [ 4, 2, 1 ], 0, 'row-major' ); - - values = [ - [ 0, 0 ], - [ 1, 1 ], - [ 2, 2 ], - [ 0, -3 ], - [ -2, 1 ], - [ -1, 2 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided dimension indices ['+values[ i ]+']' ); - } - t.end(); - - function badValue( dims ) { - return function badValue() { - diagonal( x, dims, 0, false ); - }; - } -}); - -tape( 'the function returns a view of the main diagonal of a square matrix', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); - - y = diagonal( x, [ 0, 1 ], 0, false ); - - expected = [ 3 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 1, 5, 9 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.strictEqual( getData( y ), getData( x ), 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of the super-diagonal of a square matrix', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); - - y = diagonal( x, [ 0, 1 ], 1, false ); - - expected = [ 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 2, 6 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], 2, false ); - - expected = [ 1 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 3 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of the sub-diagonal of a square matrix', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); - - y = diagonal( x, [ 0, 1 ], -1, false ); - - expected = [ 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 4, 8 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], -2, false ); - - expected = [ 1 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 7 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of the diagonal of a non-square matrix (M < N)', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ 1, 2, 3, 4 ], [ 5, 6, 7, 8 ] ] ); - - y = diagonal( x, [ 0, 1 ], 0, false ); - - expected = [ 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 1, 6 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], 2, false ); - - expected = [ 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 3, 8 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], -1, false ); - - expected = [ 1 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 5 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of the diagonal of a non-square matrix (M > N)', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ], [ 7, 8 ] ] ); - - y = diagonal( x, [ 0, 1 ], 0, false ); - - expected = [ 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 1, 4 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], -2, false ); - - expected = [ 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 5, 8 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], 1, false ); - - expected = [ 1 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 2 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an empty view when the diagonal offset is out-of-bounds', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); - - y = diagonal( x, [ 0, 1 ], 3, false ); - - expected = [ 0 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = []; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], -3, false ); - - expected = [ 0 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = []; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], 100, false ); - - expected = [ 0 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = []; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function swaps the row-like and column-like dimensions when `dims` is reversed', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); - - y = diagonal( x, [ 1, 0 ], 1, false ); - - expected = [ 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 4, 8 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 1, 0 ], -1, false ); - - expected = [ 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 2, 6 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of the diagonals of a stack of matrices', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); - - y = diagonal( x, [ 1, 2 ], 0, false ); - - expected = [ 2, 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ [ 1, 4 ], [ 5, 8 ] ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 1, 2 ], 1, false ); - - expected = [ 2, 1 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ [ 2 ], [ 6 ] ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 1, 2 ], -1, false ); - - expected = [ 2, 1 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ [ 3 ], [ 7 ] ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function appends the diagonal dimension as the trailing dimension of the output ndarray', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ [ 1, 2, 3 ], [ 4, 5, 6 ] ], [ [ 7, 8, 9 ], [ 10, 11, 12 ] ] ] ); - - y = diagonal( x, [ 0, 2 ], 0, false ); - - expected = [ 2, 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ [ 1, 8 ], [ 4, 11 ] ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function normalizes negative dimension indices', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); - - y = diagonal( x, [ -2, -1 ], 0, false ); - - expected = [ 3 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 1, 5, 9 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a column-major ndarray when the input ndarray is column-major', function test( t ) { - var expected; - var x; - var y; - - x = ndarray( 'generic', [ 1, 4, 7, 2, 5, 8, 3, 6, 9 ], [ 3, 3 ], [ 1, 3 ], 0, 'column-major' ); - - y = diagonal( x, [ 0, 1 ], 0, false ); - - expected = 'column-major'; - t.strictEqual( getOrder( y ), expected, 'returns expected value' ); - - expected = [ 3 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 1, 5, 9 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a writable ndarray when `writable` is `true`', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); - y = diagonal( x, [ 0, 1 ], 0, true ); - - t.strictEqual( isReadOnly( y ), false, 'returns expected value' ); - t.strictEqual( getData( y ), getData( x ), 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a read-only ndarray when `writable` is `false`', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); - y = diagonal( x, [ 0, 1 ], 0, false ); - - t.strictEqual( isReadOnly( y ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function constructs the output by retaining all dimensions except the specified dimensions and appending the diagonal dimension', function test( t ) { - var expected; - var x; - var y; - - x = array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ], { - 'shape': [ 3, 2, 2 ] - }); - - y = diagonal( x, [ 1, 2 ], 0, false ); - - expected = [ 3, 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 4, 3 ]; - t.deepEqual( getStrides( y ), expected, 'returns expected value' ); - - expected = getOffset( x ); - t.strictEqual( getOffset( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function adjusts the offset to point to the first element of the requested diagonal', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); - - y = diagonal( x, [ 0, 1 ], 1, false ); - - expected = getOffset( x ) + getStride( x, 1 ); - t.strictEqual( getOffset( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], -1, false ); - - expected = getOffset( x ) + getStride( x, 0 ); - t.strictEqual( getOffset( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports input ndarrays having a non-zero buffer offset', function test( t ) { - var expected; - var x; - var y; - - x = ndarray( 'generic', [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], [ 3, 3 ], [ 3, 1 ], 1, 'row-major' ); - - y = diagonal( x, [ 0, 1 ], 0, false ); - - expected = [ 3 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 1, 5, 9 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.strictEqual( getData( y ), getData( x ), 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], 1, false ); - - expected = [ 2, 6 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ 0, 1 ], -1, false ); - - expected = [ 4, 8 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports 4D inputs with non-trailing `dims`', function test( t ) { - var expected; - var arr; - var x; - var y; - - arr = [ - [ - [ - [ 0, 1 ], - [ 2, 3 ], - [ 4, 5 ] - ], - [ - [ 6, 7 ], - [ 8, 9 ], - [ 10, 11 ] - ], - [ - [ 12, 13 ], - [ 14, 15 ], - [ 16, 17 ] - ] - ], - [ - [ - [ 18, 19 ], - [ 20, 21 ], - [ 22, 23 ] - ], - [ - [ 24, 25 ], - [ 26, 27 ], - [ 28, 29 ] - ], - [ - [ 30, 31 ], - [ 32, 33 ], - [ 34, 35 ] - ] - ] - ]; - x = array( arr ); - y = diagonal( x, [ 1, 2 ], 0, false ); - expected = [ 2, 2, 3 ]; - - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ - [ - [ 0, 8, 16 ], - [ 1, 9, 17 ] - ], - [ - [ 18, 26, 34 ], - [ 19, 27, 35 ] - ] - ]; - - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - t.strictEqual( getData( y ), getData( x ), 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports negative dimension indices combined with a non-zero `k`', function test( t ) { - var expected; - var x; - var y; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); - y = diagonal( x, [ -2, -1 ], 1, false ); - - expected = [ 2 ]; - t.deepEqual( getShape( y ), expected, 'returns expected value' ); - - expected = [ 2, 6 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - y = diagonal( x, [ -2, -1 ], -1, false ); - - expected = [ 4, 8 ]; - t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); - - t.end(); -});