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 2cd2345..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2026-08-20T03:06:52.289Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 879d78b..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/includes) 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 b188b3a..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/includes) 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 7625fb7..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: '10 22 * * 2' - - # 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 + + ```
@@ -309,7 +306,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]. @@ -372,13 +369,13 @@ Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-includes/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm -[@stdlib/ndarray/mostly-safe-casts]: https://github.com/stdlib-js/ndarray-mostly-safe-casts +[@stdlib/ndarray/mostly-safe-casts]: https://github.com/stdlib-js/ndarray-mostly-safe-casts/tree/esm -[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.1d.js b/benchmark/benchmark.1d.js deleted file mode 100644 index 914925e..0000000 --- a/benchmark/benchmark.1d.js +++ /dev/null @@ -1,138 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var discreteUniform = require( '@stdlib/random-array-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var includes = require( './../lib' ); - - -// VARIABLES // - -var types = [ 'float64' ]; -var orders = [ 'row-major', 'column-major' ]; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - ndarray length -* @param {NonNegativeIntegerArray} shape - ndarray shape -* @param {string} xtype - ndarray data type -* @param {string} order - memory layout -* @param {NonNegativeIntegerArray} dims - list of dimensions to reduce -* @returns {Function} benchmark function -*/ -function createBenchmark( len, shape, xtype, order, dims ) { - var x; - - x = discreteUniform( len, 1, 100 ); - x = new ndarray( xtype, x, shape, shape2strides( shape, order ), 0, order ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = includes( x, 101, { - 'dims': dims - }); - if ( typeof out !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var dims; - var len; - var min; - var max; - var ord; - var sh; - var t1; - var f; - var i; - var j; - var k; - var n; - var d; - - min = 1; // 10^min - max = 6; // 10^max - - d = [ - [ 0 ], - [] - ]; - - for ( n = 0; n < d.length; n++ ) { - dims = d[ n ]; - for ( k = 0; k < orders.length; k++ ) { - ord = orders[ k ]; - for ( j = 0; j < types.length; j++ ) { - t1 = types[ j ]; - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - sh = [ len ]; - f = createBenchmark( len, sh, t1, ord, dims ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s,dims=[%s]', pkg, sh.length, len, sh.join(','), ord, t1, dims.join(',') ), f ); - } - } - } - } -} - -main(); diff --git a/benchmark/benchmark.2d.js b/benchmark/benchmark.2d.js deleted file mode 100644 index ae88336..0000000 --- a/benchmark/benchmark.2d.js +++ /dev/null @@ -1,151 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var sqrt = require( '@stdlib/math-base-special-sqrt' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var discreteUniform = require( '@stdlib/random-array-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var includes = require( './../lib' ); - - -// VARIABLES // - -var types = [ 'float64' ]; -var orders = [ 'row-major', 'column-major' ]; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - ndarray length -* @param {NonNegativeIntegerArray} shape - ndarray shape -* @param {string} xtype - ndarray data type -* @param {string} order - memory layout -* @param {NonNegativeIntegerArray} dims - list of dimensions to reduce -* @returns {Function} benchmark function -*/ -function createBenchmark( len, shape, xtype, order, dims ) { - var x; - - x = discreteUniform( len, 1, 100 ); - x = new ndarray( xtype, x, shape, shape2strides( shape, order ), 0, order ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = includes( x, 101, { - 'dims': dims - }); - if ( typeof out !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var dims; - var len; - var min; - var max; - var ord; - var sh; - var t1; - var f; - var i; - var j; - var k; - var n; - var d; - - min = 1; // 10^min - max = 6; // 10^max - - d = [ - [ 0, 1 ], - [ 0 ], - [ 1 ], - [] - ]; - - for ( n = 0; n < d.length; n++ ) { - dims = d[ n ]; - for ( k = 0; k < orders.length; k++ ) { - ord = orders[ k ]; - for ( j = 0; j < types.length; j++ ) { - t1 = types[ j ]; - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - sh = [ len/2, 2 ]; - f = createBenchmark( len, sh, t1, ord, dims ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s,dims=[%s]', pkg, sh.length, len, sh.join(','), ord, t1, dims.join(',') ), f ); - - sh = [ 2, len/2 ]; - f = createBenchmark( len, sh, t1, ord, dims ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s,dims=[%s]', pkg, sh.length, len, sh.join(','), ord, t1, dims.join(',') ), f ); - len = floor( sqrt( len ) ); - sh = [ len, len ]; - len *= len; - f = createBenchmark( len, sh, t1, ord, dims ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s,dims=[%s]', pkg, sh.length, len, sh.join(','), ord, t1, dims.join(',') ), f ); - } - } - } - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index e694340..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/includes" -%% click B href "https://github.com/stdlib-js/ndarray-includes/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-includes/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-includes/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-includes/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-includes/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/includes -[production-url]: https://github.com/stdlib-js/ndarray-includes/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-includes/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-includes/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-includes/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-includes/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-includes/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-includes/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 90f394f..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import includes from '../docs/types/index'; -export = includes; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index a7f7da2..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var q=function(r,e){return function(){try{return e||r((e={exports:{}}).exports,e),e.exports}catch(a){throw e=0,a}}};var g=q(function(Or,M){M.exports={dims:null,keepdims:!1}});var b=q(function(jr,T){"use strict";var z=require("@stdlib/assert-is-plain-object"),S=require("@stdlib/assert-has-own-property"),I=require("@stdlib/assert-is-boolean").isPrimitive,N=require("@stdlib/assert-is-integer-array").primitives,F=require("@stdlib/assert-is-empty-collection"),L=require("@stdlib/ndarray-base-to-unique-normalized-indices"),c=require("@stdlib/array-base-join"),m=require("@stdlib/string-format");function P(r,e,a){var i;if(!z(a))return new TypeError(m("invalid argument. Options argument must be an object. Value: `%s`.",a));if(S(a,"keepdims")&&(r.keepdims=a.keepdims,!I(r.keepdims)))return new TypeError(m("invalid option. `%s` option must be a boolean. Option: `%s`.","keepdims",r.keepdims));if(S(a,"dims")){if(r.dims=a.dims,!N(r.dims)&&!F(r.dims))return new TypeError(m("invalid option. `%s` option must be an array of integers. Option: `%s`.","dims",r.dims));if(i=L(r.dims,e-1),i===null)return new RangeError(m("invalid option. `%s` option contains an out-of-bounds dimension index. Option: [%s].","dims",c(r.dims,",")));if(i.length!==r.dims.length)return new Error(m("invalid option. `%s` option contains duplicate indices. Option: [%s].","dims",c(r.dims,",")));if(i.length>e)return new RangeError(m("invalid option. `%s` option specifies more dimensions than exists in the input array. Number of dimensions: %d. Option: [%s].","dims",e,c(r.dims,",")));r.dims=i}return null}T.exports=P});var C=q(function(Vr,V){"use strict";var G=require("@stdlib/ndarray-base-assert-is-scalar-mostly-safe-compatible"),H=require("@stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast"),k=require("@stdlib/assert-is-ndarray-like"),J=require("@stdlib/ndarray-base-unary-reduce-subarray"),K=require("@stdlib/ndarray-base-includes"),Q=require("@stdlib/ndarray-base-spread-dimensions"),U=require("@stdlib/array-base-indices-complement"),W=require("@stdlib/ndarray-shape"),O=require("@stdlib/ndarray-base-order"),X=require("@stdlib/ndarray-base-data-buffer"),Y=require("@stdlib/ndarray-base-strides"),Z=require("@stdlib/ndarray-base-offset"),j=require("@stdlib/ndarray-base-dtype"),_=require("@stdlib/ndarray-empty"),$=require("@stdlib/ndarray-base-ctor"),x=require("@stdlib/ndarray-base-maybe-broadcast-array"),rr=require("@stdlib/ndarray-base-broadcast-scalar"),er=require("@stdlib/strided-base-reinterpret-boolean"),ar=require("@stdlib/array-base-take-indexed"),ir=require("@stdlib/array-base-zero-to"),tr=require("@stdlib/object-assign"),w=require("@stdlib/string-format"),nr=g(),ur=b();function sr(r,e,a){var i,n,o,v,u,t,d,l,p,y,s;if(!k(r))throw new TypeError(w("invalid argument. First argument must be an ndarray-like object. Value: `%s`.",r));if(u=W(r),p=u.length,i=tr({},nr),arguments.length>2&&(o=ur(i,p,a),o))throw o;if(i.dims===null&&(i.dims=ir(p)),v=U(p,i.dims),t=ar(u,v),l=j(r),d=O(r),k(e)){if(!H(j(e),l))throw new TypeError(w("invalid argument. Second argument cannot be safely cast to the input array data type. Value: `%s`.",e));try{y=x(e,t)}catch(Tr){throw new Error("invalid argument. Second argument must be broadcast-compatible with the non-reduced dimensions of the input array.")}}else if(G(e,l))y=rr(e,l,t,d);else throw new TypeError(w("invalid argument. Second argument cannot be safely cast to the input array data type. Value: `%s`.",e));return s=_(t,{dtype:"bool",order:d}),n=new $("uint8",er(X(s),0),t,Y(s,!1),Z(s),O(s)),J(K,[r,n,y],i.dims),i.keepdims&&(s=Q(p,s,v,!0)),s}V.exports=sr});var D=q(function(Cr,B){"use strict";var or=require("@stdlib/ndarray-base-assert-is-scalar-mostly-safe-compatible"),dr=require("@stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast"),h=require("@stdlib/assert-is-ndarray-like"),vr=require("@stdlib/ndarray-base-unary-reduce-subarray"),mr=require("@stdlib/ndarray-ndims"),lr=require("@stdlib/ndarray-base-includes"),A=require("@stdlib/ndarray-shape"),pr=require("@stdlib/ndarray-base-order"),R=require("@stdlib/ndarray-base-dtype"),qr=require("@stdlib/ndarray-base-maybe-broadcast-array"),fr=require("@stdlib/ndarray-base-broadcast-scalar"),yr=require("@stdlib/object-assign"),gr=require("@stdlib/array-base-zero-to"),f=require("@stdlib/string-format"),cr=g(),br=b();function wr(r,e,a,i){var n,o,v,u,t,d;if(!h(r))throw new TypeError(f("invalid argument. First argument must be an ndarray-like object. Value: `%s`.",r));if(!h(a))throw new TypeError(f("invalid argument. Third argument must be an ndarray-like object. Value: `%s`.",a));if(t=mr(r),n=yr({},cr),arguments.length>3&&(o=br(n,t,i),o))throw o;if(n.dims===null&&(n.dims=gr(t)),u=R(r),v=pr(r),h(e)){if(!dr(R(e),u))throw new TypeError(f("invalid argument. Second argument cannot be safely cast to the input array data type. Value: `%s`.",e));try{d=qr(e,A(a))}catch(l){throw new Error("invalid argument. Second argument must be broadcast-compatible with the non-reduced dimensions of the input array.")}}else if(or(e,u))d=fr(e,u,A(a),v);else throw new TypeError(f("invalid argument. Second argument cannot be safely cast to the input array data type. Value: `%s`.",e));return vr(lr,[r,a,d],n.dims),a}B.exports=wr});var hr=require("@stdlib/utils-define-nonenumerable-read-only-property"),E=C(),Sr=D();hr(E,"assign",Sr);module.exports=E; -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index c222237..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/defaults.json", "../lib/validate.js", "../lib/main.js", "../lib/assign.js", "../lib/index.js"], - "sourcesContent": ["{\n \"dims\": null,\n \"keepdims\": false\n}\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isIntegerArray = require( '@stdlib/assert-is-integer-array' ).primitives;\nvar isEmptyCollection = require( '@stdlib/assert-is-empty-collection' );\nvar normalizeIndices = require( '@stdlib/ndarray-base-to-unique-normalized-indices' );\nvar join = require( '@stdlib/array-base-join' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {NonNegativeInteger} ndims - number of input ndarray dimensions\n* @param {Options} options - function options\n* @param {boolean} [options.keepdims] - boolean indicating whether the reduced dimensions should be included in the returned ndarray as singleton dimensions\n* @param {IntegerArray} [options.dims] - list of dimensions over which to perform a reduction\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'keepdims': true\n* };\n* var err = validate( opts, 3, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, ndims, options ) {\n\tvar tmp;\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'keepdims' ) ) {\n\t\topts.keepdims = options.keepdims;\n\t\tif ( !isBoolean( opts.keepdims ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'keepdims', opts.keepdims ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'dims' ) ) {\n\t\topts.dims = options.dims;\n\t\tif ( !isIntegerArray( opts.dims ) && !isEmptyCollection( opts.dims ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array of integers. Option: `%s`.', 'dims', opts.dims ) );\n\t\t}\n\t\ttmp = normalizeIndices( opts.dims, ndims-1 );\n\t\tif ( tmp === null ) {\n\t\t\treturn new RangeError( format( 'invalid option. `%s` option contains an out-of-bounds dimension index. Option: [%s].', 'dims', join( opts.dims, ',' ) ) );\n\t\t}\n\t\tif ( tmp.length !== opts.dims.length ) {\n\t\t\treturn new Error( format( 'invalid option. `%s` option contains duplicate indices. Option: [%s].', 'dims', join( opts.dims, ',' ) ) );\n\t\t}\n\t\tif ( tmp.length > ndims ) {\n\t\t\treturn new RangeError( format( 'invalid option. `%s` option specifies more dimensions than exists in the input array. Number of dimensions: %d. Option: [%s].', 'dims', ndims, join( opts.dims, ',' ) ) );\n\t\t}\n\t\topts.dims = tmp;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isScalarMostlySafeCompatible = require( '@stdlib/ndarray-base-assert-is-scalar-mostly-safe-compatible' ); // eslint-disable-line id-length\nvar isMostlySafeCast = require( '@stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar unaryReduceSubarray = require( '@stdlib/ndarray-base-unary-reduce-subarray' );\nvar base = require( '@stdlib/ndarray-base-includes' );\nvar spreadDimensions = require( '@stdlib/ndarray-base-spread-dimensions' );\nvar indicesComplement = require( '@stdlib/array-base-indices-complement' );\nvar getShape = require( '@stdlib/ndarray-shape' ); // note: non-base accessor is intentional due to the input array originating in userland\nvar getOrder = require( '@stdlib/ndarray-base-order' );\nvar getData = require( '@stdlib/ndarray-base-data-buffer' );\nvar getStrides = require( '@stdlib/ndarray-base-strides' );\nvar getOffset = require( '@stdlib/ndarray-base-offset' );\nvar getDType = require( '@stdlib/ndarray-base-dtype' );\nvar empty = require( '@stdlib/ndarray-empty' );\nvar ndarrayCtor = require( '@stdlib/ndarray-base-ctor' );\nvar maybeBroadcastArray = require( '@stdlib/ndarray-base-maybe-broadcast-array' );\nvar broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' );\nvar reinterpretBoolean = require( '@stdlib/strided-base-reinterpret-boolean' );\nvar takeIndexed = require( '@stdlib/array-base-take-indexed' );\nvar zeroTo = require( '@stdlib/array-base-zero-to' );\nvar objectAssign = require( '@stdlib/object-assign' );\nvar format = require( '@stdlib/string-format' );\nvar defaults = require( './defaults.json' );\nvar validate = require( './validate.js' );\n\n\n// MAIN //\n\n/**\n* Tests whether an ndarray contains a specified value along one or more dimensions.\n*\n* @param {ndarray} x - input ndarray\n* @param {(ndarray|*)} searchElement - search element\n* @param {Options} [options] - function options\n* @param {IntegerArray} [options.dims] - list of dimensions over which to perform a reduction\n* @param {boolean} [options.keepdims=false] - boolean indicating whether the reduced dimensions should be included in the returned ndarray as singleton dimensions\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {Error} second argument must be broadcast-compatible with the non-reduced dimensions of the input ndarray\n* @throws {TypeError} second argument must have a data type which can be safely cast to the data type of the input ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {RangeError} dimension indices must not exceed input ndarray bounds\n* @throws {RangeError} number of dimension indices must not exceed the number of input ndarray dimensions\n* @throws {Error} must provide valid options\n* @returns {ndarray} output ndarray\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n*\n* // Create a data buffer:\n* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] );\n*\n* // Define the shape of the input array:\n* var sh = [ 3, 1, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 4, 4, 1 ];\n*\n* // Define the index offset:\n* var ox = 1;\n*\n* // Create an input ndarray:\n* var x = new ndarray( 'float64', xbuf, sh, sx, ox, 'row-major' );\n*\n* // Perform reduction:\n* var out = includes( x, 6.0 );\n* // returns \n*\n* var v = out.get();\n* // returns true\n*/\nfunction includes( x, searchElement, options ) {\n\tvar opts;\n\tvar view;\n\tvar err;\n\tvar idx;\n\tvar shx;\n\tvar shy;\n\tvar ord;\n\tvar dt;\n\tvar N;\n\tvar v;\n\tvar y;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray-like object. Value: `%s`.', x ) );\n\t}\n\tshx = getShape( x );\n\tN = shx.length;\n\n\topts = objectAssign( {}, defaults );\n\tif ( arguments.length > 2 ) {\n\t\terr = validate( opts, N, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// When a list of dimensions is not provided, reduce the entire input array across all dimensions...\n\tif ( opts.dims === null ) {\n\t\topts.dims = zeroTo( N );\n\t}\n\t// Resolve the list of non-reduced dimensions:\n\tidx = indicesComplement( N, opts.dims );\n\n\t// Resolve the output array shape:\n\tshy = takeIndexed( shx, idx );\n\n\t// Resolve input array meta data:\n\tdt = getDType( x );\n\tord = getOrder( x );\n\n\t// Determine how to broadcast the search element...\n\tif ( isndarrayLike( searchElement ) ) {\n\t\tif ( !isMostlySafeCast( getDType( searchElement ), dt ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument cannot be safely cast to the input array data type. Value: `%s`.', searchElement ) );\n\t\t}\n\t\ttry {\n\t\t\tv = maybeBroadcastArray( searchElement, shy );\n\t\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\t\tthrow new Error( 'invalid argument. Second argument must be broadcast-compatible with the non-reduced dimensions of the input array.' );\n\t\t}\n\t} else if ( isScalarMostlySafeCompatible( searchElement, dt ) ) {\n\t\tv = broadcastScalar( searchElement, dt, shy, ord );\n\t} else {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument cannot be safely cast to the input array data type. Value: `%s`.', searchElement ) );\n\t}\n\t// Initialize an output array whose shape matches that of the non-reduced dimensions and which has the same memory layout as the input array:\n\ty = empty( shy, {\n\t\t'dtype': 'bool',\n\t\t'order': ord\n\t});\n\n\t// Reinterpret the output array as an \"indexed\" array to ensure faster element access:\n\tview = new ndarrayCtor( 'uint8', reinterpretBoolean( getData( y ), 0 ), shy, getStrides( y, false ), getOffset( y ), getOrder( y ) );\n\n\t// Perform the reduction:\n\tunaryReduceSubarray( base, [ x, view, v ], opts.dims );\n\n\t// Check whether we need to reinsert singleton dimensions which can be useful for broadcasting the returned output array to the shape of the original input array...\n\tif ( opts.keepdims ) {\n\t\ty = spreadDimensions( N, y, idx, true );\n\t}\n\treturn y;\n}\n\n\n// EXPORTS //\n\nmodule.exports = includes;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isScalarMostlySafeCompatible = require( '@stdlib/ndarray-base-assert-is-scalar-mostly-safe-compatible' ); // eslint-disable-line id-length\nvar isMostlySafeCast = require( '@stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar unaryReduceSubarray = require( '@stdlib/ndarray-base-unary-reduce-subarray' );\nvar ndims = require( '@stdlib/ndarray-ndims' );\nvar base = require( '@stdlib/ndarray-base-includes' );\nvar getShape = require( '@stdlib/ndarray-shape' ); // note: non-base accessor is intentional due to the input arrays originating in userland\nvar getOrder = require( '@stdlib/ndarray-base-order' );\nvar getDType = require( '@stdlib/ndarray-base-dtype' );\nvar maybeBroadcastArray = require( '@stdlib/ndarray-base-maybe-broadcast-array' );\nvar broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' );\nvar objectAssign = require( '@stdlib/object-assign' );\nvar zeroTo = require( '@stdlib/array-base-zero-to' );\nvar format = require( '@stdlib/string-format' );\nvar defaults = require( './defaults.json' );\nvar validate = require( './validate.js' );\n\n\n// MAIN //\n\n/**\n* Tests whether an ndarray contains a specified value along one or more dimensions and assigns the results to a provided output ndarray.\n*\n* @param {ndarray} x - input ndarray\n* @param {(ndarray|*)} searchElement - search element\n* @param {ndarray} y - output ndarray\n* @param {Options} [options] - function options\n* @param {IntegerArray} [options.dims] - list of dimensions over which to perform a reduction\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {Error} second argument must be broadcast-compatible with the non-reduced dimensions of the input ndarray\n* @throws {TypeError} second argument must have a data type which can be safely cast to the data type of the input ndarray\n* @throws {TypeError} third argument must be an ndarray-like object\n* @throws {TypeError} options argument must be an object\n* @throws {Error} must provide valid options\n* @returns {ndarray} output ndarray\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* // Create a data buffer:\n* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 3, 1, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 4, 4, 1 ];\n*\n* // Define the index offset:\n* var ox = 1;\n*\n* // Create an input ndarray:\n* var x = new ndarray( 'float64', xbuf, shape, sx, ox, 'row-major' );\n*\n* // Create an output ndarray:\n* var y = empty( [], {\n* 'dtype': 'bool'\n* });\n*\n* // Perform reduction:\n* var out = assign( x, 6.0, y );\n* // returns \n*\n* var v = out.get();\n* // returns true\n*/\nfunction assign( x, searchElement, y, options ) {\n\tvar opts;\n\tvar err;\n\tvar ord;\n\tvar dt;\n\tvar N;\n\tvar v;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray-like object. Value: `%s`.', x ) );\n\t}\n\tif ( !isndarrayLike( y ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object. Value: `%s`.', y ) );\n\t}\n\tN = ndims( x );\n\n\topts = objectAssign( {}, defaults );\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, N, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( opts.dims === null ) {\n\t\topts.dims = zeroTo( N );\n\t}\n\t// Resolve input array meta data:\n\tdt = getDType( x );\n\tord = getOrder( x );\n\n\t// Determine how to broadcast the search element...\n\tif ( isndarrayLike( searchElement ) ) {\n\t\tif ( !isMostlySafeCast( getDType( searchElement ), dt ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument cannot be safely cast to the input array data type. Value: `%s`.', searchElement ) );\n\t\t}\n\t\ttry {\n\t\t\tv = maybeBroadcastArray( searchElement, getShape( y ) );\n\t\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\t\tthrow new Error( 'invalid argument. Second argument must be broadcast-compatible with the non-reduced dimensions of the input array.' );\n\t\t}\n\t} else if ( isScalarMostlySafeCompatible( searchElement, dt ) ) {\n\t\tv = broadcastScalar( searchElement, dt, getShape( y ), ord );\n\t} else {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument cannot be safely cast to the input array data type. Value: `%s`.', searchElement ) );\n\t}\n\t// Perform the reduction:\n\tunaryReduceSubarray( base, [ x, y, v ], opts.dims ); // note: we assume that this lower-level function handles further validation of the output ndarray (e.g., expected shape, etc)\n\treturn y;\n}\n\n\n// EXPORTS //\n\nmodule.exports = assign;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Test whether an ndarray contains a specified value along one or more dimensions.\n*\n* @module @stdlib/ndarray-includes\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var includes = require( '@stdlib/ndarray-includes' );\n*\n* // Create a data buffer:\n* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] );\n*\n* // Define the shape of the input array:\n* var sh = [ 3, 1, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 4, 4, 1 ];\n*\n* // Define the index offset:\n* var ox = 1;\n*\n* // Create an input ndarray:\n* var x = new ndarray( 'float64', xbuf, sh, sx, ox, 'row-major' );\n*\n* // Perform reduction:\n* var out = includes( x, 6.0 );\n* // returns \n*\n* var v = out.get();\n* // returns true\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var empty = require( '@stdlib/ndarray-empty' );\n* var includes = require( '@stdlib/ndarray-includes' );\n*\n* // Create a data buffer:\n* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 3, 1, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 4, 4, 1 ];\n*\n* // Define the index offset:\n* var ox = 1;\n*\n* // Create an input ndarray:\n* var x = new ndarray( 'float64', xbuf, shape, sx, ox, 'row-major' );\n*\n* // Create an output ndarray:\n* var y = empty( [], {\n* 'dtype': 'bool'\n* });\n*\n* // Perform reduction:\n* var out = includes.assign( x, 6.0, y );\n* // returns \n*\n* var v = out.get();\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar assign = require( './assign.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n\n// exports: { \"assign\": \"main.assign\" }\n"], - "mappings": "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", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isBoolean", "isIntegerArray", "isEmptyCollection", "normalizeIndices", "join", "format", "validate", "opts", "ndims", "options", "tmp", "require_main", "__commonJSMin", "exports", "module", "isScalarMostlySafeCompatible", "isMostlySafeCast", "isndarrayLike", "unaryReduceSubarray", "base", "spreadDimensions", "indicesComplement", "getShape", "getOrder", "getData", "getStrides", "getOffset", "getDType", "empty", "ndarrayCtor", "maybeBroadcastArray", "broadcastScalar", "reinterpretBoolean", "takeIndexed", "zeroTo", "objectAssign", "format", "defaults", "validate", "includes", "x", "searchElement", "options", "opts", "view", "err", "idx", "shx", "shy", "ord", "dt", "N", "v", "y", "require_assign", "__commonJSMin", "exports", "module", "isScalarMostlySafeCompatible", "isMostlySafeCast", "isndarrayLike", "unaryReduceSubarray", "ndims", "base", "getShape", "getOrder", "getDType", "maybeBroadcastArray", "broadcastScalar", "objectAssign", "zeroTo", "format", "defaults", "validate", "assign", "x", "searchElement", "y", "options", "opts", "err", "ord", "dt", "N", "v", "setReadOnly", "main", "assign"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 04d9390..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,93 +0,0 @@ - -{{alias}}( x, searchElement[, options] ) - Tests whether an ndarray contains a specified value along one or more - dimensions. - - Parameters - ---------- - x: ndarray - Input ndarray. - - searchElement: ndarray|any - Search element. Must be broadcast-compatible with the non-reduced - dimensions of the input ndarray. Must have a data type which can be - safely cast to the data type of the input ndarray. - - options: Object (optional) - Function options. - - options.dims: Array (optional) - List of dimensions over which to perform a reduction. If not provided, - the function performs a reduction over all elements in a provided input - ndarray. - - options.keepdims: boolean (optional) - Boolean indicating whether the reduced dimensions should be included in - the returned ndarray as singleton dimensions. Default: false. - - Returns - ------- - out: ndarray - Output ndarray. When performing a reduction over all elements, the - function returns a zero-dimensional ndarray containing the result. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ); - > var y = {{alias}}( x, 3.0 ) - - > y.get() - true - > y = {{alias}}( x, 3.0, { 'keepdims': true } ) - - > {{alias:@stdlib/ndarray/to-array}}( y ) - [ [ true ] ] - > y.get( 0, 0 ) - true - - -{{alias}}.assign( x, searchElement, y[, options] ) - Tests whether an ndarray contains a specified value along one or more - dimensions and assigns the results to a provided output ndarray. - - Parameters - ---------- - x: ndarray - Input ndarray. - - searchElement: ndarray|any - Search element. Must be broadcast-compatible with the non-reduced - dimensions of the input ndarray. Must have a data type which can be - safely cast to the data type of the input ndarray. - - y: ndarray - Output ndarray. The output shape must match the shape of the non-reduced - dimensions of the input ndarray. - - options: Object (optional) - Function options. - - options.dims: Array (optional) - List of dimensions over which to perform a reduction. If not provided, - the function performs a reduction over all elements in a provided input - ndarray. - - Returns - ------- - y: ndarray - Output ndarray. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ); - > var y = {{alias:@stdlib/ndarray/from-scalar}}( false ); - > var out = {{alias}}.assign( x, 3.0, y ) - - > var bool = ( out === y ) - true - > y.get() - true - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 1911572..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,199 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 empty = require( '@stdlib/ndarray-empty' ); -import includes = require( './index' ); - - -// TESTS // - -// The function returns an boolean ndarray... -{ - const x = zeros( [ 2, 2 ] ); - - includes( x, 0.0 ); // $ExpectType boolndarray - includes( x, 0.0, {} ); // $ExpectType boolndarray - includes( x, 0.0, { 'keepdims': true } ); // $ExpectType boolndarray - includes( x, 0.0, { 'dims': [ 0 ] } ); // $ExpectType boolndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - includes( 5, 0.0 ); // $ExpectError - includes( true, 0.0 ); // $ExpectError - includes( false, 0.0 ); // $ExpectError - includes( null, 0.0 ); // $ExpectError - includes( undefined, 0.0 ); // $ExpectError - includes( {}, 0.0 ); // $ExpectError - includes( [ 1 ], 0.0 ); // $ExpectError - includes( ( x: number ): number => x, 0.0 ); // $ExpectError - - includes( 5, 0.0, {} ); // $ExpectError - includes( true, 0.0, {} ); // $ExpectError - includes( false, 0.0, {} ); // $ExpectError - includes( null, 0.0, {} ); // $ExpectError - includes( undefined, 0.0, {} ); // $ExpectError - includes( {}, 0.0, {} ); // $ExpectError - includes( [ 1 ], 0.0, {} ); // $ExpectError - includes( ( x: number ): number => x, 0.0, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not an object... -{ - const x = zeros( [ 2, 2 ] ); - - includes( x, 0.0, '5' ); // $ExpectError - includes( x, 0.0, 5 ); // $ExpectError - includes( x, 0.0, true ); // $ExpectError - includes( x, 0.0, false ); // $ExpectError - includes( x, 0.0, null ); // $ExpectError - includes( x, 0.0, [ 1 ] ); // $ExpectError - includes( x, 0.0, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `keepdims` option which is not a boolean... -{ - const x = zeros( [ 2, 2 ] ); - - includes( x, 0.0, { 'keepdims': '5' } ); // $ExpectError - includes( x, 0.0, { 'keepdims': 5 } ); // $ExpectError - includes( x, 0.0, { 'keepdims': null } ); // $ExpectError - includes( x, 0.0, { 'keepdims': [ 1 ] } ); // $ExpectError - includes( x, 0.0, { 'keepdims': {} } ); // $ExpectError - includes( x, 0.0, { 'keepdims': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `dims` option which is not an array of numbers... -{ - const x = zeros( [ 2, 2 ] ); - - includes( x, 0.0, { 'dims': '5' } ); // $ExpectError - includes( x, 0.0, { 'dims': 5 } ); // $ExpectError - includes( x, 0.0, { 'dims': null } ); // $ExpectError - includes( x, 0.0, { 'dims': true } ); // $ExpectError - includes( x, 0.0, { 'dims': false } ); // $ExpectError - includes( x, 0.0, { 'dims': {} } ); // $ExpectError - includes( x, 0.0, { 'dims': ( 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 ] ); - - includes(); // $ExpectError - includes( x ); // $ExpectError - includes( x, 0.0, {}, {} ); // $ExpectError -} - -// Attached to the function is an `assign` method which returns an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - const y = empty( [], { 'dtype': 'bool' } ); - - includes.assign( x, 0.0, y ); // $ExpectType boolndarray - includes.assign( x, 0.0, y, {} ); // $ExpectType boolndarray - includes.assign( x, 0.0, y, { 'dims': [ 0 ] } ); // $ExpectType boolndarray -} - -// The compiler throws an error if the `assign` method is provided a first argument which is not an ndarray... -{ - const y = empty( [], { 'dtype': 'bool' } ); - - includes.assign( 5, 0.0, y ); // $ExpectError - includes.assign( true, 0.0, y ); // $ExpectError - includes.assign( false, 0.0, y ); // $ExpectError - includes.assign( null, 0.0, y ); // $ExpectError - includes.assign( undefined, 0.0, y ); // $ExpectError - includes.assign( {}, 0.0, y ); // $ExpectError - includes.assign( [ 1 ], 0.0, y ); // $ExpectError - includes.assign( ( x: number ): number => x, 0.0, y ); // $ExpectError - - includes.assign( 5, 0.0, y, {} ); // $ExpectError - includes.assign( true, 0.0, y, {} ); // $ExpectError - includes.assign( false, 0.0, y, {} ); // $ExpectError - includes.assign( null, 0.0, y, {} ); // $ExpectError - includes.assign( undefined, 0.0, y, {} ); // $ExpectError - includes.assign( {}, 0.0, y, {} ); // $ExpectError - includes.assign( [ 1 ], 0.0, y, {} ); // $ExpectError - includes.assign( ( x: number ): number => x, 0.0, y, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a third argument which is not an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - - includes.assign( x, 0.0, 5 ); // $ExpectError - includes.assign( x, 0.0, true ); // $ExpectError - includes.assign( x, 0.0, false ); // $ExpectError - includes.assign( x, 0.0, null ); // $ExpectError - includes.assign( x, 0.0, undefined ); // $ExpectError - includes.assign( x, 0.0, {} ); // $ExpectError - includes.assign( x, 0.0, [ 1 ] ); // $ExpectError - includes.assign( x, 0.0, ( x: number ): number => x ); // $ExpectError - - includes.assign( x, 0.0, 5, {} ); // $ExpectError - includes.assign( x, 0.0, true, {} ); // $ExpectError - includes.assign( x, 0.0, false, {} ); // $ExpectError - includes.assign( x, 0.0, null, {} ); // $ExpectError - includes.assign( x, 0.0, undefined, {} ); // $ExpectError - includes.assign( x, 0.0, {}, {} ); // $ExpectError - includes.assign( x, 0.0, [ 1 ], {} ); // $ExpectError - includes.assign( x, 0.0, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a third argument which is not an object... -{ - const x = zeros( [ 2, 2 ] ); - const y = empty( [], { 'dtype': 'bool' } ); - - includes.assign( x, 0.0, y, '5' ); // $ExpectError - includes.assign( x, 0.0, y, 5 ); // $ExpectError - includes.assign( x, 0.0, y, true ); // $ExpectError - includes.assign( x, 0.0, y, false ); // $ExpectError - includes.assign( x, 0.0, y, null ); // $ExpectError - includes.assign( x, 0.0, y, [ 1 ] ); // $ExpectError - includes.assign( x, 0.0, y, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `dims` option which is not an array of numbers... -{ - const x = zeros( [ 2, 2 ] ); - const y = empty( [], { 'dtype': 'bool' } ); - - includes.assign( x, 0.0, y, { 'dims': '5' } ); // $ExpectError - includes.assign( x, 0.0, y, { 'dims': 5 } ); // $ExpectError - includes.assign( x, 0.0, y, { 'dims': null } ); // $ExpectError - includes.assign( x, 0.0, y, { 'dims': true } ); // $ExpectError - includes.assign( x, 0.0, y, { 'dims': false } ); // $ExpectError - includes.assign( x, 0.0, y, { 'dims': {} } ); // $ExpectError - includes.assign( x, 0.0, y, { 'dims': ( 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 ] ); - const y = empty( [], { 'dtype': 'bool' } ); - - includes.assign(); // $ExpectError - includes.assign( x ); // $ExpectError - includes.assign( x, 0.0 ); // $ExpectError - includes.assign( x, 0.0, y, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 525b7e6..0000000 --- a/examples/index.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 discreteUniform = require( '@stdlib/random-base-discrete-uniform' ).factory; -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var fillBy = require( '@stdlib/ndarray-fill-by' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var includes = require( './../lib' ); - -var x = zeros( [ 2, 4, 5 ], { - 'dtype': 'float64' -}); -x = fillBy( x, discreteUniform( 0, 10 ) ); -console.log( ndarray2array( x ) ); - -var y = includes( x, 1 ); -console.log( 'includes(x[:,:,:], 1) =' ); -console.log( y.get() ); - -y = includes( x, 2, { - 'dims': [ 0 ], - 'keepdims': true -}); -console.log( 'includes(x[:,j,k], 2) =' ); -console.log( ndarray2array( y ) ); - -y = includes( x, 3, { - 'dims': [ 1 ], - 'keepdims': true -}); -console.log( 'includes(x[i,:,k], 3) =' ); -console.log( ndarray2array( y ) ); - -y = includes( x, 4, { - 'dims': [ 2 ], - 'keepdims': true -}); -console.log( 'includes(x[i,j,:], 4) =' ); -console.log( ndarray2array( y ) ); - -y = includes( x, 5, { - 'dims': [ 0, 1 ], - 'keepdims': true -}); -console.log( 'includes(x[:,:,k], 5) =' ); -console.log( ndarray2array( y ) ); - -y = includes( x, 6, { - 'dims': [ 0, 2 ], - 'keepdims': true -}); -console.log( 'includes(x[:,j,:], 6) =' ); -console.log( ndarray2array( y ) ); - -y = includes( x, 7, { - 'dims': [ 1, 2 ], - 'keepdims': true -}); -console.log( 'includes(x[i,:,:], 7) =' ); -console.log( ndarray2array( y ) ); - -y = includes( x, 8, { - 'dims': [ 0, 1, 2 ], - 'keepdims': true -}); -console.log( 'includes(x[:,:,:], 8) =' ); -console.log( ndarray2array( y ) ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index f4ddce6..ad24b59 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { ndarray, boolndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..727292b --- /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/utils-define-nonenumerable-read-only-property@v0.2.3-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-scalar-mostly-safe-compatible@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-mostly-safe-data-type-cast@v0.3.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.3-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-unary-reduce-subarray@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-includes@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-spread-dimensions@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-indices-complement@v0.1.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.3-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.3-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.3-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.3-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.3-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.3-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-empty@v0.3.1-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.3.1-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-maybe-broadcast-array@v0.2.5-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-scalar@v0.2.4-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-boolean@v0.0.3-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take-indexed@v0.2.3-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zero-to@v0.2.2-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/object-assign@v0.2.3-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.3-esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.3-esm/index.mjs";import{isPrimitive as T}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.3-esm/index.mjs";import{primitives as S}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer-array@v0.2.3-esm/index.mjs";import V from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-empty-collection@v0.2.4-esm/index.mjs";import O from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-to-unique-normalized-indices@v0.1.1-esm/index.mjs";import z from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-join@v0.1.2-esm/index.mjs";import R from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ndims@v0.2.3-esm/index.mjs";var q={dims:null,keepdims:!1};function N(e,s,t){var r;if(!E(t))return new TypeError(w("null2V",t));if(k(t,"keepdims")&&(e.keepdims=t.keepdims,!T(e.keepdims)))return new TypeError(w("null2o","keepdims",e.keepdims));if(k(t,"dims")){if(e.dims=t.dims,!S(e.dims)&&!V(e.dims))return new TypeError(w("invalid option. `%s` option must be an array of integers. Option: `%s`.","dims",e.dims));if(null===(r=O(e.dims,s-1)))return new RangeError(w("invalid option. `%s` option contains an out-of-bounds dimension index. Option: [%s].","dims",z(e.dims,",")));if(r.length!==e.dims.length)return new Error(w("invalid option. `%s` option contains duplicate indices. Option: [%s].","dims",z(e.dims,",")));if(r.length>s)return new RangeError(w("invalid option. `%s` option specifies more dimensions than exists in the input array. Number of dimensions: %d. Option: [%s].","dims",s,z(e.dims,",")));e.dims=r}return null}function A(e,E,k){var T,S,V,O,z,R,A,B,C,D,F;if(!r(e))throw new TypeError(w("null5t",e));if(C=(z=m(e)).length,T=x({},q),arguments.length>2&&(V=N(T,C,k)))throw V;if(null===T.dims&&(T.dims=g(C)),O=a(C,T.dims),R=y(z,O),B=h(e),A=o(e),r(E)){if(!t(h(E),B))throw new TypeError(w("invalid argument. Second argument cannot be safely cast to the input array data type. Value: `%s`.",E));try{D=v(E,R)}catch(V){throw new Error("invalid argument. Second argument must be broadcast-compatible with the non-reduced dimensions of the input array.")}}else{if(!s(E,B))throw new TypeError(w("invalid argument. Second argument cannot be safely cast to the input array data type. Value: `%s`.",E));D=f(E,B,R,A)}return F=c(R,{dtype:"bool",order:A}),S=new b("uint8",u(l(F),0),R,p(F,!1),j(F),o(F)),i(n,[e,S,D],T.dims),T.keepdims&&(F=d(C,F,O,!0)),F}function B(e,d,a,l){var p,j,c,b,u,y;if(!r(e))throw new TypeError(w("null5t",e));if(!r(a))throw new TypeError(w("invalid argument. Third argument must be an ndarray-like object. Value: `%s`.",a));if(u=R(e),p=x({},q),arguments.length>3&&(j=N(p,u,l)))throw j;if(null===p.dims&&(p.dims=g(u)),b=h(e),c=o(e),r(d)){if(!t(h(d),b))throw new TypeError(w("invalid argument. Second argument cannot be safely cast to the input array data type. Value: `%s`.",d));try{y=v(d,m(a))}catch(j){throw new Error("invalid argument. Second argument must be broadcast-compatible with the non-reduced dimensions of the input array.")}}else{if(!s(d,b))throw new TypeError(w("invalid argument. Second argument cannot be safely cast to the input array data type. Value: `%s`.",d));y=f(d,b,m(a),c)}return i(n,[e,a,y],p.dims),a}e(A,"assign",B);export{B as assign,A as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..29ee4ca --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/main.js","../lib/assign.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { primitives as isIntegerArray } from '@stdlib/assert-is-integer-array';\nimport isEmptyCollection from '@stdlib/assert-is-empty-collection';\nimport normalizeIndices from '@stdlib/ndarray-base-to-unique-normalized-indices';\nimport join from '@stdlib/array-base-join';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {NonNegativeInteger} ndims - number of input ndarray dimensions\n* @param {Options} options - function options\n* @param {boolean} [options.keepdims] - boolean indicating whether the reduced dimensions should be included in the returned ndarray as singleton dimensions\n* @param {IntegerArray} [options.dims] - list of dimensions over which to perform a reduction\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'keepdims': true\n* };\n* var err = validate( opts, 3, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, ndims, options ) {\n\tvar tmp;\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'keepdims' ) ) {\n\t\topts.keepdims = options.keepdims;\n\t\tif ( !isBoolean( opts.keepdims ) ) {\n\t\t\treturn new TypeError( format( 'null2o', 'keepdims', opts.keepdims ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'dims' ) ) {\n\t\topts.dims = options.dims;\n\t\tif ( !isIntegerArray( opts.dims ) && !isEmptyCollection( opts.dims ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array of integers. Option: `%s`.', 'dims', opts.dims ) );\n\t\t}\n\t\ttmp = normalizeIndices( opts.dims, ndims-1 );\n\t\tif ( tmp === null ) {\n\t\t\treturn new RangeError( format( 'invalid option. `%s` option contains an out-of-bounds dimension index. Option: [%s].', 'dims', join( opts.dims, ',' ) ) );\n\t\t}\n\t\tif ( tmp.length !== opts.dims.length ) {\n\t\t\treturn new Error( format( 'invalid option. `%s` option contains duplicate indices. Option: [%s].', 'dims', join( opts.dims, ',' ) ) );\n\t\t}\n\t\tif ( tmp.length > ndims ) {\n\t\t\treturn new RangeError( format( 'invalid option. `%s` option specifies more dimensions than exists in the input array. Number of dimensions: %d. Option: [%s].', 'dims', ndims, join( opts.dims, ',' ) ) );\n\t\t}\n\t\topts.dims = tmp;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isScalarMostlySafeCompatible from '@stdlib/ndarray-base-assert-is-scalar-mostly-safe-compatible'; // eslint-disable-line id-length\nimport isMostlySafeCast from '@stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport unaryReduceSubarray from '@stdlib/ndarray-base-unary-reduce-subarray';\nimport base from '@stdlib/ndarray-base-includes';\nimport spreadDimensions from '@stdlib/ndarray-base-spread-dimensions';\nimport indicesComplement from '@stdlib/array-base-indices-complement';\nimport getShape from '@stdlib/ndarray-shape'; // note: non-base accessor is intentional due to the input array originating in userland\nimport getOrder from '@stdlib/ndarray-base-order';\nimport getData from '@stdlib/ndarray-base-data-buffer';\nimport getStrides from '@stdlib/ndarray-base-strides';\nimport getOffset from '@stdlib/ndarray-base-offset';\nimport getDType from '@stdlib/ndarray-base-dtype';\nimport empty from '@stdlib/ndarray-empty';\nimport ndarrayCtor from '@stdlib/ndarray-base-ctor';\nimport maybeBroadcastArray from '@stdlib/ndarray-base-maybe-broadcast-array';\nimport broadcastScalar from '@stdlib/ndarray-base-broadcast-scalar';\nimport reinterpretBoolean from '@stdlib/strided-base-reinterpret-boolean';\nimport takeIndexed from '@stdlib/array-base-take-indexed';\nimport zeroTo from '@stdlib/array-base-zero-to';\nimport objectAssign from '@stdlib/object-assign';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport defaults from './defaults.json';\nimport validate from './validate.js';\n\n\n// MAIN //\n\n/**\n* Tests whether an ndarray contains a specified value along one or more dimensions.\n*\n* @param {ndarray} x - input ndarray\n* @param {(ndarray|*)} searchElement - search element\n* @param {Options} [options] - function options\n* @param {IntegerArray} [options.dims] - list of dimensions over which to perform a reduction\n* @param {boolean} [options.keepdims=false] - boolean indicating whether the reduced dimensions should be included in the returned ndarray as singleton dimensions\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {Error} second argument must be broadcast-compatible with the non-reduced dimensions of the input ndarray\n* @throws {TypeError} second argument must have a data type which can be safely cast to the data type of the input ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {RangeError} dimension indices must not exceed input ndarray bounds\n* @throws {RangeError} number of dimension indices must not exceed the number of input ndarray dimensions\n* @throws {Error} must provide valid options\n* @returns {ndarray} output ndarray\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n* import ndarray from '@stdlib/ndarray-ctor';\n*\n* // Create a data buffer:\n* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] );\n*\n* // Define the shape of the input array:\n* var sh = [ 3, 1, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 4, 4, 1 ];\n*\n* // Define the index offset:\n* var ox = 1;\n*\n* // Create an input ndarray:\n* var x = new ndarray( 'float64', xbuf, sh, sx, ox, 'row-major' );\n*\n* // Perform reduction:\n* var out = includes( x, 6.0 );\n* // returns \n*\n* var v = out.get();\n* // returns true\n*/\nfunction includes( x, searchElement, options ) {\n\tvar opts;\n\tvar view;\n\tvar err;\n\tvar idx;\n\tvar shx;\n\tvar shy;\n\tvar ord;\n\tvar dt;\n\tvar N;\n\tvar v;\n\tvar y;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null5t', x ) );\n\t}\n\tshx = getShape( x );\n\tN = shx.length;\n\n\topts = objectAssign( {}, defaults );\n\tif ( arguments.length > 2 ) {\n\t\terr = validate( opts, N, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// When a list of dimensions is not provided, reduce the entire input array across all dimensions...\n\tif ( opts.dims === null ) {\n\t\topts.dims = zeroTo( N );\n\t}\n\t// Resolve the list of non-reduced dimensions:\n\tidx = indicesComplement( N, opts.dims );\n\n\t// Resolve the output array shape:\n\tshy = takeIndexed( shx, idx );\n\n\t// Resolve input array meta data:\n\tdt = getDType( x );\n\tord = getOrder( x );\n\n\t// Determine how to broadcast the search element...\n\tif ( isndarrayLike( searchElement ) ) {\n\t\tif ( !isMostlySafeCast( getDType( searchElement ), dt ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument cannot be safely cast to the input array data type. Value: `%s`.', searchElement ) );\n\t\t}\n\t\ttry {\n\t\t\tv = maybeBroadcastArray( searchElement, shy );\n\t\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\t\tthrow new Error( 'invalid argument. Second argument must be broadcast-compatible with the non-reduced dimensions of the input array.' );\n\t\t}\n\t} else if ( isScalarMostlySafeCompatible( searchElement, dt ) ) {\n\t\tv = broadcastScalar( searchElement, dt, shy, ord );\n\t} else {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument cannot be safely cast to the input array data type. Value: `%s`.', searchElement ) );\n\t}\n\t// Initialize an output array whose shape matches that of the non-reduced dimensions and which has the same memory layout as the input array:\n\ty = empty( shy, {\n\t\t'dtype': 'bool',\n\t\t'order': ord\n\t});\n\n\t// Reinterpret the output array as an \"indexed\" array to ensure faster element access:\n\tview = new ndarrayCtor( 'uint8', reinterpretBoolean( getData( y ), 0 ), shy, getStrides( y, false ), getOffset( y ), getOrder( y ) );\n\n\t// Perform the reduction:\n\tunaryReduceSubarray( base, [ x, view, v ], opts.dims );\n\n\t// Check whether we need to reinsert singleton dimensions which can be useful for broadcasting the returned output array to the shape of the original input array...\n\tif ( opts.keepdims ) {\n\t\ty = spreadDimensions( N, y, idx, true );\n\t}\n\treturn y;\n}\n\n\n// EXPORTS //\n\nexport default includes;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isScalarMostlySafeCompatible from '@stdlib/ndarray-base-assert-is-scalar-mostly-safe-compatible'; // eslint-disable-line id-length\nimport isMostlySafeCast from '@stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport unaryReduceSubarray from '@stdlib/ndarray-base-unary-reduce-subarray';\nimport ndims from '@stdlib/ndarray-ndims';\nimport base from '@stdlib/ndarray-base-includes';\nimport getShape from '@stdlib/ndarray-shape'; // note: non-base accessor is intentional due to the input arrays originating in userland\nimport getOrder from '@stdlib/ndarray-base-order';\nimport getDType from '@stdlib/ndarray-base-dtype';\nimport maybeBroadcastArray from '@stdlib/ndarray-base-maybe-broadcast-array';\nimport broadcastScalar from '@stdlib/ndarray-base-broadcast-scalar';\nimport objectAssign from '@stdlib/object-assign';\nimport zeroTo from '@stdlib/array-base-zero-to';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport defaults from './defaults.json';\nimport validate from './validate.js';\n\n\n// MAIN //\n\n/**\n* Tests whether an ndarray contains a specified value along one or more dimensions and assigns the results to a provided output ndarray.\n*\n* @param {ndarray} x - input ndarray\n* @param {(ndarray|*)} searchElement - search element\n* @param {ndarray} y - output ndarray\n* @param {Options} [options] - function options\n* @param {IntegerArray} [options.dims] - list of dimensions over which to perform a reduction\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {Error} second argument must be broadcast-compatible with the non-reduced dimensions of the input ndarray\n* @throws {TypeError} second argument must have a data type which can be safely cast to the data type of the input ndarray\n* @throws {TypeError} third argument must be an ndarray-like object\n* @throws {TypeError} options argument must be an object\n* @throws {Error} must provide valid options\n* @returns {ndarray} output ndarray\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n* import ndarray from '@stdlib/ndarray-ctor';\n* import empty from '@stdlib/ndarray-empty';\n*\n* // Create a data buffer:\n* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 3, 1, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 4, 4, 1 ];\n*\n* // Define the index offset:\n* var ox = 1;\n*\n* // Create an input ndarray:\n* var x = new ndarray( 'float64', xbuf, shape, sx, ox, 'row-major' );\n*\n* // Create an output ndarray:\n* var y = empty( [], {\n* 'dtype': 'bool'\n* });\n*\n* // Perform reduction:\n* var out = assign( x, 6.0, y );\n* // returns \n*\n* var v = out.get();\n* // returns true\n*/\nfunction assign( x, searchElement, y, options ) {\n\tvar opts;\n\tvar err;\n\tvar ord;\n\tvar dt;\n\tvar N;\n\tvar v;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null5t', x ) );\n\t}\n\tif ( !isndarrayLike( y ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object. Value: `%s`.', y ) );\n\t}\n\tN = ndims( x );\n\n\topts = objectAssign( {}, defaults );\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, N, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( opts.dims === null ) {\n\t\topts.dims = zeroTo( N );\n\t}\n\t// Resolve input array meta data:\n\tdt = getDType( x );\n\tord = getOrder( x );\n\n\t// Determine how to broadcast the search element...\n\tif ( isndarrayLike( searchElement ) ) {\n\t\tif ( !isMostlySafeCast( getDType( searchElement ), dt ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument cannot be safely cast to the input array data type. Value: `%s`.', searchElement ) );\n\t\t}\n\t\ttry {\n\t\t\tv = maybeBroadcastArray( searchElement, getShape( y ) );\n\t\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\t\tthrow new Error( 'invalid argument. Second argument must be broadcast-compatible with the non-reduced dimensions of the input array.' );\n\t\t}\n\t} else if ( isScalarMostlySafeCompatible( searchElement, dt ) ) {\n\t\tv = broadcastScalar( searchElement, dt, getShape( y ), ord );\n\t} else {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument cannot be safely cast to the input array data type. Value: `%s`.', searchElement ) );\n\t}\n\t// Perform the reduction:\n\tunaryReduceSubarray( base, [ x, y, v ], opts.dims ); // note: we assume that this lower-level function handles further validation of the output ndarray (e.g., expected shape, etc)\n\treturn y;\n}\n\n\n// EXPORTS //\n\nexport default assign;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Test whether an ndarray contains a specified value along one or more dimensions.\n*\n* @module @stdlib/ndarray-includes\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n* import ndarray from '@stdlib/ndarray-ctor';\n* import includes from '@stdlib/ndarray-includes';\n*\n* // Create a data buffer:\n* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] );\n*\n* // Define the shape of the input array:\n* var sh = [ 3, 1, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 4, 4, 1 ];\n*\n* // Define the index offset:\n* var ox = 1;\n*\n* // Create an input ndarray:\n* var x = new ndarray( 'float64', xbuf, sh, sx, ox, 'row-major' );\n*\n* // Perform reduction:\n* var out = includes( x, 6.0 );\n* // returns \n*\n* var v = out.get();\n* // returns true\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n* import ndarray from '@stdlib/ndarray-ctor';\n* import empty from '@stdlib/ndarray-empty';\n* import includes from '@stdlib/ndarray-includes';\n*\n* // Create a data buffer:\n* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 3, 1, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 4, 4, 1 ];\n*\n* // Define the index offset:\n* var ox = 1;\n*\n* // Create an input ndarray:\n* var x = new ndarray( 'float64', xbuf, shape, sx, ox, 'row-major' );\n*\n* // Create an output ndarray:\n* var y = empty( [], {\n* 'dtype': 'bool'\n* });\n*\n* // Perform reduction:\n* var out = includes.assign( x, 6.0, y );\n* // returns \n*\n* var v = out.get();\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport assign from './assign.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nexport default main;\n\n// exports: { \"assign\": \"main.assign\" }\n"],"names":["validate","opts","ndims","options","tmp","isObject","TypeError","format","hasOwnProp","keepdims","isBoolean","dims","isIntegerArray","isEmptyCollection","normalizeIndices","RangeError","join","length","Error","includes","x","searchElement","view","err","idx","shx","shy","ord","dt","N","v","y","isndarrayLike","getShape","objectAssign","defaults","arguments","zeroTo","indicesComplement","takeIndexed","getDType","getOrder","isMostlySafeCast","maybeBroadcastArray","isScalarMostlySafeCompatible","broadcastScalar","empty","dtype","order","ndarrayCtor","reinterpretBoolean","getData","getStrides","getOffset","unaryReduceSubarray","base","spreadDimensions","assign","setReadOnly","main"],"mappings":"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"} \ No newline at end of file diff --git a/lib/assign.js b/lib/assign.js deleted file mode 100644 index 42a2d90..0000000 --- a/lib/assign.js +++ /dev/null @@ -1,144 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isScalarMostlySafeCompatible = require( '@stdlib/ndarray-base-assert-is-scalar-mostly-safe-compatible' ); // eslint-disable-line id-length -var isMostlySafeCast = require( '@stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var unaryReduceSubarray = require( '@stdlib/ndarray-base-unary-reduce-subarray' ); -var ndims = require( '@stdlib/ndarray-ndims' ); -var base = require( '@stdlib/ndarray-base-includes' ); -var getShape = require( '@stdlib/ndarray-shape' ); // note: non-base accessor is intentional due to the input arrays originating in userland -var getOrder = require( '@stdlib/ndarray-base-order' ); -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var maybeBroadcastArray = require( '@stdlib/ndarray-base-maybe-broadcast-array' ); -var broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' ); -var objectAssign = require( '@stdlib/object-assign' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var format = require( '@stdlib/string-format' ); -var defaults = require( './defaults.json' ); -var validate = require( './validate.js' ); - - -// MAIN // - -/** -* Tests whether an ndarray contains a specified value along one or more dimensions and assigns the results to a provided output ndarray. -* -* @param {ndarray} x - input ndarray -* @param {(ndarray|*)} searchElement - search element -* @param {ndarray} y - output ndarray -* @param {Options} [options] - function options -* @param {IntegerArray} [options.dims] - list of dimensions over which to perform a reduction -* @throws {TypeError} first argument must be an ndarray-like object -* @throws {Error} second argument must be broadcast-compatible with the non-reduced dimensions of the input ndarray -* @throws {TypeError} second argument must have a data type which can be safely cast to the data type of the input ndarray -* @throws {TypeError} third argument must be an ndarray-like object -* @throws {TypeError} options argument must be an object -* @throws {Error} must provide valid options -* @returns {ndarray} output ndarray -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var empty = require( '@stdlib/ndarray-empty' ); -* -* // Create a data buffer: -* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); -* -* // Define the shape of the input array: -* var shape = [ 3, 1, 2 ]; -* -* // Define the array strides: -* var sx = [ 4, 4, 1 ]; -* -* // Define the index offset: -* var ox = 1; -* -* // Create an input ndarray: -* var x = new ndarray( 'float64', xbuf, shape, sx, ox, 'row-major' ); -* -* // Create an output ndarray: -* var y = empty( [], { -* 'dtype': 'bool' -* }); -* -* // Perform reduction: -* var out = assign( x, 6.0, y ); -* // returns -* -* var v = out.get(); -* // returns true -*/ -function assign( x, searchElement, y, options ) { - var opts; - var err; - var ord; - var dt; - var N; - var v; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray-like object. Value: `%s`.', x ) ); - } - if ( !isndarrayLike( y ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object. Value: `%s`.', y ) ); - } - N = ndims( x ); - - opts = objectAssign( {}, defaults ); - if ( arguments.length > 3 ) { - err = validate( opts, N, options ); - if ( err ) { - throw err; - } - } - if ( opts.dims === null ) { - opts.dims = zeroTo( N ); - } - // Resolve input array meta data: - dt = getDType( x ); - ord = getOrder( x ); - - // Determine how to broadcast the search element... - if ( isndarrayLike( searchElement ) ) { - if ( !isMostlySafeCast( getDType( searchElement ), dt ) ) { - throw new TypeError( format( 'invalid argument. Second argument cannot be safely cast to the input array data type. Value: `%s`.', searchElement ) ); - } - try { - v = maybeBroadcastArray( searchElement, getShape( y ) ); - } catch ( err ) { // eslint-disable-line no-unused-vars - throw new Error( 'invalid argument. Second argument must be broadcast-compatible with the non-reduced dimensions of the input array.' ); - } - } else if ( isScalarMostlySafeCompatible( searchElement, dt ) ) { - v = broadcastScalar( searchElement, dt, getShape( y ), ord ); - } else { - throw new TypeError( format( 'invalid argument. Second argument cannot be safely cast to the input array data type. Value: `%s`.', searchElement ) ); - } - // Perform the reduction: - unaryReduceSubarray( base, [ x, y, v ], opts.dims ); // note: we assume that this lower-level function handles further validation of the output ndarray (e.g., expected shape, etc) - return y; -} - - -// EXPORTS // - -module.exports = assign; diff --git a/lib/defaults.json b/lib/defaults.json deleted file mode 100644 index 08433b3..0000000 --- a/lib/defaults.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "dims": null, - "keepdims": false -} diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index e0e191b..0000000 --- a/lib/index.js +++ /dev/null @@ -1,103 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Test whether an ndarray contains a specified value along one or more dimensions. -* -* @module @stdlib/ndarray-includes -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var includes = require( '@stdlib/ndarray-includes' ); -* -* // Create a data buffer: -* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); -* -* // Define the shape of the input array: -* var sh = [ 3, 1, 2 ]; -* -* // Define the array strides: -* var sx = [ 4, 4, 1 ]; -* -* // Define the index offset: -* var ox = 1; -* -* // Create an input ndarray: -* var x = new ndarray( 'float64', xbuf, sh, sx, ox, 'row-major' ); -* -* // Perform reduction: -* var out = includes( x, 6.0 ); -* // returns -* -* var v = out.get(); -* // returns true -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var empty = require( '@stdlib/ndarray-empty' ); -* var includes = require( '@stdlib/ndarray-includes' ); -* -* // Create a data buffer: -* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); -* -* // Define the shape of the input array: -* var shape = [ 3, 1, 2 ]; -* -* // Define the array strides: -* var sx = [ 4, 4, 1 ]; -* -* // Define the index offset: -* var ox = 1; -* -* // Create an input ndarray: -* var x = new ndarray( 'float64', xbuf, shape, sx, ox, 'row-major' ); -* -* // Create an output ndarray: -* var y = empty( [], { -* 'dtype': 'bool' -* }); -* -* // Perform reduction: -* var out = includes.assign( x, 6.0, y ); -* // returns -* -* var v = out.get(); -* // returns true -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var assign = require( './assign.js' ); - - -// MAIN // - -setReadOnly( main, 'assign', assign ); - - -// EXPORTS // - -module.exports = main; - -// exports: { "assign": "main.assign" } diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 8131a8e..0000000 --- a/lib/main.js +++ /dev/null @@ -1,171 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isScalarMostlySafeCompatible = require( '@stdlib/ndarray-base-assert-is-scalar-mostly-safe-compatible' ); // eslint-disable-line id-length -var isMostlySafeCast = require( '@stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var unaryReduceSubarray = require( '@stdlib/ndarray-base-unary-reduce-subarray' ); -var base = require( '@stdlib/ndarray-base-includes' ); -var spreadDimensions = require( '@stdlib/ndarray-base-spread-dimensions' ); -var indicesComplement = require( '@stdlib/array-base-indices-complement' ); -var getShape = require( '@stdlib/ndarray-shape' ); // note: non-base accessor is intentional due to the input array originating in userland -var getOrder = require( '@stdlib/ndarray-base-order' ); -var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var empty = require( '@stdlib/ndarray-empty' ); -var ndarrayCtor = require( '@stdlib/ndarray-base-ctor' ); -var maybeBroadcastArray = require( '@stdlib/ndarray-base-maybe-broadcast-array' ); -var broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' ); -var reinterpretBoolean = require( '@stdlib/strided-base-reinterpret-boolean' ); -var takeIndexed = require( '@stdlib/array-base-take-indexed' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var objectAssign = require( '@stdlib/object-assign' ); -var format = require( '@stdlib/string-format' ); -var defaults = require( './defaults.json' ); -var validate = require( './validate.js' ); - - -// MAIN // - -/** -* Tests whether an ndarray contains a specified value along one or more dimensions. -* -* @param {ndarray} x - input ndarray -* @param {(ndarray|*)} searchElement - search element -* @param {Options} [options] - function options -* @param {IntegerArray} [options.dims] - list of dimensions over which to perform a reduction -* @param {boolean} [options.keepdims=false] - boolean indicating whether the reduced dimensions should be included in the returned ndarray as singleton dimensions -* @throws {TypeError} first argument must be an ndarray-like object -* @throws {Error} second argument must be broadcast-compatible with the non-reduced dimensions of the input ndarray -* @throws {TypeError} second argument must have a data type which can be safely cast to the data type of the input ndarray -* @throws {TypeError} options argument must be an object -* @throws {RangeError} dimension indices must not exceed input ndarray bounds -* @throws {RangeError} number of dimension indices must not exceed the number of input ndarray dimensions -* @throws {Error} must provide valid options -* @returns {ndarray} output ndarray -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* // Create a data buffer: -* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); -* -* // Define the shape of the input array: -* var sh = [ 3, 1, 2 ]; -* -* // Define the array strides: -* var sx = [ 4, 4, 1 ]; -* -* // Define the index offset: -* var ox = 1; -* -* // Create an input ndarray: -* var x = new ndarray( 'float64', xbuf, sh, sx, ox, 'row-major' ); -* -* // Perform reduction: -* var out = includes( x, 6.0 ); -* // returns -* -* var v = out.get(); -* // returns true -*/ -function includes( x, searchElement, options ) { - var opts; - var view; - var err; - var idx; - var shx; - var shy; - var ord; - var dt; - var N; - var v; - var y; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray-like object. Value: `%s`.', x ) ); - } - shx = getShape( x ); - N = shx.length; - - opts = objectAssign( {}, defaults ); - if ( arguments.length > 2 ) { - err = validate( opts, N, options ); - if ( err ) { - throw err; - } - } - // When a list of dimensions is not provided, reduce the entire input array across all dimensions... - if ( opts.dims === null ) { - opts.dims = zeroTo( N ); - } - // Resolve the list of non-reduced dimensions: - idx = indicesComplement( N, opts.dims ); - - // Resolve the output array shape: - shy = takeIndexed( shx, idx ); - - // Resolve input array meta data: - dt = getDType( x ); - ord = getOrder( x ); - - // Determine how to broadcast the search element... - if ( isndarrayLike( searchElement ) ) { - if ( !isMostlySafeCast( getDType( searchElement ), dt ) ) { - throw new TypeError( format( 'invalid argument. Second argument cannot be safely cast to the input array data type. Value: `%s`.', searchElement ) ); - } - try { - v = maybeBroadcastArray( searchElement, shy ); - } catch ( err ) { // eslint-disable-line no-unused-vars - throw new Error( 'invalid argument. Second argument must be broadcast-compatible with the non-reduced dimensions of the input array.' ); - } - } else if ( isScalarMostlySafeCompatible( searchElement, dt ) ) { - v = broadcastScalar( searchElement, dt, shy, ord ); - } else { - throw new TypeError( format( 'invalid argument. Second argument cannot be safely cast to the input array data type. Value: `%s`.', searchElement ) ); - } - // Initialize an output array whose shape matches that of the non-reduced dimensions and which has the same memory layout as the input array: - y = empty( shy, { - 'dtype': 'bool', - 'order': ord - }); - - // Reinterpret the output array as an "indexed" array to ensure faster element access: - view = new ndarrayCtor( 'uint8', reinterpretBoolean( getData( y ), 0 ), shy, getStrides( y, false ), getOffset( y ), getOrder( y ) ); - - // Perform the reduction: - unaryReduceSubarray( base, [ x, view, v ], opts.dims ); - - // Check whether we need to reinsert singleton dimensions which can be useful for broadcasting the returned output array to the shape of the original input array... - if ( opts.keepdims ) { - y = spreadDimensions( N, y, idx, true ); - } - return y; -} - - -// EXPORTS // - -module.exports = includes; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index df22202..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,90 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isIntegerArray = require( '@stdlib/assert-is-integer-array' ).primitives; -var isEmptyCollection = require( '@stdlib/assert-is-empty-collection' ); -var normalizeIndices = require( '@stdlib/ndarray-base-to-unique-normalized-indices' ); -var join = require( '@stdlib/array-base-join' ); -var format = require( '@stdlib/string-format' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {NonNegativeInteger} ndims - number of input ndarray dimensions -* @param {Options} options - function options -* @param {boolean} [options.keepdims] - boolean indicating whether the reduced dimensions should be included in the returned ndarray as singleton dimensions -* @param {IntegerArray} [options.dims] - list of dimensions over which to perform a reduction -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'keepdims': true -* }; -* var err = validate( opts, 3, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, ndims, options ) { - var tmp; - if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp( options, 'keepdims' ) ) { - opts.keepdims = options.keepdims; - if ( !isBoolean( opts.keepdims ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'keepdims', opts.keepdims ) ); - } - } - if ( hasOwnProp( options, 'dims' ) ) { - opts.dims = options.dims; - if ( !isIntegerArray( opts.dims ) && !isEmptyCollection( opts.dims ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an array of integers. Option: `%s`.', 'dims', opts.dims ) ); - } - tmp = normalizeIndices( opts.dims, ndims-1 ); - if ( tmp === null ) { - return new RangeError( format( 'invalid option. `%s` option contains an out-of-bounds dimension index. Option: [%s].', 'dims', join( opts.dims, ',' ) ) ); - } - if ( tmp.length !== opts.dims.length ) { - return new Error( format( 'invalid option. `%s` option contains duplicate indices. Option: [%s].', 'dims', join( opts.dims, ',' ) ) ); - } - if ( tmp.length > ndims ) { - return new RangeError( format( 'invalid option. `%s` option specifies more dimensions than exists in the input array. Number of dimensions: %d. Option: [%s].', 'dims', ndims, join( opts.dims, ',' ) ) ); - } - opts.dims = tmp; - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 5f19daf..5b86d67 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.1", "description": "Test whether an ndarray contains a specified value along one or more dimensions.", "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,73 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-indices-complement": "^0.1.1", - "@stdlib/array-base-join": "^0.1.2", - "@stdlib/array-base-take-indexed": "^0.2.3", - "@stdlib/array-base-zero-to": "^0.2.2", - "@stdlib/assert-has-own-property": "^0.2.3", - "@stdlib/assert-is-boolean": "^0.2.3", - "@stdlib/assert-is-empty-collection": "^0.2.4", - "@stdlib/assert-is-integer-array": "^0.2.3", - "@stdlib/assert-is-ndarray-like": "^0.2.3", - "@stdlib/assert-is-plain-object": "^0.2.3", - "@stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast": "^0.3.1", - "@stdlib/ndarray-base-assert-is-scalar-mostly-safe-compatible": "^0.1.1", - "@stdlib/ndarray-base-broadcast-scalar": "^0.2.4", - "@stdlib/ndarray-base-ctor": "^0.3.1", - "@stdlib/ndarray-base-data-buffer": "^0.2.3", - "@stdlib/ndarray-base-dtype": "^0.2.3", - "@stdlib/ndarray-base-includes": "^0.1.1", - "@stdlib/ndarray-base-maybe-broadcast-array": "^0.2.5", - "@stdlib/ndarray-base-offset": "^0.2.3", - "@stdlib/ndarray-base-order": "^0.2.3", - "@stdlib/ndarray-base-spread-dimensions": "^0.1.1", - "@stdlib/ndarray-base-strides": "^0.2.3", - "@stdlib/ndarray-base-to-unique-normalized-indices": "^0.1.1", - "@stdlib/ndarray-base-unary-reduce-subarray": "^0.1.1", - "@stdlib/ndarray-empty": "^0.3.1", - "@stdlib/ndarray-ndims": "^0.2.3", - "@stdlib/ndarray-shape": "^0.2.3", - "@stdlib/object-assign": "^0.2.3", - "@stdlib/strided-base-reinterpret-boolean": "^0.0.3", - "@stdlib/string-format": "^0.2.3", - "@stdlib/types": "^0.5.1", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3" - }, - "devDependencies": { - "@stdlib/assert-is-method": "^0.2.3", - "@stdlib/math-base-special-floor": "^0.2.4", - "@stdlib/math-base-special-pow": "^0.3.1", - "@stdlib/math-base-special-sqrt": "^0.2.3", - "@stdlib/ndarray-base-shape2strides": "^0.2.3", - "@stdlib/ndarray-ctor": "^0.3.1", - "@stdlib/ndarray-fill-by": "^0.1.1", - "@stdlib/ndarray-to-array": "^0.2.2", - "@stdlib/ndarray-zeros": "^0.3.1", - "@stdlib/random-array-discrete-uniform": "^0.2.2", - "@stdlib/random-base-discrete-uniform": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.3" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "strided", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..ebc8aa2 --- /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 c883090..0000000 --- a/test/test.js +++ /dev/null @@ -1,39 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isMethod = require( '@stdlib/assert-is-method' ); -var includes = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof includes, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is an `assign` method', function test( t ) { - t.strictEqual( isMethod( includes, 'assign' ), true, 'returns expected value' ); - t.end(); -});