diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index dab5d2a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,180 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 731bd4f..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/dispatch) 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 5e92c3e..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/dispatch) 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 2b4fac7..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: '43 7 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -304,7 +295,7 @@ console.log( ybuf ); ## 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]. @@ -367,11 +358,11 @@ Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-dispatch/main/LICENSE -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@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 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.dispatch_size.js b/benchmark/benchmark.dispatch_size.js deleted file mode 100644 index 15805ba..0000000 --- a/benchmark/benchmark.dispatch_size.js +++ /dev/null @@ -1,156 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var pkg = require( './../package.json' ).name; -var dispatch = require( './../lib/main.js' ); - - -// FUNCTIONS // - -/** -* Evaluates the identity function. -* -* @private -* @param {*} v - value -* @returns {*} input value -*/ -function identity( v ) { - return v; -} - -/** -* Dummy function which throws an error. -* -* @private -* @throws {Error} unexpected error -*/ -function throwError() { - throw new Error( 'unexpected error' ); -} - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} size - dispatch size -* @returns {Function} benchmark function -*/ -function createBenchmark( size ) { - var types; - var data; - var fcn; - var x; - var y; - var t; - var i; - - types = []; - - // Create dummy types... - for ( i = 0; i < (size-1)*2; i += 2 ) { - t = 'foo' + i; - types.push( t ); - types.push( t ); - } - // Append test types: - types.push( 'float64' ); - types.push( 'float64' ); - - // Define a list of callbacks: - data = []; - for ( i = 0; i < size-1; i++ ) { - data.push( throwError ); - } - // Append a test callback: - data.push( identity ); - - // Create the dispatcher: - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - // Create sample arrays: - x = new Float64Array( 1 ); - y = new Float64Array( x.length ); - - x = ndarray( 'float64', x, [ 1 ], [ 1 ], 0, 'row-major' ); - y = ndarray( 'float64', y, [ 1 ], [ 1 ], 0, 'row-major' ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var z; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x.data[ 0 ] = i; - z = fcn( x, y ); - if ( isnan( z.data[ 0 ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( z.data[ 0 ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var size; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - size = pow( 2, i ); - f = createBenchmark( size ); - bench( pkg+':size='+size, f ); - } -} - -main(); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 3c6f450..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isFunction = require( '@stdlib/assert-is-function' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var pkg = require( './../package.json' ).name; -var dispatch = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::fcns_array', function benchmark( b ) { - var types; - var fcns; - var data; - var out; - var i; - - fcns = [ unary ]; - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = dispatch( fcns, types, data, 2, 1, 1 ); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::fcn_arg', function benchmark( b ) { - var types; - var data; - var out; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = dispatch( unary, types, data, 2, 1, 1 ); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 0aae4af..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/dispatch" -%% click B href "https://github.com/stdlib-js/ndarray-dispatch/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-dispatch/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-dispatch/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-dispatch/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-dispatch/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch -[production-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-dispatch/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-dispatch/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-dispatch/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 1295a44..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import dispatch from '../docs/types/index'; -export = dispatch; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 945d47d..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var q=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var b=q(function(S,y){"use strict";var w=require("@stdlib/assert-is-nonnegative-integer").isPrimitive,T=require("@stdlib/assert-is-positive-integer"),V=require("@stdlib/assert-is-integer").isPrimitive,x=require("@stdlib/assert-is-function-array"),F=require("@stdlib/assert-is-function"),c=require("@stdlib/assert-is-collection"),I=require("@stdlib/assert-is-ndarray-like"),n=require("@stdlib/string-format"),k=require("@stdlib/ndarray-dtype"),j=require("@stdlib/ndarray-base-dtype-resolve-enum"),A=require("@stdlib/ndarray-base-dtypes2enums"),P=require("@stdlib/blas-ext-base-gindex-of-row").ndarray;function U(e,r,i,t,v,m){var a,u,d;if(F(e))d=e;else if(!x(e))throw new TypeError(n("invalid argument. First argument must be either a function or an array of functions. Value: `%s`.",e));if(!c(r))throw new TypeError(n("invalid argument. Second argument must be an array-like object. Value: `%s`.",r));if(!c(i)&&i!==null)throw new TypeError(n("invalid argument. Third argument must be an array-like object or null. Value: `%s`.",i));if(!T(t))throw new TypeError(n("invalid argument. Fourth argument must be a positive integer. Value: `%s`.",t));if(!w(v))throw new TypeError(n("invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.",v));if(!w(m))throw new TypeError(n("invalid argument. Sixth argument must be a nonnegative integer. Value: `%s`.",m));if(a=v+m,a===0)throw new Error("invalid arguments. Interface must accept at least one input and/or output ndarray. Based on the provided arguments, `nin+nout` equals `0`.");if(t!==a)throw new Error("invalid arguments. Fourth argument does not equal the number of input and output ndarrays.");if(d){if(u=r.length/a,!V(u))throw new Error("invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.")}else if(u=e.length,r.length!==u*a)throw new Error("invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.");if(i&&i.length!==u)throw new Error("invalid argument. The third argument must have the same number of elements as the first argument.");return r=A(r),E;function E(){var o,g,p,f,s,h,l;if(p=arguments.length,p!==t)throw p [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either a function or an array of functions. Value: `%s`.', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be a positive integer. Value: `%s`.', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Sixth argument must be a nonnegative integer. Value: `%s`.', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( 'invalid arguments. Interface must accept at least one input and/or output ndarray. Based on the provided arguments, `nin+nout` equals `0`.' );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( 'invalid arguments. Fourth argument does not equal the number of input and output ndarrays.' );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( 'invalid argument. The third argument must have the same number of elements as the first argument.' );\n\t}\n\ttypes = dtypes2enums( types );\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( 'invalid invocation. Insufficient arguments.' );\n\t\t\t}\n\t\t\tthrow new Error( 'invalid invocation. Too many arguments.' );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( resolveEnum( getDType( v ) ) );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = gindexOfRow( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 );\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( 'invalid arguments. Unable to resolve an ndarray function supporting the provided array argument data types.' );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = dispatch;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Create an ndarray function interface which performs multiple dispatch.\n*\n* @module @stdlib/ndarray-dispatch\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var unary = require( '@stdlib/ndarray-base-unary' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n* var Float64Array = require( '@stdlib/array-float64' );\n* var dispatch = require( '@stdlib/ndarray-dispatch' );\n*\n* var types = [\n* 'float64', 'float64'\n* ];\n*\n* var data = [\n* abs\n* ];\n*\n* var absolute = dispatch( unary, types, data, 2, 1, 1 );\n*\n* // ...\n*\n* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] );\n* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] );\n*\n* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' );\n* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' );\n*\n* absolute( x, y );\n* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,EAAoB,QAAS,oCAAqC,EAClEC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAkB,QAAS,kCAAmC,EAC9DC,EAAa,QAAS,4BAA6B,EACnDC,EAAe,QAAS,8BAA+B,EACvDC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAc,QAAS,yCAA0C,EACjEC,EAAe,QAAS,mCAAoC,EAC5DC,EAAc,QAAS,qCAAsC,EAAE,QAqDnE,SAASC,EAAUC,EAAMC,EAAOC,EAAMC,EAAOC,EAAKC,EAAO,CACxD,IAAIC,EACAC,EACAC,EAEJ,GAAKjB,EAAYS,CAAK,EACrBQ,EAAMR,UACK,CAACV,EAAiBU,CAAK,EAClC,MAAM,IAAI,UAAWN,EAAQ,oGAAqGM,CAAK,CAAE,EAE1I,GAAK,CAACR,EAAcS,CAAM,EACzB,MAAM,IAAI,UAAWP,EAAQ,+EAAgFO,CAAM,CAAE,EAEtH,GAAK,CAACT,EAAcU,CAAK,GAAKA,IAAS,KACtC,MAAM,IAAI,UAAWR,EAAQ,sFAAuFQ,CAAK,CAAE,EAE5H,GAAK,CAACd,EAAmBe,CAAM,EAC9B,MAAM,IAAI,UAAWT,EAAQ,6EAA8ES,CAAM,CAAE,EAEpH,GAAK,CAAChB,EAAsBiB,CAAI,EAC/B,MAAM,IAAI,UAAWV,EAAQ,+EAAgFU,CAAI,CAAE,EAEpH,GAAK,CAACjB,EAAsBkB,CAAK,EAChC,MAAM,IAAI,UAAWX,EAAQ,+EAAgFW,CAAK,CAAE,EAGrH,GADAC,EAAUF,EAAMC,EACXC,IAAY,EAChB,MAAM,IAAI,MAAO,4IAA6I,EAE/J,GAAKH,IAAUG,EACd,MAAM,IAAI,MAAO,4FAA6F,EAE/G,GAAKE,GAEJ,GADAD,EAAQN,EAAM,OAASK,EAClB,CAACjB,EAAWkB,CAAM,EACtB,MAAM,IAAI,MAAO,8IAA+I,UAGjKA,EAAQP,EAAK,OACRC,EAAM,SAAWM,EAAMD,EAC3B,MAAM,IAAI,MAAO,8IAA+I,EAGlK,GAAKJ,GAAQA,EAAK,SAAWK,EAC5B,MAAM,IAAI,MAAO,mGAAoG,EAEtH,OAAAN,EAAQJ,EAAcI,CAAM,EACrBQ,EAeP,SAASA,GAAa,CACrB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GADAJ,EAAO,UAAU,OACZA,IAAST,EACb,MAAKS,EAAOT,EACL,IAAI,MAAO,6CAA8C,EAE1D,IAAI,MAAO,yCAA0C,EAI5D,IAFAO,EAAS,CAAC,EACVC,EAAS,CAAC,EACJK,EAAI,EAAGA,EAAIb,EAAOa,IAAM,CAE7B,GADAF,EAAI,UAAWE,CAAE,EACZ,CAACvB,EAAeqB,CAAE,EACtB,MAAKE,EAAIZ,EACF,IAAI,UAAWV,EAAQ,6EAA8EoB,CAAE,CAAE,EAEzG,IAAI,UAAWpB,EAAQ,8EAA+EoB,CAAE,CAAE,EAGlHJ,EAAO,KAAMI,CAAE,EACfH,EAAO,KAAMf,EAAaD,EAAUmB,CAAE,CAAE,CAAE,CAC3C,CAKA,GAHAD,EAAMf,EAAaS,EAAOD,EAASL,EAAOK,EAAS,EAAG,EAAGK,EAAQ,EAAG,CAAE,EAGjEE,EAAM,EACV,MAAM,IAAI,UAAW,6GAA8G,EAcpI,GAXKL,EACJO,EAAIP,EAEJO,EAAIf,EAAMa,CAAI,EAGVX,EACJa,EAAGL,EAAQR,EAAMW,CAAI,CAAE,EAEvBE,EAAGL,CAAO,EAENL,IAAS,EACb,OAAOK,EAAQJ,EAAQ,CAAE,EAE1B,GAAKD,IAAS,EAGd,OAAOK,EAAO,MAAON,CAAI,CAC1B,CACD,CAKAlB,EAAO,QAAUa,IC1JjB,IAAIkB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isNonNegativeInteger", "isPositiveInteger", "isInteger", "isFunctionArray", "isFunction", "isCollection", "isndarrayLike", "format", "getDType", "resolveEnum", "dtypes2enums", "gindexOfRow", "dispatch", "fcns", "types", "data", "nargs", "nin", "nout", "narrays", "nfcns", "fcn", "dispatcher", "arrays", "dtypes", "argc", "idx", "v", "f", "i", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 02fe150..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,87 +0,0 @@ - -{{alias}}( fcns, types, data, nargs, nin, nout ) - Returns an ndarray function interface which performs multiple dispatch. - - An ndarray function interface has the following signature: - - f( x, y, ... ) - - where - - - x: ndarray. - - y: ndarray. - - ...: additional ndarrays. - - The number of parameters is derived from `nargs`, the number of input - ndarrays is derived from `nin`, and the number of output ndarrays is derived - from `nout`. - - Parameters - ---------- - fcns: Function|ArrayLikeObject - List of ndarray functions. An ndarray function should have the following - signature: - - f( arrays, data ) - - where - - - arrays: array containing input and output ndarrays. - - data: ndarray function data (e.g., a callback). - - For convenience, a single ndarray function may be provided which will be - invoked whenever the ndarray argument data types match a sequence of - types in `types`. Providing a single ndarray function is particularly - convenient for the case where, regardless of array data types, - traversing arrays remains the same, but the ndarray function `data` - differs (e.g., callbacks which differ based on the array data types). - - types: ArrayLikeObject - One-dimensional list of ndarray argument data types. - - data: ArrayLikeObject|null - ndarray function data (e.g., callbacks). If `null`, a returned ndarray - function interface does **not** provide a `data` argument to an invoked - ndarray function. - - nargs: integer - Total number of ndarray function interface arguments. - - nin: integer - Number of input ndarrays. - - nout: integer - Number of output ndarrays. - - Returns - ------- - fcn: Function - ndarray function interface. - - Examples - -------- - // Define ndarray argument data types: - > var t = [ 'float64', 'float64', 'float32', 'float32' ]; - - // Define a list of ndarray function data (callbacks): - > var d = [ {{alias:@stdlib/math/base/special/abs}}, {{alias:@stdlib/math/base/special/absf}} ]; - - // Create an ndarray function interface for applying unary callbacks: - > var f = {{alias}}( {{alias:@stdlib/ndarray/base/unary}}, t, d, 2, 1, 1 ); - - // Create an input ndarray: - > var xbuf = new {{alias:@stdlib/array/float64}}( [ -1.0, -2.0, -3.0, -4.0 ] ); - > var x = {{alias:@stdlib/ndarray/ctor}}( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - // Create an output ndarray: - > var ybuf = new {{alias:@stdlib/array/float64}}( [ 0.0, 0.0, 0.0, 0.0 ] ); - > var y = {{alias:@stdlib/ndarray/ctor}}( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - // Compute the element-wise absolute value: - > f( x, y ); - > ybuf - [ 1.0, 2.0, 3.0, 4.0 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 3fece39..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,615 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable max-lines, prefer-const */ - -/// - -import { ndarray } from '@stdlib/types/ndarray'; -import ind2sub = require( '@stdlib/ndarray-ind2sub' ); -import dispatch = require( './index' ); - - -// FUNCTIONS // - -/** -* Nullary callback. -* -* @returns input value -*/ -function nullary(): any { - return 5.0; -} - -/** -* Unary callback. -* -* @param x - input value -* @returns input value -*/ -function unary( x: any ): any { - return x; -} - -/** -* Binary callback. -* -* @param x - input value -* @param y - input value -* @returns output value -*/ -function binary( x: number, y: number ): number { - return x + y; -} - -/** -* Ternary callback. -* -* @param x - input value -* @param y - input value -* @param z - input value -* @returns output value -*/ -function ternary( x: number, y: number, z: number ): number { - return x + y + z; -} - -/** -* Quaternary callback. -* -* @param x - input value -* @param y - input value -* @param z - input value -* @param w - input value -* @returns output value -*/ -function quaternary( x: number, y: number, z: number, w: number ): number { - return x + y + z + w; -} - -/** -* Mock ndarray function. -* -* @param arrays - ndarrays -* @param fcn - callback -*/ -function ndarrayFcn( arrays: Array, fcn: ( x: any ) => any ): void { - let xord; - let yord; - let opts; - let sub; - let sh; - let N; - let x; - let y; - let v; - let i; - - x = arrays[ 0 ]; - y = arrays[ 1 ]; - sh = x.shape; - if ( sh.length === 0 ) { - return; - } - N = 1; - for ( i = 0; i < sh.length; i += 1 ) { - N *= sh[ i ]; - } - xord = x.order; - yord = y.order; - opts = { - 'order': xord - }; - for ( i = 0; i < N; i += 1 ) { - // Convert a linear index to subscripts: - opts.order = xord; - sub = ind2sub( sh, i, opts ); - - // Retrieve an element from `x`: - v = x.get.apply( x, sub ); - - // Convert a linear index to subscripts: - opts.order = yord; - sub = ind2sub( sh, i, opts ); - - // Append the result of applying the callback: - sub[ sub.length ] = fcn( v ) as number; - - // Assign the result to an element in `y`: - y.set.apply( y, sub ); - } -} - -/** -* Mock function to create an ndarray-like object. -* -* @returns ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns a dispatch function... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, 1, 1 ); // $ExpectType Dispatcher - dispatch( [ ndarrayFcn ], types, data, 2, 1, 1 ); // $ExpectType Dispatcher -} - -// The compiler throws an error if the function is provided a first argument which is not either an ndarray function or an array-like object containing ndarray functions... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( '10', types, data, 2, 1, 1 ); // $ExpectError - dispatch( 10, types, data, 2, 1, 1 ); // $ExpectError - dispatch( true, types, data, 2, 1, 1 ); // $ExpectError - dispatch( false, types, data, 2, 1, 1 ); // $ExpectError - dispatch( null, types, data, 2, 1, 1 ); // $ExpectError - dispatch( undefined, types, data, 2, 1, 1 ); // $ExpectError - dispatch( [ '1' ], types, data, 2, 1, 1 ); // $ExpectError - dispatch( {}, types, data, 2, 1, 1 ); // $ExpectError - dispatch( ( x: number ): number => x, types, data, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object... -{ - const data = [ unary ]; - - dispatch( ndarrayFcn, 10, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, true, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, false, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, null, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, undefined, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, {}, data, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not an array-like object or null... -{ - const types = [ 'float64', 'float64' ]; - - dispatch( ndarrayFcn, types, 10, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, true, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, false, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, undefined, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, {}, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, '10', 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, true, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, false, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, null, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, undefined, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, [ '1' ], 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, {}, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, ( x: number ): number => x, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, '10', 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, true, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, false, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, null, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, undefined, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, [ '1' ], 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, {}, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, ( x: number ): number => x, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a sixth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, 1, '10' ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, true ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, false ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, null ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, undefined ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, [ '1' ] ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, {} ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch(); // $ExpectError - dispatch( ndarrayFcn ); // $ExpectError - dispatch( ndarrayFcn, types ); // $ExpectError - dispatch( ndarrayFcn, types, data ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, 1, 0 ); // $ExpectError -} - -// The function returns a dispatch function... -{ - const x = array(); - const y = array(); - const z = array(); - const w = array(); - const u = array(); - - const t1 = [ 'float64' ]; - const d1 = [ nullary ]; - const f1 = dispatch( ndarrayFcn, t1, d1, 1, 1, 0 ); - f1( x ); // $ExpectType void | ndarray - - const t2 = [ 'float64', 'float64' ]; - const d2 = [ unary ]; - const f2 = dispatch( ndarrayFcn, t2, d2, 2, 1, 1 ); - f2( x, y ); // $ExpectType void | ndarray - - const t3 = [ 'float64', 'float64', 'float64' ]; - const d3 = [ binary ]; - const f3 = dispatch( ndarrayFcn, t3, d3, 3, 2, 1 ); - f3( x, y, z ); // $ExpectType void | ndarray - - const t4 = [ 'float64', 'float64', 'float64', 'float64' ]; - const d4 = [ ternary ]; - const f4 = dispatch( ndarrayFcn, t4, d4, 4, 3, 1 ); - f4( x, y, z, w ); // $ExpectType void | ndarray - - const t5 = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const d5 = [ quaternary ]; - const f5 = dispatch( ndarrayFcn, t5, d5, 5, 4, 1 ); - f5( x, y, z, w, u ); // $ExpectType void | ndarray -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (1 ndarray)... -{ - const types = [ 'float64' ]; - const data = [ nullary ]; - - const f = dispatch( ndarrayFcn, types, data, 1, 0, 1 ); - f( '10' ); // $ExpectError - f( 10 ); // $ExpectError - f( true ); // $ExpectError - f( false ); // $ExpectError - f( null ); // $ExpectError - f( undefined ); // $ExpectError - f( [ '1' ] ); // $ExpectError - f( {} ); // $ExpectError - f( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (2 ndarrays)... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - const y = array(); - - const f = dispatch( ndarrayFcn, types, data, 2, 1, 1 ); - f( 10, y ); // $ExpectError - f( '10', y ); // $ExpectError - f( true, y ); // $ExpectError - f( false, y ); // $ExpectError - f( null, y ); // $ExpectError - f( undefined, y ); // $ExpectError - f( [ '1' ], y ); // $ExpectError - f( {}, y ); // $ExpectError - f( ( x: number ): number => x, y ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (2 ndarrays)... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - const x = array(); - - const f = dispatch( ndarrayFcn, types, data, 2, 1, 1 ); - f( x, 10 ); // $ExpectError - f( x, '10' ); // $ExpectError - f( x, true ); // $ExpectError - f( x, false ); // $ExpectError - f( x, null ); // $ExpectError - f( x, undefined ); // $ExpectError - f( x, [ '1' ] ); // $ExpectError - f( x, {} ); // $ExpectError - f( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const y = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( 10, y, z ); // $ExpectError - f( '10', y, z ); // $ExpectError - f( true, y, z ); // $ExpectError - f( false, y, z ); // $ExpectError - f( null, y, z ); // $ExpectError - f( undefined, y, z ); // $ExpectError - f( [ '1' ], y, z ); // $ExpectError - f( {}, y, z ); // $ExpectError - f( ( x: number ): number => x, y, z ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const x = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( x, 10, z ); // $ExpectError - f( x, '10', z ); // $ExpectError - f( x, true, z ); // $ExpectError - f( x, false, z ); // $ExpectError - f( x, null, z ); // $ExpectError - f( x, undefined, z ); // $ExpectError - f( x, [ '1' ], z ); // $ExpectError - f( x, {}, z ); // $ExpectError - f( x, ( x: number ): number => x, z ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const x = array(); - const y = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( x, y, '10' ); // $ExpectError - f( x, y, true ); // $ExpectError - f( x, y, false ); // $ExpectError - f( x, y, null ); // $ExpectError - f( x, y, undefined ); // $ExpectError - f( x, y, [ '1' ] ); // $ExpectError - f( x, y, {} ); // $ExpectError - f( x, y, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const y = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( 10, y, z, w ); // $ExpectError - f( '10', y, z, w ); // $ExpectError - f( true, y, z, w ); // $ExpectError - f( false, y, z, w ); // $ExpectError - f( null, y, z, w ); // $ExpectError - f( undefined, y, z, w ); // $ExpectError - f( [ '1' ], y, z, w ); // $ExpectError - f( {}, y, z, w ); // $ExpectError - f( ( x: number ): number => x, y, z, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, 10, z, w ); // $ExpectError - f( x, '10', z, w ); // $ExpectError - f( x, true, z, w ); // $ExpectError - f( x, false, z, w ); // $ExpectError - f( x, null, z, w ); // $ExpectError - f( x, undefined, z, w ); // $ExpectError - f( x, [ '1' ], z, w ); // $ExpectError - f( x, {}, z, w ); // $ExpectError - f( x, ( x: number ): number => x, z, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const y = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, y, 10, w ); // $ExpectError - f( x, y, '10', w ); // $ExpectError - f( x, y, true, w ); // $ExpectError - f( x, y, false, w ); // $ExpectError - f( x, y, null, w ); // $ExpectError - f( x, y, undefined, w ); // $ExpectError - f( x, y, [ '1' ], w ); // $ExpectError - f( x, y, {}, w ); // $ExpectError - f( x, y, ( x: number ): number => x, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fourth argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const y = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, y, z, 10 ); // $ExpectError - f( x, y, z, '10' ); // $ExpectError - f( x, y, z, true ); // $ExpectError - f( x, y, z, false ); // $ExpectError - f( x, y, z, null ); // $ExpectError - f( x, y, z, undefined ); // $ExpectError - f( x, y, z, [ '1' ] ); // $ExpectError - f( x, y, z, {} ); // $ExpectError - f( x, y, z, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const y = array(); - const z = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( 10, y, z, w, u ); // $ExpectError - f( '10', y, z, w, u ); // $ExpectError - f( true, y, z, w, u ); // $ExpectError - f( false, y, z, w, u ); // $ExpectError - f( null, y, z, w, u ); // $ExpectError - f( undefined, y, z, w, u ); // $ExpectError - f( [ '1' ], y, z, w, u ); // $ExpectError - f( {}, y, z, w, u ); // $ExpectError - f( ( x: number ): number => x, y, z, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const z = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, 10, z, w, u ); // $ExpectError - f( x, '10', z, w, u ); // $ExpectError - f( x, true, z, w, u ); // $ExpectError - f( x, false, z, w, u ); // $ExpectError - f( x, null, z, w, u ); // $ExpectError - f( x, undefined, z, w, u ); // $ExpectError - f( x, [ '1' ], z, w, u ); // $ExpectError - f( x, {}, z, w, u ); // $ExpectError - f( x, ( x: number ): number => x, z, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, 10, w, u ); // $ExpectError - f( x, y, '10', w, u ); // $ExpectError - f( x, y, true, w, u ); // $ExpectError - f( x, y, false, w, u ); // $ExpectError - f( x, y, null, w, u ); // $ExpectError - f( x, y, undefined, w, u ); // $ExpectError - f( x, y, [ '1' ], w, u ); // $ExpectError - f( x, y, {}, w, u ); // $ExpectError - f( x, y, ( x: number ): number => x, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fourth argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const z = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, z, 10, u ); // $ExpectError - f( x, y, z, '10', u ); // $ExpectError - f( x, y, z, true, u ); // $ExpectError - f( x, y, z, false, u ); // $ExpectError - f( x, y, z, null, u ); // $ExpectError - f( x, y, z, undefined, u ); // $ExpectError - f( x, y, z, [ '1' ], u ); // $ExpectError - f( x, y, z, {}, u ); // $ExpectError - f( x, y, z, ( x: number ): number => x, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fifth argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, z, w, 10 ); // $ExpectError - f( x, y, z, w, '10' ); // $ExpectError - f( x, y, z, w, true ); // $ExpectError - f( x, y, z, w, false ); // $ExpectError - f( x, y, z, w, null ); // $ExpectError - f( x, y, z, w, undefined ); // $ExpectError - f( x, y, z, w, [ '1' ] ); // $ExpectError - f( x, y, z, w, {} ); // $ExpectError - f( x, y, z, w, ( x: number ): number => x ); // $ExpectError -} diff --git a/examples/add.js b/examples/add.js deleted file mode 100644 index 3949bc0..0000000 --- a/examples/add.js +++ /dev/null @@ -1,121 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var Int32Array = require( '@stdlib/array-int32' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var dispatch = require( './../lib' ); - -function add2( arrays ) { - var opts; - var xo; - var yo; - var zo; - var sx; - var sy; - var sz; - var sh; - var N; - var x; - var y; - var z; - var v; - var i; - - x = arrays[ 0 ]; - sh = x.shape; - N = numel( sh ); - if ( N <= 0 ) { - return; - } - y = arrays[ 1 ]; - z = arrays[ 2 ]; - xo = x.order; - yo = y.order; - zo = z.order; - opts = { - 'order': xo - }; - for ( i = 0; i < N; i++ ) { - opts.order = xo; - sx = ind2sub( sh, i, opts ); - opts.order = yo; - sy = ind2sub( sh, i, opts ); - v = x.get.apply( x, sx ) + y.get.apply( y, sy ); - - opts.order = zo; - sz = ind2sub( sh, i, opts ); - sz.push( v ); - z.set.apply( z, sz ); - } -} - -var fcns = [ - add2, - add2, - add2, - add2, - add2, - add2, - add2, - add2, - add2 -]; - -var types = [ - dtypes.float64.enum, dtypes.float64.enum, dtypes.float64.enum, - dtypes.float32.enum, dtypes.float32.enum, dtypes.float32.enum, - dtypes.int32.enum, dtypes.int32.enum, dtypes.int32.enum, - dtypes.uint32.enum, dtypes.uint32.enum, dtypes.uint32.enum, - dtypes.int16.enum, dtypes.int16.enum, dtypes.int16.enum, - dtypes.uint16.enum, dtypes.uint16.enum, dtypes.uint16.enum, - dtypes.int8.enum, dtypes.int8.enum, dtypes.int8.enum, - dtypes.uint8.enum, dtypes.uint8.enum, dtypes.uint8.enum, - dtypes.uint8c.enum, dtypes.uint8c.enum, dtypes.uint8c.enum -]; - -var add = dispatch( fcns, types, null, 3, 2, 1 ); - -var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var zbuf = new Float64Array( xbuf.length ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var z = ndarray( 'float64', zbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -add( x, y, z ); -console.log( zbuf ); - -xbuf = new Int32Array( [ 10, 20, 30, 40, 50 ] ); -ybuf = new Int32Array( [ 10, 20, 30, 40, 50 ] ); -zbuf = new Int32Array( xbuf.length ); - -x = ndarray( 'int32', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -y = ndarray( 'int32', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -z = ndarray( 'int32', zbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -add( x, y, z ); -console.log( zbuf ); diff --git a/examples/sin.js b/examples/sin.js deleted file mode 100644 index 106a586..0000000 --- a/examples/sin.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int8Array = require( '@stdlib/array-int8' ); -var sin = require( '@stdlib/math-base-special-sin' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var dispatch = require( './../lib' ); - -function apply( arrays, fcn ) { - var opts; - var xo; - var yo; - var sx; - var sy; - var sh; - var N; - var x; - var y; - var v; - var i; - - x = arrays[ 0 ]; - sh = x.shape; - N = numel( sh ); - if ( N <= 0 ) { - return; - } - y = arrays[ 1 ]; - xo = x.order; - yo = y.order; - opts = { - 'order': xo - }; - for ( i = 0; i < N; i++ ) { - opts.order = xo; - sx = ind2sub( sh, i, opts ); - v = fcn( x.get.apply( x, sx ) ); - - opts.order = yo; - sy = ind2sub( sh, i, opts ); - sy.push( v ); - y.set.apply( y, sy ); - } -} - -var fcns = [ - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply -]; - -var types = [ - dtypes.float64.enum, dtypes.float64.enum, - dtypes.float32.enum, dtypes.float64.enum, - dtypes.float32.enum, dtypes.float32.enum, - dtypes.int32.enum, dtypes.float64.enum, - dtypes.uint32.enum, dtypes.float64.enum, - dtypes.int16.enum, dtypes.float64.enum, - dtypes.int16.enum, dtypes.float32.enum, - dtypes.uint16.enum, dtypes.float64.enum, - dtypes.uint16.enum, dtypes.float32.enum, - dtypes.int8.enum, dtypes.float64.enum, - dtypes.int8.enum, dtypes.float32.enum, - dtypes.uint8.enum, dtypes.float64.enum, - dtypes.uint8.enum, dtypes.float32.enum, - dtypes.uint8c.enum, dtypes.float64.enum, - dtypes.uint8c.enum, dtypes.float32.enum -]; - -var data = [ - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin -]; - -var sine = dispatch( fcns, types, data, 2, 1, 1 ); - -var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -sine( x, y ); -console.log( ybuf ); - -xbuf = new Int8Array( [ 1, 2, 3, 4, 5 ] ); -ybuf = new Float32Array( xbuf.length ); - -x = ndarray( 'int8', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -y = ndarray( 'float32', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -sine( x, y ); -console.log( ybuf ); diff --git a/examples/unary.js b/examples/unary.js deleted file mode 100644 index e9c3fb4..0000000 --- a/examples/unary.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 unary = require( '@stdlib/ndarray-base-unary' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var Float64Array = require( '@stdlib/array-float64' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var dispatch = require( './../lib' ); - -var types = [ 'float64', 'float64' ]; - -var data = [ - abs -]; - -var absolute = dispatch( unary, types, data, 2, 1, 1 ); - -var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -absolute( x, y ); -console.log( ybuf ); -// => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 5f280a1..c49a4e4 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..2efc206 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.2-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function-array@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype-resolve-enum@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtypes2enums@esm/index.mjs";import{ndarray as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/blas-ext-base-gindex-of-row@v0.0.0-esm/index.mjs";function p(p,f,w,v,a,g){var c,y,b;if(i(p))b=p;else if(!t(p))throw new TypeError(d("0jr5d",p));if(!n(f))throw new TypeError(d("0jr2y",f));if(!n(w)&&null!==w)throw new TypeError(d("0jr5e",w));if(!e(v))throw new TypeError(d("0jr5f",v));if(!r(a))throw new TypeError(d("0jr5X",a));if(!r(g))throw new TypeError(d("0jr5g",g));if(0===(c=a+g))throw new Error(d("0jr0h"));if(v!==c)throw new Error(d("0jr0i"));if(b){if(y=f.length/c,!s(y))throw new Error(d("0jr0j"))}else if(y=p.length,f.length!==y*c)throw new Error(d("0jr0j"));if(w&&w.length!==y)throw new Error(d("0jr0k"));return f=h(f),function(){var r,e,s,t,i,n,h;if(s=arguments.length,s!==v){if(s [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( '0jr5d', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( '0jr2y', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( '0jr5e', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( '0jr5f', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( '0jr5X', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( '0jr5g', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( format('0jr0h') );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( format('0jr0i') );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( format('0jr0j') );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( format('0jr0j') );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( format('0jr0k') );\n\t}\n\ttypes = dtypes2enums( types );\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( format('0jr0l') );\n\t\t\t}\n\t\t\tthrow new Error( format('0jr0m') );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( '0jr5h', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( '0jr5i', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( resolveEnum( getDType( v ) ) );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = gindexOfRow( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 );\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( format('0jr0n') );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default dispatch;\n"],"names":["dispatch","fcns","types","data","nargs","nin","nout","narrays","nfcns","fcn","isFunction","isFunctionArray","TypeError","format","isCollection","isPositiveInteger","isNonNegativeInteger","Error","length","isInteger","dtypes2enums","arrays","dtypes","argc","idx","v","f","i","arguments","isndarrayLike","push","resolveEnum","getDType","gindexOfRow","slice"],"mappings":";;wrCAsFA,SAASA,EAAUC,EAAMC,EAAOC,EAAMC,EAAOC,EAAKC,GACjD,IAAIC,EACAC,EACAC,EAEJ,GAAKC,EAAYT,GAChBQ,EAAMR,OACA,IAAMU,EAAiBV,GAC7B,MAAM,IAAIW,UAAWC,EAAQ,QAASZ,IAEvC,IAAMa,EAAcZ,GACnB,MAAM,IAAIU,UAAWC,EAAQ,QAASX,IAEvC,IAAMY,EAAcX,IAAmB,OAATA,EAC7B,MAAM,IAAIS,UAAWC,EAAQ,QAASV,IAEvC,IAAMY,EAAmBX,GACxB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAEvC,IAAMY,EAAsBX,GAC3B,MAAM,IAAIO,UAAWC,EAAQ,QAASR,IAEvC,IAAMW,EAAsBV,GAC3B,MAAM,IAAIM,UAAWC,EAAQ,QAASP,IAGvC,GAAiB,KADjBC,EAAUF,EAAMC,GAEf,MAAM,IAAIW,MAAOJ,EAAO,UAEzB,GAAKT,IAAUG,EACd,MAAM,IAAIU,MAAOJ,EAAO,UAEzB,GAAKJ,GAEJ,GADAD,EAAQN,EAAMgB,OAASX,GACjBY,EAAWX,GAChB,MAAM,IAAIS,MAAOJ,EAAO,eAIzB,GADAL,EAAQP,EAAKiB,OACRhB,EAAMgB,SAAWV,EAAMD,EAC3B,MAAM,IAAIU,MAAOJ,EAAO,UAG1B,GAAKV,GAAQA,EAAKe,SAAWV,EAC5B,MAAM,IAAIS,MAAOJ,EAAO,UAGzB,OADAX,EAAQkB,EAAclB,GAgBtB,WACC,IAAImB,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GADAJ,EAAOK,UAAUV,OACZK,IAASnB,EAAQ,CACrB,GAAKmB,EAAOnB,EACX,MAAM,IAAIa,MAAOJ,EAAO,UAEzB,MAAM,IAAII,MAAOJ,EAAO,SACxB,CAGD,IAFAQ,EAAS,GACTC,EAAS,GACHK,EAAI,EAAGA,EAAIvB,EAAOuB,IAAM,CAE7B,IAAME,EADNJ,EAAIG,UAAWD,IAEd,MAAKA,EAAItB,EACF,IAAIO,UAAWC,EAAQ,QAASY,IAEhC,IAAIb,UAAWC,EAAQ,QAASY,IAGxCJ,EAAOS,KAAML,GACbH,EAAOQ,KAAMC,EAAaC,EAAUP,IACpC,CAKD,IAHAD,EAAMS,EAAazB,EAAOD,EAASL,EAAOK,EAAS,EAAG,EAAGe,EAAQ,EAAG,IAGzD,EACV,MAAM,IAAIV,UAAWC,EAAO,UAI5Ba,EADIjB,GAGAR,EAAMuB,GAGNrB,EACJuB,EAAGL,EAAQlB,EAAMqB,IAEjBE,EAAGL,GAEJ,GAAc,IAATf,EACJ,OAAOe,EAAQd,EAAQ,GAExB,GAAc,IAATD,EACJ,OAED,OAAOe,EAAOa,MAAO7B,EACrB,CACF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 88f0e3e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an ndarray function interface which performs multiple dispatch. -* -* @module @stdlib/ndarray-dispatch -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* var dispatch = require( '@stdlib/ndarray-dispatch' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var absolute = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* absolute( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 29d8984..0000000 --- a/lib/main.js +++ /dev/null @@ -1,211 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var isFunctionArray = require( '@stdlib/assert-is-function-array' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var format = require( '@stdlib/string-format' ); -var getDType = require( '@stdlib/ndarray-dtype' ); -var resolveEnum = require( '@stdlib/ndarray-base-dtype-resolve-enum' ); -var dtypes2enums = require( '@stdlib/ndarray-base-dtypes2enums' ); -var gindexOfRow = require( '@stdlib/blas-ext-base-gindex-of-row' ).ndarray; - - -// MAIN // - -/** -* Returns an ndarray function interface which performs multiple dispatch. -* -* @param {(FunctionArray|Function)} fcns - list of ndarray functions -* @param {Collection} types - one-dimensional list of ndarray argument data types -* @param {(Collection|null)} data - ndarray function data (e.g., callbacks) -* @param {PositiveInteger} nargs - total number of ndarray function interface arguments -* @param {NonNegativeInteger} nin - number of input ndarrays -* @param {NonNegativeInteger} nout - number of output ndarrays -* @throws {TypeError} first argument must be either a function or an array of functions -* @throws {TypeError} second argument must be an array-like object -* @throws {TypeError} third argument must be an array-like object or `null` -* @throws {Error} third and first arguments must have the same number of elements -* @throws {TypeError} fourth argument must be a positive integer -* @throws {TypeError} fifth argument must be a nonnegative integer -* @throws {TypeError} sixth argument must be a nonnegative integer -* @throws {Error} fourth argument must equal the specified number of input and output arrays -* @throws {Error} number of types must match the number of functions times the total number of array arguments for each function -* @throws {Error} interface must accept at least one input and/or output ndarray -* @returns {Function} ndarray function interface -* -* @example -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var absolute = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* absolute( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function dispatch( fcns, types, data, nargs, nin, nout ) { - var narrays; - var nfcns; - var fcn; - - if ( isFunction( fcns ) ) { - fcn = fcns; - } else if ( !isFunctionArray( fcns ) ) { - throw new TypeError( format( 'invalid argument. First argument must be either a function or an array of functions. Value: `%s`.', fcns ) ); - } - if ( !isCollection( types ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', types ) ); - } - if ( !isCollection( data ) && data !== null ) { - throw new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) ); - } - if ( !isPositiveInteger( nargs ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be a positive integer. Value: `%s`.', nargs ) ); - } - if ( !isNonNegativeInteger( nin ) ) { - throw new TypeError( format( 'invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.', nin ) ); - } - if ( !isNonNegativeInteger( nout ) ) { - throw new TypeError( format( 'invalid argument. Sixth argument must be a nonnegative integer. Value: `%s`.', nout ) ); - } - narrays = nin + nout; - if ( narrays === 0 ) { - throw new Error( 'invalid arguments. Interface must accept at least one input and/or output ndarray. Based on the provided arguments, `nin+nout` equals `0`.' ); - } - if ( nargs !== narrays ) { - throw new Error( 'invalid arguments. Fourth argument does not equal the number of input and output ndarrays.' ); - } - if ( fcn ) { - nfcns = types.length / narrays; - if ( !isInteger( nfcns ) ) { - throw new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' ); - } - } else { - nfcns = fcns.length; - if ( types.length !== nfcns*narrays ) { - throw new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' ); - } - } - if ( data && data.length !== nfcns ) { - throw new Error( 'invalid argument. The third argument must have the same number of elements as the first argument.' ); - } - types = dtypes2enums( types ); - return dispatcher; - - /** - * ndarray function interface which performs multiple dispatch. - * - * @private - * @param {ndarrayLike} x - ndarray - * @param {...ndarrayLike} args - ndarray arguments - * @throws {Error} insufficient arguments - * @throws {Error} too many arguments - * @throws {TypeError} input array arguments must be ndarray-like objects - * @throws {TypeError} output array arguments must be ndarray-like objects - * @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types - * @returns {(ndarrayLike|Array|void)} destination array(s) - */ - function dispatcher() { - var arrays; - var dtypes; - var argc; - var idx; - var v; - var f; - var i; - - argc = arguments.length; - if ( argc !== nargs ) { - if ( argc < nargs ) { - throw new Error( 'invalid invocation. Insufficient arguments.' ); - } - throw new Error( 'invalid invocation. Too many arguments.' ); - } - arrays = []; - dtypes = []; - for ( i = 0; i < nargs; i++ ) { - v = arguments[ i ]; - if ( !isndarrayLike( v ) ) { - if ( i < nin ) { - throw new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) ); - } else { - throw new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) ); - } - } - arrays.push( v ); - dtypes.push( resolveEnum( getDType( v ) ) ); - } - // Resolve the ndarray function satisfying the input array types: - idx = gindexOfRow( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); - - // Check whether we were able to successfully resolve an ndarray function: - if ( idx < 0 ) { - throw new TypeError( 'invalid arguments. Unable to resolve an ndarray function supporting the provided array argument data types.' ); - } - // Retrieve the ndarray function: - if ( fcn ) { - f = fcn; - } else { - f = fcns[ idx ]; - } - // Evaluate the ndarray function: - if ( data ) { - f( arrays, data[ idx ] ); - } else { - f( arrays ); - } - if ( nout === 1 ) { - return arrays[ narrays-1 ]; - } - if ( nout === 0 ) { - return; - } - return arrays.slice( nin ); - } -} - - -// EXPORTS // - -module.exports = dispatch; diff --git a/package.json b/package.json index 0d34d20..e6c8bad 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Create an ndarray function interface which performs multiple dispatch.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,58 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-collection": "^0.2.2", - "@stdlib/assert-is-function": "^0.2.2", - "@stdlib/assert-is-function-array": "^0.2.2", - "@stdlib/assert-is-integer": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-nonnegative-integer": "^0.2.2", - "@stdlib/assert-is-positive-integer": "^0.2.2", - "@stdlib/blas-ext-base-gindex-of-row": "github:stdlib-js/blas-ext-base-gindex-of-row#main", - "@stdlib/ndarray-base-dtype-resolve-enum": "^0.2.2", - "@stdlib/ndarray-base-dtypes2enums": "github:stdlib-js/ndarray-base-dtypes2enums#main", - "@stdlib/ndarray-dtype": "^0.2.2", - "@stdlib/string-format": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.2.2", - "@stdlib/array-float64": "^0.2.2", - "@stdlib/array-int32": "^0.2.2", - "@stdlib/array-int8": "^0.2.2", - "@stdlib/array-uint8": "^0.2.2", - "@stdlib/math-base-assert-is-nan": "^0.2.2", - "@stdlib/math-base-special-abs": "^0.2.2", - "@stdlib/math-base-special-pow": "^0.3.0", - "@stdlib/math-base-special-sin": "^0.3.0", - "@stdlib/ndarray-base-buffer-dtype": "^0.3.0", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-base-unary": "^0.2.1", - "@stdlib/ndarray-ctor": "^0.2.2", - "@stdlib/ndarray-dtypes": "^0.3.0", - "@stdlib/ndarray-ind2sub": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "ndarray", @@ -101,7 +26,6 @@ "multimethod", "multimethods" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..6a59ed9 --- /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/fixtures/binary.js b/test/fixtures/binary.js deleted file mode 100644 index a60dfa2..0000000 --- a/test/fixtures/binary.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Binary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @returns {number} sum -*/ -function binary( x, y ) { - return x + y; -} - - -// EXPORTS // - -module.exports = binary; diff --git a/test/fixtures/fill.js b/test/fixtures/fill.js deleted file mode 100644 index 41b2958..0000000 --- a/test/fixtures/fill.js +++ /dev/null @@ -1,76 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* Return an ndarray function which fills one or more ndarrays. -* -* @private -* @param {*} value - fill value -* @returns {Function} ndarray function -*/ -function fill( value ) { - return ndarrayFcn; - - /** - * ndarray function. - * - * @private - * @param {Array} arrays - ndarrays - */ - function ndarrayFcn( arrays ) { - var opts; - var sub; - var arr; - var sh; - var M; - var N; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - opts = { - 'order': '' - }; - for ( j = 0; j < M; j++ ) { - arr = arrays[ j ]; - opts.order = arrays[ j ].order; - for ( i = 0; i < N; i++ ) { - sub = ind2sub( sh, i, opts ); - sub.push( value ); - arr.set.apply( arr, sub ); - } - } - } -} - - -// EXPORTS // - -module.exports = fill; diff --git a/test/fixtures/foreach.js b/test/fixtures/foreach.js deleted file mode 100644 index a426290..0000000 --- a/test/fixtures/foreach.js +++ /dev/null @@ -1,72 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* ndarray function. -* -* @private -* @param {Array} arrays - ndarrays -* @param {Function} fcn - callback -*/ -function forEach( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - args[ j ] = arrays[ j ].get.apply( arrays[ j ], sub ); - } - fcn.apply( null, args ); - } -} - - -// EXPORTS // - -module.exports = forEach; diff --git a/test/fixtures/map1n.js b/test/fixtures/map1n.js deleted file mode 100644 index 614196b..0000000 --- a/test/fixtures/map1n.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* ndarray function which maps the return value of a callback to `N` arrays. -* -* @private -* @param {Array} arrays - ndarrays -* @param {Function} fcn - callback -*/ -function map1N( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var v; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - for ( i = 0; i < N; i++ ) { - v = fcn(); - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - sub.push( v ); - arrays[ j ].set.apply( arrays[ j ], sub ); - } - } -} - - -// EXPORTS // - -module.exports = map1N; diff --git a/test/fixtures/nullary.js b/test/fixtures/nullary.js deleted file mode 100644 index 4f22126..0000000 --- a/test/fixtures/nullary.js +++ /dev/null @@ -1,36 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Nullary callback. -* -* @private -* @returns {number} value -*/ -function nullary() { - return 3.0; -} - - -// EXPORTS // - -module.exports = nullary; diff --git a/test/fixtures/quaternary.js b/test/fixtures/quaternary.js deleted file mode 100644 index 548437b..0000000 --- a/test/fixtures/quaternary.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Quaternary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @param {number} w - input value -* @returns {number} sum -*/ -function quaternary( x, y, z, w ) { - return x + y + z + w; -} - - -// EXPORTS // - -module.exports = quaternary; diff --git a/test/fixtures/quinary.js b/test/fixtures/quinary.js deleted file mode 100644 index 36068de..0000000 --- a/test/fixtures/quinary.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Quinary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @param {number} w - input value -* @param {number} u - input value -* @returns {number} sum -*/ -function quinary( x, y, z, w, u ) { - return x + y + z + w + u; -} - - -// EXPORTS // - -module.exports = quinary; diff --git a/test/fixtures/sum.js b/test/fixtures/sum.js deleted file mode 100644 index efdbb1b..0000000 --- a/test/fixtures/sum.js +++ /dev/null @@ -1,98 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* Return an ndarray function which computes the sum across one or more ndarrays. -* -* @private -* @param {Object} ctx - context -* @param {number} ctx.sum - initial sum -* @returns {Function} ndarray function -*/ -function wrapper( ctx ) { - return ndarrayFcn; - - /** - * ndarray function. - * - * @private - * @param {Array} arrays - ndarrays - * @param {Function} [fcn] - callback - */ - function ndarrayFcn( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var f; - var i; - var j; - - if ( arguments.length > 1 ) { - f = fcn; - } - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - if ( f ) { - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - args[ j ] = arrays[ j ].get.apply( arrays[ j ], sub ); - } - ctx.sum += f.apply( null, args ); - } - } else { - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - ctx.sum += arrays[ j ].get.apply( arrays[ j ], sub ); - } - } - } - } -} - - -// EXPORTS // - -module.exports = wrapper; diff --git a/test/fixtures/ternary.js b/test/fixtures/ternary.js deleted file mode 100644 index 0595d5f..0000000 --- a/test/fixtures/ternary.js +++ /dev/null @@ -1,39 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Ternary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @returns {number} sum -*/ -function ternary( x, y, z ) { - return x + y + z; -} - - -// EXPORTS // - -module.exports = ternary; diff --git a/test/test.js b/test/test.js deleted file mode 100644 index d6c2c8e..0000000 --- a/test/test.js +++ /dev/null @@ -1,363 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var dispatch = require( './../lib' ); - - -// FIXTURES // - -var fill = require( './fixtures/fill.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dispatch, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided either a function or an array of functions as a first argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( value, types, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided an array-like object as a second argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var data = [ abs ]; - dispatch( unary, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided either an array-like object or `null` as a third argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - dispatch( unary, types, value, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a positive integer for a fourth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 0, - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, value, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a nonnegative integer for a fifth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, 2, value, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a nonnegative integer for a sixth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, 2, 1, value ); - }; - } -}); - -tape( 'the function throws an error if the number of types is incompatible with the number of types indicated by other function parameters (function array)', function test( t ) { - var values; - var i; - - values = [ - [ 'float64' ], - [ 'float64', 'float64', 'float64' ], - [ 'float64', 'float32', 'float32' ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var fcns = [ unary, unary, unary ]; - var data = [ abs, abs, abs ]; - dispatch( fcns, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the number of types is incompatible with the number of types indicated by other function parameters (function argument)', function test( t ) { - var values; - var i; - - values = [ - [ 'float64' ], - [ 'float64', 'float64', 'float64' ], - [ 'float64', 'float32', 'float32' ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var data = [ abs, abs, abs ]; - dispatch( unary, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the length of `data` argument does not match the number of ndarray functions', function test( t ) { - var values; - var i; - - values = [ - [], - [ abs, abs ], - [ abs, abs, abs ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var fcns = [ unary ]; - dispatch( fcns, types, value, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the fourth argument is incompatible with the number of input and output ndarrays', function test( t ) { - var values; - var i; - - values = [ - 0, - 1, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, value, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the number of specified input and output ndarrays is zero', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var types = [ 'float64' ]; - dispatch( fill( 3 ), types, null, 1, 0, 0 ); - } -}); - -tape( 'the function returns an ndarray function interface', function test( t ) { - var types; - var data; - var f; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - f = dispatch( unary, types, data, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( [ unary ], types, data, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( fill( 3 ), types, null, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( [ fill( 3 ) ], types, null, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.two_arrays.js b/test/test.two_arrays.js deleted file mode 100644 index 16eb61b..0000000 --- a/test/test.two_arrays.js +++ /dev/null @@ -1,814 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var dtype = require( '@stdlib/ndarray-base-buffer-dtype' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var dispatch = require( './../lib' ); - - -// FIXTURES // - -var forEach = require( './fixtures/foreach.js' ); -var map1N = require( './fixtures/map1n.js' ); -var fill = require( './fixtures/fill.js' ); -var sum = require( './fixtures/sum.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dispatch, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns a function which throws an error if not provided an ndarray for the first argument', function test( t ) { - var values; - var types; - var data; - var fcn; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var ybuf = new Float64Array( 10 ); - var y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - fcn( value, y ); - }; - } -}); - -tape( 'the function returns a function which throws an error if not provided an ndarray for the second argument', function test( t ) { - var values; - var types; - var data; - var fcn; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var xbuf = new Float64Array( 10 ); - var x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - fcn( x, value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided insufficient arguments', function test( t ) { - var values; - var types; - var data; - var xbuf; - var f; - var x; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - f = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - values = [ - [], - [ x ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( wrapper( values[i] ), Error, 'throws an error when provided ' + values[ i ].length + ' arguments' ); - } - t.end(); - - function wrapper( args ) { - return function fcn() { - f.apply( null, args ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided too many arguments', function test( t ) { - var values; - var types; - var data; - var xbuf; - var ybuf; - var f; - var x; - var y; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - f = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - values = [ - [ x, y, y ], - [ x, y, y, y ], - [ x, y, y, y, y ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( wrapper( values[i] ), Error, 'throws an error when provided ' + values[ i ].length + ' arguments' ); - } - t.end(); - - function wrapper( args ) { - return function fcn() { - f.apply( null, args ); - }; - } -}); - -tape( 'the function returns a function which throws an error if unable to resolve a ndarray function supporting the provided array argument data types', function test( t ) { - var values; - var types; - var data; - var xbuf; - var fcn; - var x; - var i; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ abs, abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 4 ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - values = [ - new Uint8Array( 4 ), - new Int32Array( 4 ), - [ 0, 0, 0, 0 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided an array having data type: ' + dtype( values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var y = ndarray( dtype( value ), value, [ value.length ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - }; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; no data; only input arrays)', function test( t ) { - var types; - var xbuf; - var ybuf; - var ctx; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - ctx = { - 'sum': 0 - }; - fcn = dispatch( sum( ctx ), types, null, 2, 2, 0 ); - - ctx.sum = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 20.0, 'returns expected value' ); - - ctx.sum = 5; - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 25.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; no data; only output arrays)', function test( t ) { - var expected; - var types; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - fcn = dispatch( fill( 3.0 ), types, null, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( xbuf.length ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; no data; only input arrays)', function test( t ) { - var types; - var fcns; - var xbuf; - var ybuf; - var fcn; - var ctx; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - ctx = { - 'sum': 0 - }; - fcns = [ - sum( ctx ), - sum( ctx ) - ]; - fcn = dispatch( fcns, types, null, 2, 2, 0 ); - - ctx.sum = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 20.0, 'returns expected value' ); - - ctx.sum = 5; - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 25.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; no data; only output arrays)', function test( t ) { - var expected; - var types; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - fcns = [ - fill( 3.0 ), - fill( 4.0 ) - ]; - fcn = dispatch( fcns, types, null, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( xbuf.length ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; only input arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var cnt; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - clbk, - clbk - ]; - - fcn = dispatch( forEach, types, data, 2, 2, 0 ); - cnt = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 4, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 8, 'returns expected value' ); - - t.end(); - - function clbk() { - cnt += 1; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; only output arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - three, - four - ]; - - fcn = dispatch( map1N, types, data, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); - - function three() { - return 3.0; - } - - function four() { - return 4.0; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; input and output arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - abs, - abs - ]; - - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; only input arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var cnt; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - clbk, - clbk - ]; - fcns = [ - forEach, - forEach - ]; - fcn = dispatch( fcns, types, data, 2, 2, 0 ); - cnt = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 4, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 8, 'returns expected value' ); - - t.end(); - - function clbk() { - cnt += 1; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; only output arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - three, - four - ]; - fcns = [ - map1N, - map1N - ]; - fcn = dispatch( fcns, types, data, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); - - function three() { - return 3.0; - } - - function four() { - return 4.0; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; input and output arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - abs, - abs - ]; - fcns = [ - unary, - unary - ]; - fcn = dispatch( fcns, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which returns one or more output arrays, if one or more output arrays is specified, and otherwise returns `undefined`', function test( t ) { - var types; - var data; - var xbuf; - var ybuf; - var out; - var ctx; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - // No output arrays... - ctx = { - 'sum': 0 - }; - fcn = dispatch( sum( ctx ), types, null, 2, 2, 0 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, void 0, 'returns expected value' ); - - // One output array... - data = [ - abs, - abs - ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, y, 'returns expected value' ); - - fcn = dispatch( fill( 3.0 ), types, null, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, y, 'returns expected value' ); - - // Two output arrays... - fcn = dispatch( fill( 3.0 ), types, null, 2, 0, 2 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out.length, 2, 'returns expected value' ); - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - - t.end(); -});