diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index dab5d2a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,180 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index bc2ef1f..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-02-24T00:44:23.139Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 4014d9a..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/filter-map) 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 008fb29..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/filter-map) 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 3091c7b..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: '26 2 * * 2' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 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 + + ```
@@ -299,7 +290,7 @@ console.log( ndarray2array( y ) ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -362,21 +353,21 @@ Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-filter-map/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm -[@stdlib/ndarray/orders]: https://github.com/stdlib-js/ndarray-orders +[@stdlib/ndarray/orders]: https://github.com/stdlib-js/ndarray-orders/tree/esm -[@stdlib/ndarray/filter]: https://github.com/stdlib-js/ndarray-filter +[@stdlib/ndarray/filter]: https://github.com/stdlib-js/ndarray-filter/tree/esm -[@stdlib/ndarray/map]: https://github.com/stdlib-js/ndarray-map +[@stdlib/ndarray/map]: https://github.com/stdlib-js/ndarray-map/tree/esm -[@stdlib/ndarray/reject]: https://github.com/stdlib-js/ndarray-reject +[@stdlib/ndarray/reject]: https://github.com/stdlib-js/ndarray-reject/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.1d.js b/benchmark/benchmark.1d.js deleted file mode 100644 index 14bad46..0000000 --- a/benchmark/benchmark.1d.js +++ /dev/null @@ -1,152 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var discreteUniform = require( '@stdlib/random-array-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var pkg = require( './../package.json' ).name; -var filterMap = require( './../lib' ); - - -// VARIABLES // - -var xtypes = [ 'generic' ]; -var ytypes = [ 'float64' ]; -var orders = [ 'row-major', 'column-major' ]; - - -// FUNCTIONS // - -/** -* Callback function. -* -* @private -* @param {number} value - array element -* @param {NonNegativeIntegerArray} indices - element indices -* @param {ndarray} arr - input array -* @returns {(number|void)} result -*/ -function fcn( value ) { - if ( value > 0.0 ) { - return value * 10.0; - } -} - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @param {NonNegativeIntegerArray} shape - ndarray shape -* @param {string} xtype - input ndarray data type -* @param {string} ytype - output ndarray data type -* @param {string} order - ndarray memory layout -* @returns {Function} benchmark function -*/ -function createBenchmark( len, shape, xtype, ytype, order ) { - var strides; - var opts; - var xbuf; - var x; - - xbuf = discreteUniform( len, -100, 100, { - 'dtype': xtype - }); - strides = shape2strides( shape, order ); - x = ndarray( xtype, xbuf, shape, strides, 0, order ); - opts = { - 'dtype': ytype - }; - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var y; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - y = filterMap( x, opts, fcn ); - if ( isnan( y.data[ i%y.length ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isndarrayLike( y ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var ord; - var sh; - var t1; - var t2; - var f; - var i; - var j; - var k; - - min = 1; // 10^min - max = 6; // 10^max - - for ( k = 0; k < orders.length; k++ ) { - ord = orders[ k ]; - for ( j = 0; j < xtypes.length; j++ ) { - t1 = xtypes[ j ]; - t2 = ytypes[ j ]; - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - sh = [ len ]; - f = createBenchmark( len, sh, t1, t2, ord ); - bench( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+ord+',yorder='+ord+',xtype='+t1+',ytype='+t2, f ); - } - } - } -} - -main(); diff --git a/benchmark/benchmark.2d.js b/benchmark/benchmark.2d.js deleted file mode 100644 index 93dac49..0000000 --- a/benchmark/benchmark.2d.js +++ /dev/null @@ -1,163 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var sqrt = require( '@stdlib/math-base-special-sqrt' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var discreteUniform = require( '@stdlib/random-array-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var pkg = require( './../package.json' ).name; -var filterMap = require( './../lib' ); - - -// VARIABLES // - -var xtypes = [ 'generic' ]; -var ytypes = [ 'float64' ]; -var orders = [ 'row-major', 'column-major' ]; - - -// FUNCTIONS // - -/** -* Callback function. -* -* @private -* @param {number} value - array element -* @param {NonNegativeIntegerArray} indices - element indices -* @param {ndarray} arr - input array -* @returns {(number|void)} result -*/ -function fcn( value ) { - if ( value > 0.0 ) { - return value * 10.0; - } -} - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - ndarray length -* @param {NonNegativeIntegerArray} shape - ndarray shape -* @param {string} xtype - input ndarray data type -* @param {string} ytype - output ndarray data type -* @param {string} order - ndarray memory layout -* @returns {Function} benchmark function -*/ -function createBenchmark( len, shape, xtype, ytype, order ) { - var strides; - var opts; - var xbuf; - var x; - var y; - - xbuf = discreteUniform( len, -100, 100, { - 'dtype': xtype - }); - strides = shape2strides( shape, order ); - x = ndarray( xtype, xbuf, shape, strides, 0, order ); - opts = { - 'dtype': ytype - }; - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - y = filterMap( x, opts, fcn ); - if ( isnan( y.data[ i%y.length ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isndarrayLike( y ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var ord; - var sh; - var t1; - var t2; - var f; - var i; - var j; - var k; - - min = 1; // 10^min - max = 6; // 10^max - - for ( k = 0; k < orders.length; k++ ) { - ord = orders[ k ]; - for ( j = 0; j < xtypes.length; j++ ) { - t1 = xtypes[ j ]; - t2 = ytypes[ j ]; - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - sh = [ len/2, 2 ]; - f = createBenchmark( len, sh, t1, t2, ord ); - bench( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+ord+',yorder='+ord+',xtype='+t1+',ytype='+t2, f ); - - sh = [ 2, len/2 ]; - f = createBenchmark( len, sh, t1, t2, ord ); - bench( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+ord+',yorder='+ord+',xtype='+t1+',ytype='+t2, f ); - - len = floor( sqrt( len ) ); - sh = [ len, len ]; - len *= len; - f = createBenchmark( len, sh, t1, t2, ord ); - bench( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+ord+',yorder='+ord+',xtype='+t1+',ytype='+t2, f ); - } - } - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index b6510e4..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/filter-map" -%% click B href "https://github.com/stdlib-js/ndarray-filter-map/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-filter-map/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-filter-map/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-filter-map/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-filter-map/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/filter-map -[production-url]: https://github.com/stdlib-js/ndarray-filter-map/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-filter-map/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-filter-map/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-filter-map/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-filter-map/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-filter-map/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-filter-map/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 9cf47c4..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import filterMap from '../docs/types/index'; -export = filterMap; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 182374c..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var z=function(r,a){return function(){return a||r((a={exports:{}}).exports,a),a.exports}};var j=z(function(H,E){"use strict";var V=require("@stdlib/assert-is-plain-object"),b=require("@stdlib/assert-is-function"),C=require("@stdlib/assert-is-ndarray-like"),F=require("@stdlib/ndarray-base-assert-is-order"),O=require("@stdlib/assert-has-own-property"),P=require("@stdlib/ndarray-base-buffer-ctors"),D=require("@stdlib/array-base-zeros"),I=require("@stdlib/ndarray-shape"),T=require("@stdlib/ndarray-dtype"),L=require("@stdlib/ndarray-order"),M=require("@stdlib/ndarray-base-numel"),N=require("@stdlib/ndarray-base-next-cartesian-index").assign,S=require("@stdlib/blas-base-gcopy"),v=require("@stdlib/string-format");function A(r,a,p,k){var g,c,t,i,e,f,m,n,h,o,y,s,l,u,w,q,d;if(!C(r))throw new TypeError(v("invalid argument. First argument must be an ndarray-like object. Value: `%s`.",r));if(arguments.length<3?i=a:arguments.length===3?b(a)?(i=a,m=p):(g=!0,e=a,i=p):(g=!0,e=a,i=p,m=k),!b(i))throw new TypeError(v("invalid argument. Callback argument must be a function. Value: `%s`.",i));if(g){if(!V(e))throw new TypeError(v("invalid argument. Options argument must be an object. Value: `%s`.",e));if(O(e,"dtype")?s=e.dtype:s=T(r),O(e,"order")){if(!F(e.order))throw new TypeError(v("invalid option. `%s` option must be a recognized order. Option: `%s`.","order",e.order));n=e.order}}else s=T(r);if(f=P(s),f===null)throw new TypeError(v("invalid option. `%s` option must be a recognized data type. Option: `%s`.","dtype",e.dtype));for(n===void 0&&(n=L(r)),l=I(r),u=M(l),c=l.length,n==="row-major"?h=c-1:h=0,o=D(c),t={length:0},d=0;d0&&(o=N(l,n,o,h,o)),q=i.call(m,r.get.apply(r,o),o.slice(),r),q!==void 0&&(t[t.length]=q,t.length+=1);return u=t.length,y=new f(u),S(u,t,1,y,1),w=new r.constructor(s,y,[u],[1],0,n),w}E.exports=A});var B=j();module.exports=B; -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index b7fbb2c..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isOrder = require( '@stdlib/ndarray-base-assert-is-order' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar ctors = require( '@stdlib/ndarray-base-buffer-ctors' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar getDType = require( '@stdlib/ndarray-dtype' );\nvar getOrder = require( '@stdlib/ndarray-order' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign;\nvar gcopy = require( '@stdlib/blas-base-gcopy' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Filters and maps elements in an input ndarray to elements in a new output ndarray according to a callback function.\n*\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {string} [options.dtype] - output array data type\n* @param {string} [options.order] - index iteration order\n* @param {Callback} fcn - callback function\n* @param {*} [thisArg] - callback execution context\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} callback argument must be a function\n* @throws {TypeError} options argument must be an object\n* @returns {ndarray} output ndarray\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n*\n* function fcn( v ) {\n* if ( v > 5.0 ) {\n* return v * 10.0;\n* }\n* }\n*\n* var buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] );\n* var shape = [ 2, 3 ];\n* var strides = [ 6, 1 ];\n* var offset = 1;\n*\n* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var y = filterMap( x, fcn );\n* // returns \n*\n* var arr = ndarray2array( y );\n* // returns [ 80.0, 90.0, 100.0 ]\n*/\nfunction filterMap( x, options, fcn, thisArg ) {\n\tvar hasOpts;\n\tvar ndims;\n\tvar cache;\n\tvar clbk;\n\tvar opts;\n\tvar ctor;\n\tvar ctx;\n\tvar ord;\n\tvar dim;\n\tvar idx;\n\tvar buf;\n\tvar dt;\n\tvar sh;\n\tvar N;\n\tvar y;\n\tvar v;\n\tvar i;\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray-like object. Value: `%s`.', x ) );\n\t}\n\tif ( arguments.length < 3 ) {\n\t\tclbk = options;\n\t} else if ( arguments.length === 3 ) {\n\t\tif ( isFunction( options ) ) {\n\t\t\tclbk = options;\n\t\t\tctx = fcn;\n\t\t} else {\n\t\t\thasOpts = true;\n\t\t\topts = options;\n\t\t\tclbk = fcn;\n\t\t}\n\t} else {\n\t\thasOpts = true;\n\t\topts = options;\n\t\tclbk = fcn;\n\t\tctx = thisArg;\n\t}\n\tif ( !isFunction( clbk ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Callback argument must be a function. Value: `%s`.', clbk ) );\n\t}\n\tif ( hasOpts ) {\n\t\tif ( !isPlainObject( opts ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) );\n\t\t}\n\t\tif ( hasOwnProp( opts, 'dtype' ) ) {\n\t\t\tdt = opts.dtype;\n\t\t} else {\n\t\t\tdt = getDType( x );\n\t\t}\n\t\tif ( hasOwnProp( opts, 'order' ) ) {\n\t\t\tif ( !isOrder( opts.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', opts.order ) );\n\t\t\t}\n\t\t\tord = opts.order;\n\t\t}\n\t} else {\n\t\tdt = getDType( x );\n\t}\n\t// Resolve an output array buffer constructor:\n\tctor = ctors( dt );\n\tif ( ctor === null ) {\n\t\t// The only way we should get here is if the user provided an unsupported data type, as `getDType` should error if the input array has an unrecognized/unsupported data type...\n\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a recognized data type. Option: `%s`.', 'dtype', opts.dtype ) );\n\t}\n\t// Resolve the iteration order:\n\tif ( ord === void 0 ) {\n\t\tord = getOrder( x );\n\t}\n\t// Resolve the input array shape:\n\tsh = getShape( x );\n\n\t// Compute the number of array elements:\n\tN = numel( sh );\n\n\t// Retrieve the number of dimensions:\n\tndims = sh.length;\n\n\t// Resolve the dimension in which indices should iterate fastest:\n\tif ( ord === 'row-major' ) {\n\t\tdim = ndims - 1;\n\t} else { // ord === 'column-major'\n\t\tdim = 0;\n\t}\n\t// Initialize an index array workspace:\n\tidx = zeros( ndims );\n\n\t// Initialize a value cache for those elements which pass a callback function (note: unfortunately, we use an associative array here, as no other good options. If we use a \"generic\" array, we are limited to 2^32-1 elements. If we allocate, say, a Float64Array buffer for storing indices, we risk materializing lazily-materialized input ndarray values again (e.g., lazy accessor ndarray), which could be expensive. If we allocate a workspace buffer of equal size to the input ndarray to store materialized values, we'd then need to perform another copy in order to shrink the buffer, as, otherwise, could be holding on to significantly more memory than needed for the returned ndarray. There are likely other options, but all involve complexity, so the simplest option is used here.):\n\tcache = {\n\t\t'length': 0\n\t};\n\n\t// Filter and map elements according to a callback function...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tif ( i > 0 ) {\n\t\t\tidx = nextCartesianIndex( sh, ord, idx, dim, idx );\n\t\t}\n\t\tv = clbk.call( ctx, x.get.apply( x, idx ), idx.slice(), x );\n\t\tif ( v !== void 0 ) {\n\t\t\tcache[ cache.length ] = v;\n\t\t\tcache.length += 1;\n\t\t}\n\t}\n\t// Retrieve the number of cached elements:\n\tN = cache.length;\n\n\t// Allocate an output array buffer:\n\tbuf = new ctor( N );\n\n\t// Copy cached elements to the output array buffer:\n\tgcopy( N, cache, 1, buf, 1 );\n\n\t// Create an output ndarray:\n\ty = new x.constructor( dt, buf, [ N ], [ 1 ], 0, ord );\n\n\treturn y;\n}\n\n\n// EXPORTS //\n\nmodule.exports = filterMap;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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* Filter and map elements in an input ndarray to elements in a new output ndarray according to a callback function.\n*\n* @module @stdlib/ndarray-filter-map\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var filterMap = require( '@stdlib/ndarray-filter-map' );\n*\n* function fcn( v ) {\n* if ( v > 5.0 ) {\n* return v * 10.0;\n* }\n* }\n*\n* var buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] );\n* var shape = [ 2, 3 ];\n* var strides = [ 6, 1 ];\n* var offset = 1;\n*\n* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var y = filterMap( x, fcn );\n* // returns \n*\n* var arr = ndarray2array( y );\n* // returns [ 80.0, 90.0, 100.0 ]\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,4BAA6B,EACnDC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAU,QAAS,sCAAuC,EAC1DC,EAAa,QAAS,iCAAkC,EACxDC,EAAQ,QAAS,mCAAoC,EACrDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAqB,QAAS,2CAA4C,EAAE,OAC5EC,EAAQ,QAAS,yBAA0B,EAC3CC,EAAS,QAAS,uBAAwB,EA4C9C,SAASC,EAAWC,EAAGC,EAASC,EAAKC,EAAU,CAC9C,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,GAAK,CAACjC,EAAea,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,gFAAiFE,CAAE,CAAE,EAmBnH,GAjBK,UAAU,OAAS,EACvBO,EAAON,EACI,UAAU,SAAW,EAC3Bf,EAAYe,CAAQ,GACxBM,EAAON,EACPS,EAAMR,IAENE,EAAU,GACVI,EAAOP,EACPM,EAAOL,IAGRE,EAAU,GACVI,EAAOP,EACPM,EAAOL,EACPQ,EAAMP,GAEF,CAACjB,EAAYqB,CAAK,EACtB,MAAM,IAAI,UAAWT,EAAQ,uEAAwES,CAAK,CAAE,EAE7G,GAAKH,EAAU,CACd,GAAK,CAACnB,EAAeuB,CAAK,EACzB,MAAM,IAAI,UAAWV,EAAQ,qEAAsEU,CAAK,CAAE,EAO3G,GALKnB,EAAYmB,EAAM,OAAQ,EAC9BO,EAAKP,EAAK,MAEVO,EAAKtB,EAAUO,CAAE,EAEbX,EAAYmB,EAAM,OAAQ,EAAI,CAClC,GAAK,CAACpB,EAASoB,EAAK,KAAM,EACzB,MAAM,IAAI,UAAWV,EAAQ,wEAAyE,QAASU,EAAK,KAAM,CAAE,EAE7HG,EAAMH,EAAK,KACZ,CACD,MACCO,EAAKtB,EAAUO,CAAE,EAIlB,GADAS,EAAOnB,EAAOyB,CAAG,EACZN,IAAS,KAEb,MAAM,IAAI,UAAWX,EAAQ,4EAA6E,QAASU,EAAK,KAAM,CAAE,EA8BjI,IA3BKG,IAAQ,SACZA,EAAMjB,EAAUM,CAAE,GAGnBgB,EAAKxB,EAAUQ,CAAE,EAGjBiB,EAAItB,EAAOqB,CAAG,EAGdX,EAAQW,EAAG,OAGNL,IAAQ,YACZC,EAAMP,EAAQ,EAEdO,EAAM,EAGPC,EAAMtB,EAAOc,CAAM,EAGnBC,EAAQ,CACP,OAAU,CACX,EAGMc,EAAI,EAAGA,EAAIH,EAAGG,IACdA,EAAI,IACRP,EAAMjB,EAAoBoB,EAAIL,EAAKE,EAAKD,EAAKC,CAAI,GAElDM,EAAIZ,EAAK,KAAMG,EAAKV,EAAE,IAAI,MAAOA,EAAGa,CAAI,EAAGA,EAAI,MAAM,EAAGb,CAAE,EACrDmB,IAAM,SACVb,EAAOA,EAAM,MAAO,EAAIa,EACxBb,EAAM,QAAU,GAIlB,OAAAW,EAAIX,EAAM,OAGVQ,EAAM,IAAIL,EAAMQ,CAAE,EAGlBpB,EAAOoB,EAAGX,EAAO,EAAGQ,EAAK,CAAE,EAG3BI,EAAI,IAAIlB,EAAE,YAAae,EAAID,EAAK,CAAEG,CAAE,EAAG,CAAE,CAAE,EAAG,EAAGN,CAAI,EAE9CO,CACR,CAKAlC,EAAO,QAAUe,IClJjB,IAAIsB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isPlainObject", "isFunction", "isndarrayLike", "isOrder", "hasOwnProp", "ctors", "zeros", "getShape", "getDType", "getOrder", "numel", "nextCartesianIndex", "gcopy", "format", "filterMap", "x", "options", "fcn", "thisArg", "hasOpts", "ndims", "cache", "clbk", "opts", "ctor", "ctx", "ord", "dim", "idx", "buf", "dt", "sh", "N", "y", "v", "i", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index bbe0ad9..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,56 +0,0 @@ - -{{alias}}( x[, options], fcn[, thisArg] ) - Filters and maps elements in an input ndarray to elements in a new output - ndarray according to a callback function. - - The callback function is provided the following arguments: - - - value: current array element. - - indices: current array element indices. - - arr: the input ndarray. - - If a provided callback function returns `undefined`, the function skips the - respective ndarray element. If the callback function returns a value other - than `undefined`, the function stores the callback's return value in the - output ndarray. - - Parameters - ---------- - x: ndarray - Input ndarray. - - options: Object (optional) - Function options. - - options.dtype: string (optional) - Output ndarray data type. Overrides using the input array's inferred - data type. - - options.order: string (optional) - Index iteration order. By default, the function iterates over elements - according to the layout order of the provided array. Accordingly, for - row-major input arrays, the last dimension indices increment fastest. - For column-major input arrays, the first dimension indices increment - fastest. To override the inferred order and ensure that indices - increment in a specific manner, regardless of the input array's layout - order, explicitly set the iteration order. Note, however, that iterating - according to an order which does not match that of the input array may, - in some circumstances, result in performance degradation due to cache - misses. Must be either 'row-major' or 'column-major'. - - fcn: Function - Callback function. - - thisArg: any (optional) - Callback function execution context. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ); - > function f( v ) { if ( v > 2.0 ) { return v * 10.0; } }; - > var y = {{alias}}( x, f ); - > {{alias:@stdlib/ndarray/to-array}}( y ) - [ 30.0, 40.0 ] - - See Also - -------- diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 42deef8..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,226 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/// - -import { ComplexLike } from '@stdlib/types/complex'; -import empty = require( '@stdlib/ndarray-base-empty' ); -import zeros = require( '@stdlib/ndarray-base-zeros' ); -import filterMap = require( './index' ); - -/** -* Callback function. -* -* @param x - input value -* @returns result -*/ -function fcn( x: any ): any { - return x; -} - -/** -* Callback function. -* -* @param x - input value -* @returns result -*/ -function identity1( x: number ): number { - return x; -} - -/** -* Callback function. -* -* @param x - input value -* @returns result -*/ -function identity2( x: boolean ): boolean { - return x; -} - -/** -* Callback function. -* -* @param x - input value -* @returns result -*/ -function identity3( x: ComplexLike ): ComplexLike { - return x; -} - -// The function returns an ndarray... -{ - const sh = [ 2, 2 ]; - const ord = 'row-major'; - - filterMap( zeros( 'float64', sh, ord ), identity1 ); // $ExpectType float64ndarray - filterMap( zeros( 'float64', sh, ord ), identity1, {} ); // $ExpectType float64ndarray - filterMap( zeros( 'float32', sh, ord ), identity1 ); // $ExpectType float32ndarray - filterMap( zeros( 'float32', sh, ord ), identity1, {} ); // $ExpectType float32ndarray - filterMap( zeros( 'complex64', sh, ord ), identity3 ); // $ExpectType complex64ndarray - filterMap( zeros( 'complex64', sh, ord ), identity3, {} ); // $ExpectType complex64ndarray - filterMap( zeros( 'complex128', sh, ord ), identity3 ); // $ExpectType complex128ndarray - filterMap( zeros( 'complex128', sh, ord ), identity3, {} ); // $ExpectType complex128ndarray - filterMap( zeros( 'int32', sh, ord ), identity1 ); // $ExpectType int32ndarray - filterMap( zeros( 'int32', sh, ord ), identity1, {} ); // $ExpectType int32ndarray - filterMap( zeros( 'int16', sh, ord ), identity1 ); // $ExpectType int16ndarray - filterMap( zeros( 'int16', sh, ord ), identity1, {} ); // $ExpectType int16ndarray - filterMap( zeros( 'int8', sh, ord ), identity1 ); // $ExpectType int8ndarray - filterMap( zeros( 'int8', sh, ord ), identity1, {} ); // $ExpectType int8ndarray - filterMap( zeros( 'uint32', sh, ord ), identity1 ); // $ExpectType uint32ndarray - filterMap( zeros( 'uint32', sh, ord ), identity1, {} ); // $ExpectType uint32ndarray - filterMap( zeros( 'uint16', sh, ord ), identity1 ); // $ExpectType uint16ndarray - filterMap( zeros( 'uint16', sh, ord ), identity1, {} ); // $ExpectType uint16ndarray - filterMap( zeros( 'uint8', sh, ord ), identity1 ); // $ExpectType uint8ndarray - filterMap( zeros( 'uint8', sh, ord ), identity1, {} ); // $ExpectType uint8ndarray - filterMap( zeros( 'uint8c', sh, ord ), identity1 ); // $ExpectType uint8cndarray - filterMap( zeros( 'uint8c', sh, ord ), identity1, {} ); // $ExpectType uint8cndarray - filterMap( empty( 'bool', sh, ord ), identity2 ); // $ExpectType boolndarray - filterMap( empty( 'bool', sh, ord ), identity2, {} ); // $ExpectType boolndarray - filterMap( zeros( 'generic', sh, ord ), identity1 ); // $ExpectType genericndarray - filterMap( zeros( 'generic', sh, ord ), identity1, {} ); // $ExpectType genericndarray - - - filterMap( zeros( 'generic', sh, ord ), { 'dtype': 'float64' }, fcn ); // $ExpectType float64ndarray - filterMap( zeros( 'generic', sh, ord ), { 'dtype': 'float64' }, fcn, {} ); // $ExpectType float64ndarray - filterMap( zeros( 'generic', sh, ord ), { 'dtype': 'float32' }, fcn ); // $ExpectType float32ndarray - filterMap( zeros( 'generic', sh, ord ), { 'dtype': 'float32' }, fcn, {} ); // $ExpectType float32ndarray - filterMap( zeros( 'generic', sh, ord ), { 'dtype': 'complex64' }, fcn ); // $ExpectType complex64ndarray - filterMap( zeros( 'generic', sh, ord ), { 'dtype': 'complex64' }, fcn, {} ); // $ExpectType complex64ndarray - filterMap( zeros( 'generic', sh, ord ), { 'dtype': 'complex128' }, fcn ); // $ExpectType complex128ndarray - filterMap( zeros( 'generic', sh, ord ), { 'dtype': 'complex128' }, fcn, {} ); // $ExpectType complex128ndarray - filterMap( zeros( 'generic', sh, ord ), { 'dtype': 'int32' }, fcn ); // $ExpectType int32ndarray - filterMap( zeros( 'generic', sh, ord ), { 'dtype': 'int32' }, fcn, {} ); // $ExpectType int32ndarray - filterMap( zeros( 'generic', sh, ord ), { 'dtype': 'int16' }, fcn ); // $ExpectType int16ndarray - filterMap( zeros( 'generic', sh, ord ), { 'dtype': 'int16' }, fcn, {} ); // $ExpectType int16ndarray - filterMap( zeros( 'generic', sh, ord ), { 'dtype': 'int8' }, fcn ); // $ExpectType int8ndarray - filterMap( zeros( 'generic', sh, ord ), { 'dtype': 'int8' }, fcn, {} ); // $ExpectType int8ndarray - filterMap( zeros( 'generic', sh, ord ), { 'dtype': 'uint32' }, fcn ); // $ExpectType uint32ndarray - filterMap( zeros( 'generic', sh, ord ), { 'dtype': 'uint32' }, fcn, {} ); // $ExpectType uint32ndarray - filterMap( zeros( 'generic', sh, ord ), { 'dtype': 'uint16' }, fcn ); // $ExpectType uint16ndarray - filterMap( zeros( 'generic', sh, ord ), { 'dtype': 'uint16' }, fcn, {} ); // $ExpectType uint16ndarray - filterMap( zeros( 'generic', sh, ord ), { 'dtype': 'uint8' }, fcn ); // $ExpectType uint8ndarray - filterMap( zeros( 'generic', sh, ord ), { 'dtype': 'uint8' }, fcn, {} ); // $ExpectType uint8ndarray - filterMap( zeros( 'generic', sh, ord ), { 'dtype': 'uint8c' }, fcn ); // $ExpectType uint8cndarray - filterMap( zeros( 'generic', sh, ord ), { 'dtype': 'uint8c' }, fcn, {} ); // $ExpectType uint8cndarray - filterMap( zeros( 'generic', sh, ord ), { 'dtype': 'bool' }, fcn ); // $ExpectType boolndarray - filterMap( zeros( 'generic', sh, ord ), { 'dtype': 'bool' }, fcn, {} ); // $ExpectType boolndarray - filterMap( zeros( 'generic', sh, ord ), { 'dtype': 'generic' }, fcn ); // $ExpectType genericndarray - filterMap( zeros( 'generic', sh, ord ), { 'dtype': 'generic' }, fcn, {} ); // $ExpectType genericndarray - - - filterMap( zeros( 'float64', sh, ord ), { 'order': ord }, identity1 ); // $ExpectType float64ndarray - filterMap( zeros( 'float64', sh, ord ), { 'order': ord }, identity1, {} ); // $ExpectType float64ndarray - filterMap( zeros( 'float32', sh, ord ), { 'order': ord }, identity1 ); // $ExpectType float32ndarray - filterMap( zeros( 'float32', sh, ord ), { 'order': ord }, identity1, {} ); // $ExpectType float32ndarray - filterMap( zeros( 'complex64', sh, ord ), { 'order': ord }, identity3 ); // $ExpectType complex64ndarray - filterMap( zeros( 'complex64', sh, ord ), { 'order': ord }, identity3, {} ); // $ExpectType complex64ndarray - filterMap( zeros( 'complex128', sh, ord ), { 'order': ord }, identity3 ); // $ExpectType complex128ndarray - filterMap( zeros( 'complex128', sh, ord ), { 'order': ord }, identity3, {} ); // $ExpectType complex128ndarray - filterMap( zeros( 'int32', sh, ord ), { 'order': ord }, identity1 ); // $ExpectType int32ndarray - filterMap( zeros( 'int32', sh, ord ), { 'order': ord }, identity1, {} ); // $ExpectType int32ndarray - filterMap( zeros( 'int16', sh, ord ), { 'order': ord }, identity1 ); // $ExpectType int16ndarray - filterMap( zeros( 'int16', sh, ord ), { 'order': ord }, identity1, {} ); // $ExpectType int16ndarray - filterMap( zeros( 'int8', sh, ord ), { 'order': ord }, identity1 ); // $ExpectType int8ndarray - filterMap( zeros( 'int8', sh, ord ), { 'order': ord }, identity1, {} ); // $ExpectType int8ndarray - filterMap( zeros( 'uint32', sh, ord ), { 'order': ord }, identity1 ); // $ExpectType uint32ndarray - filterMap( zeros( 'uint32', sh, ord ), { 'order': ord }, identity1, {} ); // $ExpectType uint32ndarray - filterMap( zeros( 'uint16', sh, ord ), { 'order': ord }, identity1 ); // $ExpectType uint16ndarray - filterMap( zeros( 'uint16', sh, ord ), { 'order': ord }, identity1, {} ); // $ExpectType uint16ndarray - filterMap( zeros( 'uint8', sh, ord ), { 'order': ord }, identity1 ); // $ExpectType uint8ndarray - filterMap( zeros( 'uint8', sh, ord ), { 'order': ord }, identity1, {} ); // $ExpectType uint8ndarray - filterMap( zeros( 'uint8c', sh, ord ), { 'order': ord }, identity1 ); // $ExpectType uint8cndarray - filterMap( zeros( 'uint8c', sh, ord ), { 'order': ord }, identity1, {} ); // $ExpectType uint8cndarray - filterMap( empty( 'bool', sh, ord ), { 'order': ord }, identity2 ); // $ExpectType boolndarray - filterMap( empty( 'bool', sh, ord ), { 'order': ord }, identity2, {} ); // $ExpectType boolndarray - filterMap( zeros( 'generic', sh, ord ), { 'order': ord }, identity1 ); // $ExpectType genericndarray - filterMap( zeros( 'generic', sh, ord ), { 'order': ord }, identity1, {} ); // $ExpectType genericndarray - -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - filterMap( 5, fcn ); // $ExpectError - filterMap( true, fcn ); // $ExpectError - filterMap( false, fcn ); // $ExpectError - filterMap( null, fcn ); // $ExpectError - filterMap( undefined, fcn ); // $ExpectError - filterMap( {}, fcn ); // $ExpectError - filterMap( [ 1 ], fcn ); // $ExpectError - filterMap( ( x: number ): number => x, fcn ); // $ExpectError -} - -// The compiler throws an error if the function is provided a callback which is not a function... -{ - const x = zeros( 'generic', [ 2, 2 ], 'row-major' ); - - filterMap( x, '5' ); // $ExpectError - filterMap( x, true ); // $ExpectError - filterMap( x, false ); // $ExpectError - filterMap( x, null ); // $ExpectError - filterMap( x, undefined ); // $ExpectError - filterMap( x, {} ); // $ExpectError - filterMap( x, [ 1 ] ); // $ExpectError -} - -// The compiler throws an error if the function is provided an options argument which is not an object... -{ - const x = zeros( 'generic', [ 2, 2 ], 'row-major' ); - - filterMap( x, '10', fcn, {} ); // $ExpectError - filterMap( x, 10, fcn, {} ); // $ExpectError - filterMap( x, false, fcn, {} ); // $ExpectError - filterMap( x, true, fcn, {} ); // $ExpectError - filterMap( x, [], fcn, {} ); // $ExpectError - filterMap( x, ( x: number ): number => x, fcn, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `dtype` option which is not a valid data type... -{ - const x = zeros( 'generic', [ 2, 2 ], 'row-major' ); - - filterMap( x, { 'dtype': '10' }, fcn ); // $ExpectError - filterMap( x, { 'dtype': 10 }, fcn ); // $ExpectError - filterMap( x, { 'dtype': null }, fcn ); // $ExpectError - filterMap( x, { 'dtype': false }, fcn ); // $ExpectError - filterMap( x, { 'dtype': true }, fcn ); // $ExpectError - filterMap( x, { 'dtype': [] }, fcn ); // $ExpectError - filterMap( x, { 'dtype': {} }, fcn ); // $ExpectError - filterMap( x, { 'dtype': ( x: number ): number => x }, fcn ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `order` option which is not a valid order... -{ - const x = zeros( 'generic', [ 2, 2 ], 'row-major' ); - - filterMap( x, { 'order': '10' }, fcn ); // $ExpectError - filterMap( x, { 'order': 10 }, fcn ); // $ExpectError - filterMap( x, { 'order': null }, fcn ); // $ExpectError - filterMap( x, { 'order': false }, fcn ); // $ExpectError - filterMap( x, { 'order': true }, fcn ); // $ExpectError - filterMap( x, { 'order': [] }, fcn ); // $ExpectError - filterMap( x, { 'order': {} }, fcn ); // $ExpectError - filterMap( x, { 'order': ( x: number ): number => x }, fcn ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - filterMap(); // $ExpectError - filterMap( zeros( 'float64', [ 2, 2 ], 'row-major' ) ); // $ExpectError - filterMap( zeros( 'float64', [ 2, 2 ], 'row-major' ), {}, ( x: number ): number => x, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index f411e71..0000000 --- a/examples/index.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var discreteUniform = require( '@stdlib/random-array-discrete-uniform' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var array = require( '@stdlib/ndarray-array' ); -var filterMap = require( './../lib' ); - -function fcn( v ) { - if ( v > 0 ) { - return v * 100; - } -} - -var buffer = discreteUniform( 10, -100, 100, { - 'dtype': 'generic' -}); -var x = array( buffer, { - 'shape': [ 5, 2 ], - 'dtype': 'generic' -}); -console.log( ndarray2array( x ) ); - -var y = filterMap( x, fcn ); -console.log( ndarray2array( y ) ); 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 8242b5d..8f932f2 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// /* eslint-disable max-lines */ diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..a4a75e3 --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-ctors@v0.3.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-order@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/blas-base-gcopy@v0.2.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function v(v,f,b,c){var g,y,x,w,u,E,T,k,z,B,C,V,q,A,D,F;if(!s(v))throw new TypeError(a("null5t",v));if(arguments.length<3?w=f:3===arguments.length?e(f)?(w=f,T=b):(g=!0,u=f,w=b):(g=!0,u=f,w=b,T=c),!e(w))throw new TypeError(a("null2b",w));if(g){if(!r(u))throw new TypeError(a("null2V",u));if(V=n(u,"dtype")?u.dtype:m(v),n(u,"order")){if(!t(u.order))throw new TypeError(a("null5C","order",u.order));k=u.order}}else V=m(v);if(null===(E=d(V)))throw new TypeError(a("nullBf","dtype",u.dtype));for(void 0===k&&(k=l(v)),q=o(v),A=p(q),y=q.length,z="row-major"===k?y-1:0,B=i(y),x={length:0},F=0;F0&&(B=j(q,k,B,z,B)),void 0!==(D=w.call(T,v.get.apply(v,B),B.slice(),v))&&(x[x.length]=D,x.length+=1);return C=new E(A=x.length),h(A,x,1,C,1),new v.constructor(V,C,[A],[1],0,k)}export{v as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..b7c0518 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport isFunction from '@stdlib/assert-is-function';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport ctors from '@stdlib/ndarray-base-buffer-ctors';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport getDType from '@stdlib/ndarray-dtype';\nimport getOrder from '@stdlib/ndarray-order';\nimport numel from '@stdlib/ndarray-base-numel';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport gcopy from '@stdlib/blas-base-gcopy';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Filters and maps elements in an input ndarray to elements in a new output ndarray according to a callback function.\n*\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {string} [options.dtype] - output array data type\n* @param {string} [options.order] - index iteration order\n* @param {Callback} fcn - callback function\n* @param {*} [thisArg] - callback execution context\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} callback argument must be a function\n* @throws {TypeError} options argument must be an object\n* @returns {ndarray} output ndarray\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* function fcn( v ) {\n* if ( v > 5.0 ) {\n* return v * 10.0;\n* }\n* }\n*\n* var buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] );\n* var shape = [ 2, 3 ];\n* var strides = [ 6, 1 ];\n* var offset = 1;\n*\n* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var y = filterMap( x, fcn );\n* // returns \n*\n* var arr = ndarray2array( y );\n* // returns [ 80.0, 90.0, 100.0 ]\n*/\nfunction filterMap( x, options, fcn, thisArg ) {\n\tvar hasOpts;\n\tvar ndims;\n\tvar cache;\n\tvar clbk;\n\tvar opts;\n\tvar ctor;\n\tvar ctx;\n\tvar ord;\n\tvar dim;\n\tvar idx;\n\tvar buf;\n\tvar dt;\n\tvar sh;\n\tvar N;\n\tvar y;\n\tvar v;\n\tvar i;\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null5t', x ) );\n\t}\n\tif ( arguments.length < 3 ) {\n\t\tclbk = options;\n\t} else if ( arguments.length === 3 ) {\n\t\tif ( isFunction( options ) ) {\n\t\t\tclbk = options;\n\t\t\tctx = fcn;\n\t\t} else {\n\t\t\thasOpts = true;\n\t\t\topts = options;\n\t\t\tclbk = fcn;\n\t\t}\n\t} else {\n\t\thasOpts = true;\n\t\topts = options;\n\t\tclbk = fcn;\n\t\tctx = thisArg;\n\t}\n\tif ( !isFunction( clbk ) ) {\n\t\tthrow new TypeError( format( 'null2b', clbk ) );\n\t}\n\tif ( hasOpts ) {\n\t\tif ( !isPlainObject( opts ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', opts ) );\n\t\t}\n\t\tif ( hasOwnProp( opts, 'dtype' ) ) {\n\t\t\tdt = opts.dtype;\n\t\t} else {\n\t\t\tdt = getDType( x );\n\t\t}\n\t\tif ( hasOwnProp( opts, 'order' ) ) {\n\t\t\tif ( !isOrder( opts.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'null5C', 'order', opts.order ) );\n\t\t\t}\n\t\t\tord = opts.order;\n\t\t}\n\t} else {\n\t\tdt = getDType( x );\n\t}\n\t// Resolve an output array buffer constructor:\n\tctor = ctors( dt );\n\tif ( ctor === null ) {\n\t\t// The only way we should get here is if the user provided an unsupported data type, as `getDType` should error if the input array has an unrecognized/unsupported data type...\n\t\tthrow new TypeError( format( 'nullBf', 'dtype', opts.dtype ) );\n\t}\n\t// Resolve the iteration order:\n\tif ( ord === void 0 ) {\n\t\tord = getOrder( x );\n\t}\n\t// Resolve the input array shape:\n\tsh = getShape( x );\n\n\t// Compute the number of array elements:\n\tN = numel( sh );\n\n\t// Retrieve the number of dimensions:\n\tndims = sh.length;\n\n\t// Resolve the dimension in which indices should iterate fastest:\n\tif ( ord === 'row-major' ) {\n\t\tdim = ndims - 1;\n\t} else { // ord === 'column-major'\n\t\tdim = 0;\n\t}\n\t// Initialize an index array workspace:\n\tidx = zeros( ndims );\n\n\t// Initialize a value cache for those elements which pass a callback function (note: unfortunately, we use an associative array here, as no other good options. If we use a \"generic\" array, we are limited to 2^32-1 elements. If we allocate, say, a Float64Array buffer for storing indices, we risk materializing lazily-materialized input ndarray values again (e.g., lazy accessor ndarray), which could be expensive. If we allocate a workspace buffer of equal size to the input ndarray to store materialized values, we'd then need to perform another copy in order to shrink the buffer, as, otherwise, could be holding on to significantly more memory than needed for the returned ndarray. There are likely other options, but all involve complexity, so the simplest option is used here.):\n\tcache = {\n\t\t'length': 0\n\t};\n\n\t// Filter and map elements according to a callback function...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tif ( i > 0 ) {\n\t\t\tidx = nextCartesianIndex( sh, ord, idx, dim, idx );\n\t\t}\n\t\tv = clbk.call( ctx, x.get.apply( x, idx ), idx.slice(), x );\n\t\tif ( v !== void 0 ) {\n\t\t\tcache[ cache.length ] = v;\n\t\t\tcache.length += 1;\n\t\t}\n\t}\n\t// Retrieve the number of cached elements:\n\tN = cache.length;\n\n\t// Allocate an output array buffer:\n\tbuf = new ctor( N );\n\n\t// Copy cached elements to the output array buffer:\n\tgcopy( N, cache, 1, buf, 1 );\n\n\t// Create an output ndarray:\n\ty = new x.constructor( dt, buf, [ N ], [ 1 ], 0, ord );\n\n\treturn y;\n}\n\n\n// EXPORTS //\n\nexport default filterMap;\n"],"names":["filterMap","x","options","fcn","thisArg","hasOpts","ndims","cache","clbk","opts","ctor","ctx","ord","dim","idx","buf","dt","sh","N","v","i","isndarrayLike","TypeError","format","arguments","length","isFunction","isPlainObject","hasOwnProp","dtype","getDType","isOrder","order","ctors","getOrder","getShape","numel","zeros","nextCartesianIndex","call","get","apply","slice","gcopy","constructor"],"mappings":";;6zCA+EA,SAASA,EAAWC,EAAGC,EAASC,EAAKC,GACpC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEAC,EACAC,EACJ,IAAMC,EAAepB,GACpB,MAAM,IAAIqB,UAAWC,EAAQ,SAAUtB,IAmBxC,GAjBKuB,UAAUC,OAAS,EACvBjB,EAAON,EACyB,IAArBsB,UAAUC,OAChBC,EAAYxB,IAChBM,EAAON,EACPS,EAAMR,IAENE,GAAU,EACVI,EAAOP,EACPM,EAAOL,IAGRE,GAAU,EACVI,EAAOP,EACPM,EAAOL,EACPQ,EAAMP,IAEDsB,EAAYlB,GACjB,MAAM,IAAIc,UAAWC,EAAQ,SAAUf,IAExC,GAAKH,EAAU,CACd,IAAMsB,EAAelB,GACpB,MAAM,IAAIa,UAAWC,EAAQ,SAAUd,IAOxC,GAJCO,EADIY,EAAYnB,EAAM,SACjBA,EAAKoB,MAELC,EAAU7B,GAEX2B,EAAYnB,EAAM,SAAY,CAClC,IAAMsB,EAAStB,EAAKuB,OACnB,MAAM,IAAIV,UAAWC,EAAQ,SAAU,QAASd,EAAKuB,QAEtDpB,EAAMH,EAAKuB,KACX,CACH,MACEhB,EAAKc,EAAU7B,GAIhB,GAAc,QADdS,EAAOuB,EAAOjB,IAGb,MAAM,IAAIM,UAAWC,EAAQ,SAAU,QAASd,EAAKoB,QA8BtD,SA3Ba,IAARjB,IACJA,EAAMsB,EAAUjC,IAGjBgB,EAAKkB,EAAUlC,GAGfiB,EAAIkB,EAAOnB,GAGXX,EAAQW,EAAGQ,OAIVZ,EADY,cAARD,EACEN,EAAQ,EAER,EAGPQ,EAAMuB,EAAO/B,GAGbC,EAAQ,CACPkB,OAAU,GAILL,EAAI,EAAGA,EAAIF,EAAGE,IACdA,EAAI,IACRN,EAAMwB,EAAoBrB,EAAIL,EAAKE,EAAKD,EAAKC,SAGnC,KADXK,EAAIX,EAAK+B,KAAM5B,EAAKV,EAAEuC,IAAIC,MAAOxC,EAAGa,GAAOA,EAAI4B,QAASzC,MAEvDM,EAAOA,EAAMkB,QAAWN,EACxBZ,EAAMkB,QAAU,GAelB,OARAV,EAAM,IAAIL,EAHVQ,EAAIX,EAAMkB,QAMVkB,EAAOzB,EAAGX,EAAO,EAAGQ,EAAK,GAGrB,IAAId,EAAE2C,YAAa5B,EAAID,EAAK,CAAEG,GAAK,CAAE,GAAK,EAAGN,EAGlD"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 4a5dcbc..0000000 --- a/lib/index.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Filter and map elements in an input ndarray to elements in a new output ndarray according to a callback function. -* -* @module @stdlib/ndarray-filter-map -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var filterMap = require( '@stdlib/ndarray-filter-map' ); -* -* function fcn( v ) { -* if ( v > 5.0 ) { -* return v * 10.0; -* } -* } -* -* var buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filterMap( x, fcn ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 80.0, 90.0, 100.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 095a81e..0000000 --- a/lib/main.js +++ /dev/null @@ -1,201 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var ctors = require( '@stdlib/ndarray-base-buffer-ctors' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var getDType = require( '@stdlib/ndarray-dtype' ); -var getOrder = require( '@stdlib/ndarray-order' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var gcopy = require( '@stdlib/blas-base-gcopy' ); -var format = require( '@stdlib/string-format' ); - - -// MAIN // - -/** -* Filters and maps elements in an input ndarray to elements in a new output ndarray according to a callback function. -* -* @param {ndarray} x - input ndarray -* @param {Options} [options] - function options -* @param {string} [options.dtype] - output array data type -* @param {string} [options.order] - index iteration order -* @param {Callback} fcn - callback function -* @param {*} [thisArg] - callback execution context -* @throws {TypeError} first argument must be an ndarray-like object -* @throws {TypeError} callback argument must be a function -* @throws {TypeError} options argument must be an object -* @returns {ndarray} output ndarray -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* function fcn( v ) { -* if ( v > 5.0 ) { -* return v * 10.0; -* } -* } -* -* var buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filterMap( x, fcn ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 80.0, 90.0, 100.0 ] -*/ -function filterMap( x, options, fcn, thisArg ) { - var hasOpts; - var ndims; - var cache; - var clbk; - var opts; - var ctor; - var ctx; - var ord; - var dim; - var idx; - var buf; - var dt; - var sh; - var N; - var y; - var v; - var i; - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray-like object. Value: `%s`.', x ) ); - } - if ( arguments.length < 3 ) { - clbk = options; - } else if ( arguments.length === 3 ) { - if ( isFunction( options ) ) { - clbk = options; - ctx = fcn; - } else { - hasOpts = true; - opts = options; - clbk = fcn; - } - } else { - hasOpts = true; - opts = options; - clbk = fcn; - ctx = thisArg; - } - if ( !isFunction( clbk ) ) { - throw new TypeError( format( 'invalid argument. Callback argument must be a function. Value: `%s`.', clbk ) ); - } - if ( hasOpts ) { - if ( !isPlainObject( opts ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) ); - } - if ( hasOwnProp( opts, 'dtype' ) ) { - dt = opts.dtype; - } else { - dt = getDType( x ); - } - if ( hasOwnProp( opts, 'order' ) ) { - if ( !isOrder( opts.order ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', opts.order ) ); - } - ord = opts.order; - } - } else { - dt = getDType( x ); - } - // Resolve an output array buffer constructor: - ctor = ctors( dt ); - if ( ctor === null ) { - // The only way we should get here is if the user provided an unsupported data type, as `getDType` should error if the input array has an unrecognized/unsupported data type... - throw new TypeError( format( 'invalid option. `%s` option must be a recognized data type. Option: `%s`.', 'dtype', opts.dtype ) ); - } - // Resolve the iteration order: - if ( ord === void 0 ) { - ord = getOrder( x ); - } - // Resolve the input array shape: - sh = getShape( x ); - - // Compute the number of array elements: - N = numel( sh ); - - // Retrieve the number of dimensions: - ndims = sh.length; - - // Resolve the dimension in which indices should iterate fastest: - if ( ord === 'row-major' ) { - dim = ndims - 1; - } else { // ord === 'column-major' - dim = 0; - } - // Initialize an index array workspace: - idx = zeros( ndims ); - - // Initialize a value cache for those elements which pass a callback function (note: unfortunately, we use an associative array here, as no other good options. If we use a "generic" array, we are limited to 2^32-1 elements. If we allocate, say, a Float64Array buffer for storing indices, we risk materializing lazily-materialized input ndarray values again (e.g., lazy accessor ndarray), which could be expensive. If we allocate a workspace buffer of equal size to the input ndarray to store materialized values, we'd then need to perform another copy in order to shrink the buffer, as, otherwise, could be holding on to significantly more memory than needed for the returned ndarray. There are likely other options, but all involve complexity, so the simplest option is used here.): - cache = { - 'length': 0 - }; - - // Filter and map elements according to a callback function... - for ( i = 0; i < N; i++ ) { - if ( i > 0 ) { - idx = nextCartesianIndex( sh, ord, idx, dim, idx ); - } - v = clbk.call( ctx, x.get.apply( x, idx ), idx.slice(), x ); - if ( v !== void 0 ) { - cache[ cache.length ] = v; - cache.length += 1; - } - } - // Retrieve the number of cached elements: - N = cache.length; - - // Allocate an output array buffer: - buf = new ctor( N ); - - // Copy cached elements to the output array buffer: - gcopy( N, cache, 1, buf, 1 ); - - // Create an output ndarray: - y = new x.constructor( dt, buf, [ N ], [ 1 ], 0, ord ); - - return y; -} - - -// EXPORTS // - -module.exports = filterMap; diff --git a/package.json b/package.json index 0cd30d8..2bbf470 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Filter and map elements in an input ndarray to elements in a new output ndarray according to a callback function.", "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,60 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-zeros": "^0.2.2", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-function": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/blas-base-gcopy": "^0.2.1", - "@stdlib/ndarray-base-assert-is-order": "^0.2.2", - "@stdlib/ndarray-base-buffer-ctors": "^0.3.0", - "@stdlib/ndarray-base-next-cartesian-index": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-dtype": "^0.2.2", - "@stdlib/ndarray-order": "^0.2.2", - "@stdlib/ndarray-shape": "^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-ones": "^0.2.1", - "@stdlib/assert-is-same-float32array": "^0.2.2", - "@stdlib/assert-is-same-float64array": "^0.2.2", - "@stdlib/math-base-assert-is-nan": "^0.2.2", - "@stdlib/math-base-special-floor": "^0.2.3", - "@stdlib/math-base-special-pow": "^0.3.0", - "@stdlib/math-base-special-sqrt": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-shape2strides": "^0.2.2", - "@stdlib/ndarray-base-strides2offset": "^0.2.2", - "@stdlib/ndarray-ctor": "^0.2.2", - "@stdlib/ndarray-to-array": "^0.2.1", - "@stdlib/random-array-discrete-uniform": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "strided", @@ -106,7 +29,6 @@ "for-each", "apply" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..f9b3f7d --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 56d5ad0..0000000 --- a/test/test.js +++ /dev/null @@ -1,924 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 ones = require( '@stdlib/array-ones' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var isSameFloat64Array = require( '@stdlib/assert-is-same-float64array' ); -var isSameFloat32Array = require( '@stdlib/assert-is-same-float32array' ); -var filterMap = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof filterMap, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - true, - false, - null, - void 0, - [], - {}, - function noop() {}, - { - 'data': true - } - ]; - - 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() { - filterMap( value, fcn ); - }; - } - - function fcn( z ) { - if ( z > 0.0 ) { - return z * 10.0; - } - } -}); - -tape( 'the function throws an error if a callback argument which is not a function', function test( t ) { - var values; - var x; - var i; - - values = [ - '5', - 5, - true, - false, - null, - void 0, - {}, - [] - ]; - x = ndarray( 'generic', ones( 4, 'generic' ), [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); - - 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() { - filterMap( x, value ); - }; - } -}); - -tape( 'the function throws an error if callback argument which is not a function (options)', function test( t ) { - var values; - var opts; - var x; - var i; - - values = [ - '5', - 5, - true, - false, - null, - void 0, - {}, - [] - ]; - x = ndarray( 'generic', ones( 4, 'generic' ), [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); - opts = { - 'dtype': 'float64' - }; - - 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() { - filterMap( x, opts, value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var x; - var i; - - values = [ - '5', - 5, - true, - false, - null, - void 0, - [] - ]; - x = ndarray( 'generic', ones( 4, 'generic' ), [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); - - 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() { - filterMap( x, value, fcn ); - }; - } - - function fcn( z ) { - if ( z > 0.0 ) { - return z * 10.0; - } - } -}); - -tape( 'the function throws an error if provided an invalid `dtype` option', function test( t ) { - var values; - var x; - var i; - - values = [ - 'foo', - 'bar', - 1, - NaN, - true, - false, - void 0, - null, - [], - {}, - function noop() {} - ]; - x = ndarray( 'generic', ones( 4, 'generic' ), [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); - - 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 opts = { - 'dtype': value - }; - filterMap( x, opts, fcn ); - }; - } - - function fcn( z ) { - if ( z > 0.0 ) { - return z * 10.0; - } - } -}); - -tape( 'the function throws an error if provided an invalid `order` option', function test( t ) { - var values; - var x; - var i; - - values = [ - 'foo', - 'bar', - 1, - NaN, - true, - false, - void 0, - null, - [], - {}, - function noop() {} - ]; - x = ndarray( 'generic', ones( 4, 'generic' ), [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); - - 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 opts = { - 'order': value - }; - filterMap( x, opts, fcn ); - }; - } - - function fcn( z ) { - if ( z > 0.0 ) { - return z * 10.0; - } - } -}); - -tape( 'the function filters and maps an array according to a callback function (row-major)', function test( t ) { - var expected; - var ord; - var buf; - var sh; - var st; - var dt; - var o; - var x; - var y; - - buf = new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] ); - dt = 'float64'; - ord = 'row-major'; - sh = [ 2, 1, 2 ]; - st = shape2strides( sh, ord ); - o = strides2offset( sh, st ); - - x = ndarray( dt, buf, sh, st, o, ord ); - - y = filterMap( x, fcn ); - - expected = new Float64Array([ - 10.0, - 30.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - - t.end(); - - function fcn( z ) { - if ( z > 0.0 ) { - return z * 10.0; - } - } -}); - -tape( 'the function filters and maps an array according to a callback function (column-major, contiguous)', function test( t ) { - var expected; - var ord; - var buf; - var sh; - var st; - var dt; - var o; - var x; - var y; - - buf = new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] ); - dt = 'float64'; - ord = 'column-major'; - sh = [ 2, 1, 2 ]; - st = shape2strides( sh, ord ); - o = strides2offset( sh, st ); - - x = ndarray( dt, buf, sh, st, o, ord ); - - y = filterMap( x, fcn ); - - expected = new Float64Array([ - 10.0, - 30.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - - t.end(); - - function fcn( z ) { - if ( z > 0.0 ) { - return z * 10.0; - } - } -}); - -tape( 'the function filters and maps an array according to a callback function (row-major, contiguous, options)', function test( t ) { - var expected; - var opts; - var ord; - var buf; - var sh; - var st; - var dt; - var o; - var x; - var y; - - buf = new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] ); - dt = 'float64'; - ord = 'row-major'; - sh = [ 2, 1, 2 ]; - st = shape2strides( sh, ord ); - o = strides2offset( sh, st ); - x = ndarray( dt, buf, sh, st, o, ord ); - - opts = {}; - y = filterMap( x, opts, fcn ); - - expected = new Float64Array([ - 10.0, - 30.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - - opts = { - 'dtype': 'float32' - }; - y = filterMap( x, opts, fcn ); - - expected = new Float32Array([ - 10.0, - 30.0 - ]); - t.strictEqual( isSameFloat32Array( y.data, expected ), true, 'returns expected value' ); - - t.end(); - - function fcn( z ) { - if ( z > 0.0 ) { - return z * 10.0; - } - } -}); - -tape( 'the function filters and maps an array according to a callback function (column-major, contiguous, options)', function test( t ) { - var expected; - var opts; - var ord; - var buf; - var sh; - var st; - var dt; - var o; - var x; - var y; - - buf = new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] ); - dt = 'float64'; - ord = 'column-major'; - sh = [ 2, 1, 2 ]; - st = shape2strides( sh, ord ); - o = strides2offset( sh, st ); - x = ndarray( dt, buf, sh, st, o, ord ); - - opts = {}; - y = filterMap( x, opts, fcn ); - - expected = new Float64Array([ - 10.0, - 30.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - - opts = { - 'dtype': 'float32' - }; - y = filterMap( x, opts, fcn ); - - expected = new Float32Array([ - 10.0, - 30.0 - ]); - t.strictEqual( isSameFloat32Array( y.data, expected ), true, 'returns expected value' ); - - t.end(); - - function fcn( z ) { - if ( z > 0.0 ) { - return z * 10.0; - } - } -}); - -tape( 'the function supports providing a callback execution context', function test( t ) { - var expected; - var ctx; - var ord; - var buf; - var sh; - var st; - var dt; - var o; - var x; - var y; - - buf = new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] ); - dt = 'float64'; - ord = 'row-major'; - sh = [ 2, 1, 2 ]; - st = shape2strides( sh, ord ); - o = strides2offset( sh, st ); - - x = ndarray( dt, buf, sh, st, o, ord ); - - ctx = { - 'count': 0 - }; - y = filterMap( x, fcn, ctx ); - - expected = new Float64Array([ - 10.0, - 30.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( z ) { - this.count += 1; // eslint-disable-line no-invalid-this - if ( z > 0.0 ) { - return z * 10.0; - } - } -}); - -tape( 'the function supports providing a callback execution context (options)', function test( t ) { - var expected; - var ctx; - var ord; - var buf; - var sh; - var st; - var dt; - var o; - var x; - var y; - - buf = new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] ); - dt = 'float64'; - ord = 'row-major'; - sh = [ 2, 1, 2 ]; - st = shape2strides( sh, ord ); - o = strides2offset( sh, st ); - - x = ndarray( dt, buf, sh, st, o, ord ); - - ctx = { - 'count': 0 - }; - y = filterMap( x, {}, fcn, ctx ); - - expected = new Float64Array([ - 10.0, - 30.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( z ) { - this.count += 1; // eslint-disable-line no-invalid-this - if ( z > 0.0 ) { - return z * 10.0; - } - } -}); - -tape( 'the function invokes a provided callback with three arguments (row-major)', function test( t ) { - var expected; - var indices; - var values; - var arrays; - var ord; - var buf; - var sh; - var st; - var dt; - var o; - var x; - var y; - var i; - - buf = new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] ); - dt = 'float64'; - ord = 'row-major'; - sh = [ 2, 1, 2 ]; - st = shape2strides( sh, ord ); - o = strides2offset( sh, st ); - - x = ndarray( dt, buf, sh, st, o, ord ); - - values = []; - indices = []; - arrays = []; - y = filterMap( x, fcn ); - - expected = new Float64Array([ - 10.0, - 30.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 0, 0, 1 ], - [ 1, 0, 0 ], - [ 1, 0, 1 ] - ]; - t.deepEqual( indices, expected, 'returns expected value' ); - - expected = [ - x, - x, - x, - x - ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arrays[ i ], expected[ i ], 'returns expected value' ); - } - - t.end(); - - function fcn( z, idx, arr ) { - values.push( z ); - indices.push( idx ); - arrays.push( arr ); - if ( z > 0.0 ) { - return z * 10.0; - } - } -}); - -tape( 'the function invokes a provided callback with three arguments (column-major)', function test( t ) { - var expected; - var indices; - var values; - var arrays; - var ord; - var buf; - var sh; - var st; - var dt; - var o; - var x; - var y; - var i; - - buf = new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] ); - dt = 'float64'; - ord = 'column-major'; - sh = [ 2, 1, 2 ]; - st = shape2strides( sh, ord ); - o = strides2offset( sh, st ); - - x = ndarray( dt, buf, sh, st, o, ord ); - - values = []; - indices = []; - arrays = []; - y = filterMap( x, fcn ); - - expected = new Float64Array([ - 10.0, - 30.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 1, 0, 0 ], - [ 0, 0, 1 ], - [ 1, 0, 1 ] - ]; - t.deepEqual( indices, expected, 'returns expected value' ); - - expected = [ - x, - x, - x, - x - ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arrays[ i ], expected[ i ], 'returns expected value' ); - } - - t.end(); - - function fcn( z, idx, arr ) { - values.push( z ); - indices.push( idx ); - arrays.push( arr ); - if ( z > 0.0 ) { - return z * 10.0; - } - } -}); - -tape( 'the function supports specifying the iteration order (row-major/row-major)', function test( t ) { - var expected; - var indices; - var values; - var arrays; - var opts; - var ord; - var buf; - var sh; - var st; - var dt; - var o; - var x; - var y; - var i; - - buf = new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] ); - dt = 'float64'; - ord = 'row-major'; - sh = [ 2, 1, 2 ]; - st = shape2strides( sh, ord ); - o = strides2offset( sh, st ); - - x = ndarray( dt, buf, sh, st, o, ord ); - - values = []; - indices = []; - arrays = []; - - opts = { - 'order': 'row-major' - }; - y = filterMap( x, opts, fcn ); - - expected = new Float64Array([ - 10.0, - 30.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 0, 0, 1 ], - [ 1, 0, 0 ], - [ 1, 0, 1 ] - ]; - t.deepEqual( indices, expected, 'returns expected value' ); - - expected = [ - x, - x, - x, - x - ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arrays[ i ], expected[ i ], 'returns expected value' ); - } - - t.end(); - - function fcn( z, idx, arr ) { - values.push( z ); - indices.push( idx ); - arrays.push( arr ); - if ( z > 0.0 ) { - return z * 10.0; - } - } -}); - -tape( 'the function supports specifying the iteration order (row-major/column-major)', function test( t ) { - var expected; - var indices; - var values; - var arrays; - var opts; - var ord; - var buf; - var sh; - var st; - var dt; - var o; - var x; - var y; - var i; - - buf = new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] ); - dt = 'float64'; - ord = 'row-major'; - sh = [ 2, 1, 2 ]; - st = shape2strides( sh, ord ); - o = strides2offset( sh, st ); - - x = ndarray( dt, buf, sh, st, o, ord ); - - values = []; - indices = []; - arrays = []; - - opts = { - 'order': 'column-major' - }; - y = filterMap( x, opts, fcn ); - - expected = new Float64Array([ - 10.0, - 30.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 1, 0, 0 ], - [ 0, 0, 1 ], - [ 1, 0, 1 ] - ]; - t.deepEqual( indices, expected, 'returns expected value' ); - - expected = [ - x, - x, - x, - x - ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arrays[ i ], expected[ i ], 'returns expected value' ); - } - - t.end(); - - function fcn( z, idx, arr ) { - values.push( z ); - indices.push( idx ); - arrays.push( arr ); - if ( z > 0.0 ) { - return z * 10.0; - } - } -}); - -tape( 'the function supports specifying the iteration order (column-major/row-major)', function test( t ) { - var expected; - var indices; - var values; - var arrays; - var opts; - var ord; - var buf; - var sh; - var st; - var dt; - var o; - var x; - var y; - var i; - - buf = new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] ); - dt = 'float64'; - ord = 'column-major'; - sh = [ 2, 1, 2 ]; - st = shape2strides( sh, ord ); - o = strides2offset( sh, st ); - - x = ndarray( dt, buf, sh, st, o, ord ); - - values = []; - indices = []; - arrays = []; - - opts = { - 'order': 'row-major' - }; - y = filterMap( x, opts, fcn ); - - expected = new Float64Array([ - 10.0, - 30.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 0, 0, 1 ], - [ 1, 0, 0 ], - [ 1, 0, 1 ] - ]; - t.deepEqual( indices, expected, 'returns expected value' ); - - expected = [ - x, - x, - x, - x - ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arrays[ i ], expected[ i ], 'returns expected value' ); - } - - t.end(); - - function fcn( z, idx, arr ) { - values.push( z ); - indices.push( idx ); - arrays.push( arr ); - if ( z > 0.0 ) { - return z * 10.0; - } - } -}); - -tape( 'the function supports specifying the iteration order (column-major/column-major)', function test( t ) { - var expected; - var indices; - var values; - var arrays; - var opts; - var ord; - var buf; - var sh; - var st; - var dt; - var o; - var x; - var y; - var i; - - buf = new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] ); - dt = 'float64'; - ord = 'column-major'; - sh = [ 2, 1, 2 ]; - st = shape2strides( sh, ord ); - o = strides2offset( sh, st ); - - x = ndarray( dt, buf, sh, st, o, ord ); - - values = []; - indices = []; - arrays = []; - - opts = { - 'order': 'column-major' - }; - y = filterMap( x, opts, fcn ); - - expected = new Float64Array([ - 10.0, - 30.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 1, 0, 0 ], - [ 0, 0, 1 ], - [ 1, 0, 1 ] - ]; - t.deepEqual( indices, expected, 'returns expected value' ); - - expected = [ - x, - x, - x, - x - ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arrays[ i ], expected[ i ], 'returns expected value' ); - } - - t.end(); - - function fcn( z, idx, arr ) { - values.push( z ); - indices.push( idx ); - arrays.push( arr ); - if ( z > 0.0 ) { - return z * 10.0; - } - } -});