From d3becfebf51fc5b0b2e431507971e2b25c40158b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 14 Dec 2024 04:56:50 +0000 Subject: [PATCH 01/35] Transform error messages --- lib/main.js | 12 ++++++------ package.json | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/main.js b/lib/main.js index 121a6ce..f66736a 100644 --- a/lib/main.js +++ b/lib/main.js @@ -33,7 +33,7 @@ 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' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -92,7 +92,7 @@ function filter( x, options, predicate, thisArg ) { var v; var i; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray-like object. Value: `%s`.', x ) ); + throw new TypeError( format( 'null5t', x ) ); } if ( arguments.length < 3 ) { clbk = options; @@ -112,11 +112,11 @@ function filter( x, options, predicate, thisArg ) { ctx = thisArg; } if ( !isFunction( clbk ) ) { - throw new TypeError( format( 'invalid argument. Callback argument must be a function. Value: `%s`.', clbk ) ); + throw new TypeError( format( 'null2b', clbk ) ); } if ( hasOpts ) { if ( !isPlainObject( opts ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) ); + throw new TypeError( format( 'null2V', opts ) ); } if ( hasOwnProp( opts, 'dtype' ) ) { dt = opts.dtype; @@ -125,7 +125,7 @@ function filter( x, options, predicate, thisArg ) { } 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 ) ); + throw new TypeError( format( 'null5C', 'order', opts.order ) ); } ord = opts.order; } @@ -136,7 +136,7 @@ function filter( x, options, predicate, thisArg ) { 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 ) ); + throw new TypeError( format( 'nullBf', 'dtype', opts.dtype ) ); } // Resolve the iteration order: if ( ord === void 0 ) { diff --git a/package.json b/package.json index 22065aa..a44b313 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@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/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From a941253fd17eb8fc36ba426729adfaf0bc9394cd Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 14 Dec 2024 04:57:55 +0000 Subject: [PATCH 02/35] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 48 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 65 +- SECURITY.md | 5 - benchmark/benchmark.1d.js | 150 - benchmark/benchmark.2d.js | 161 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 51 - docs/types/test.ts | 195 - examples/index.js | 38 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 55 - lib/main.js | 199 - package.json | 84 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 892 ---- 44 files changed, 4878 insertions(+), 5312 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.1d.js delete mode 100644 benchmark/benchmark.2d.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 03a0613..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) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 48af73a..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) 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 443f7ec..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: '9 21 * * 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 + + ```
@@ -213,7 +204,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]. @@ -276,11 +267,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-filter/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 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 6958f29..0000000 --- a/benchmark/benchmark.1d.js +++ /dev/null @@ -1,150 +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 filter = require( './../lib' ); - - -// VARIABLES // - -var xtypes = [ 'generic' ]; -var ytypes = [ 'float64' ]; -var orders = [ 'row-major', 'column-major' ]; - - -// FUNCTIONS // - -/** -* Predicate function. -* -* @private -* @param {number} value - array element -* @param {NonNegativeIntegerArray} indices - element indices -* @param {ndarray} arr - input array -* @returns {boolean} result -*/ -function predicate( value ) { - return value > 0.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 = filter( x, opts, predicate ); - 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 e848b15..0000000 --- a/benchmark/benchmark.2d.js +++ /dev/null @@ -1,161 +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 map = require( './../lib' ); - - -// VARIABLES // - -var xtypes = [ 'generic' ]; -var ytypes = [ 'float64' ]; -var orders = [ 'row-major', 'column-major' ]; - - -// FUNCTIONS // - -/** -* Predicate function. -* -* @private -* @param {number} value - array element -* @param {NonNegativeIntegerArray} indices - element indices -* @param {ndarray} arr - input array -* @returns {boolean} result -*/ -function predicate( value ) { - return value > 0.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 = map( x, opts, predicate ); - 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 51e4f91..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" -%% click B href "https://github.com/stdlib-js/ndarray-filter/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-filter/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-filter/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-filter/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-filter/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/filter -[production-url]: https://github.com/stdlib-js/ndarray-filter/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-filter/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-filter/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-filter/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-filter/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-filter/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-filter/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 aafb9cb..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import filter from '../docs/types/index'; -export = filter; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 558b3a7..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var V=function(r,a){return function(){return a||r((a={exports:{}}).exports,a),a.exports}};var k=V(function(K,j){"use strict";var C=require("@stdlib/assert-is-plain-object"),O=require("@stdlib/assert-is-function"),F=require("@stdlib/assert-is-ndarray-like"),P=require("@stdlib/ndarray-base-assert-is-order"),T=require("@stdlib/assert-has-own-property"),D=require("@stdlib/ndarray-base-buffer-ctors"),I=require("@stdlib/array-base-zeros"),L=require("@stdlib/ndarray-shape"),E=require("@stdlib/ndarray-dtype"),N=require("@stdlib/ndarray-order"),S=require("@stdlib/ndarray-base-numel"),A=require("@stdlib/ndarray-base-next-cartesian-index").assign,B=require("@stdlib/blas-base-gcopy"),v=require("@stdlib/string-format");function G(r,a,g,z){var c,f,o,i,e,p,m,h,t,y,n,q,s,l,u,b,w,d;if(!F(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?O(a)?(i=a,h=g):(c=!0,e=a,i=g):(c=!0,e=a,i=g,h=z),!O(i))throw new TypeError(v("invalid argument. Callback argument must be a function. Value: `%s`.",i));if(c){if(!C(e))throw new TypeError(v("invalid argument. Options argument must be an object. Value: `%s`.",e));if(T(e,"dtype")?s=e.dtype:s=E(r),T(e,"order")){if(!P(e.order))throw new TypeError(v("invalid option. `%s` option must be a recognized order. Option: `%s`.","order",e.order));t=e.order}}else s=E(r);if(p=D(s),p===null)throw new TypeError(v("invalid option. `%s` option must be a recognized data type. Option: `%s`.","dtype",e.dtype));for(t===void 0&&(t=N(r)),l=L(r),u=S(l),f=l.length,t==="row-major"?y=f-1:y=0,n=I(f),o={length:0},m=-1,d=0;d0&&(n=A(l,t,n,y,n)),w=r.get.apply(r,n),i.call(h,w,n.slice(),r)&&(o.length+=1,m+=1,o[m]=w);return u=o.length,q=new p(u),B(u,o,1,q,1),b=new r.constructor(s,q,[u],[1],0,t),b}j.exports=G});var H=k();module.exports=H; -/** -* @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 92b21c3..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* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate 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 {boolean} [options.order='row-major'] - index iteration order\n* @param {Callback} predicate - predicate function\n* @param {*} [thisArg] - predicate 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 isEven = require( '@stdlib/assert-is-even' ).isPrimitive;\n* var Float64Array = require( '@stdlib/array-float64' );\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\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 = filter( x, isEven );\n* // returns \n*\n* var arr = ndarray2array( y );\n* // returns [ 2.0, 4.0, 8.0, 10.0 ]\n*/\nfunction filter( x, options, predicate, thisArg ) {\n\tvar hasOpts;\n\tvar ndims;\n\tvar cache;\n\tvar clbk;\n\tvar opts;\n\tvar ctor;\n\tvar cidx;\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 = predicate;\n\t\t} else {\n\t\t\thasOpts = true;\n\t\t\topts = options;\n\t\t\tclbk = predicate;\n\t\t}\n\t} else {\n\t\thasOpts = true;\n\t\topts = options;\n\t\tclbk = predicate;\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 predicate 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 elements according to a predicate function...\n\tcidx = -1;\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 = x.get.apply( x, idx );\n\t\tif ( clbk.call( ctx, v, idx.slice(), x ) ) {\n\t\t\tcache.length += 1;\n\t\t\tcidx += 1;\n\t\t\tcache[ cidx ] = v;\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 = filter;\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* Return a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function.\n*\n* @module @stdlib/ndarray-filter\n*\n* @example\n* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive;\n* var Float64Array = require( '@stdlib/array-float64' );\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var filter = require( '@stdlib/ndarray-filter' );\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 = filter( x, isEven );\n* // returns \n*\n* var arr = ndarray2array( y );\n* // returns [ 2.0, 4.0, 8.0, 10.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,EAuC9C,SAASC,EAAQC,EAAGC,EAASC,EAAWC,EAAU,CACjD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,GAAK,CAAClC,EAAea,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,gFAAiFE,CAAE,CAAE,EAmBnH,GAjBK,UAAU,OAAS,EACvBO,EAAON,EACI,UAAU,SAAW,EAC3Bf,EAAYe,CAAQ,GACxBM,EAAON,EACPU,EAAMT,IAENE,EAAU,GACVI,EAAOP,EACPM,EAAOL,IAGRE,EAAU,GACVI,EAAOP,EACPM,EAAOL,EACPS,EAAMR,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,EAC9BQ,EAAKR,EAAK,MAEVQ,EAAKvB,EAAUO,CAAE,EAEbX,EAAYmB,EAAM,OAAQ,EAAI,CAClC,GAAK,CAACpB,EAASoB,EAAK,KAAM,EACzB,MAAM,IAAI,UAAWV,EAAQ,wEAAyE,QAASU,EAAK,KAAM,CAAE,EAE7HI,EAAMJ,EAAK,KACZ,CACD,MACCQ,EAAKvB,EAAUO,CAAE,EAIlB,GADAS,EAAOnB,EAAO0B,CAAG,EACZP,IAAS,KAEb,MAAM,IAAI,UAAWX,EAAQ,4EAA6E,QAASU,EAAK,KAAM,CAAE,EA+BjI,IA5BKI,IAAQ,SACZA,EAAMlB,EAAUM,CAAE,GAGnBiB,EAAKzB,EAAUQ,CAAE,EAGjBkB,EAAIvB,EAAOsB,CAAG,EAGdZ,EAAQY,EAAG,OAGNL,IAAQ,YACZC,EAAMR,EAAQ,EAEdQ,EAAM,EAGPC,EAAMvB,EAAOc,CAAM,EAGnBC,EAAQ,CACP,OAAU,CACX,EAGAI,EAAO,GACDW,EAAI,EAAGA,EAAIH,EAAGG,IACdA,EAAI,IACRP,EAAMlB,EAAoBqB,EAAIL,EAAKE,EAAKD,EAAKC,CAAI,GAElDM,EAAIpB,EAAE,IAAI,MAAOA,EAAGc,CAAI,EACnBP,EAAK,KAAMI,EAAKS,EAAGN,EAAI,MAAM,EAAGd,CAAE,IACtCM,EAAM,QAAU,EAChBI,GAAQ,EACRJ,EAAOI,CAAK,EAAIU,GAIlB,OAAAF,EAAIZ,EAAM,OAGVS,EAAM,IAAIN,EAAMS,CAAE,EAGlBrB,EAAOqB,EAAGZ,EAAO,EAAGS,EAAK,CAAE,EAG3BI,EAAI,IAAInB,EAAE,YAAagB,EAAID,EAAK,CAAEG,CAAE,EAAG,CAAE,CAAE,EAAG,EAAGN,CAAI,EAE9CO,CACR,CAKAnC,EAAO,QAAUe,ICrJjB,IAAIuB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isPlainObject", "isFunction", "isndarrayLike", "isOrder", "hasOwnProp", "ctors", "zeros", "getShape", "getDType", "getOrder", "numel", "nextCartesianIndex", "gcopy", "format", "filter", "x", "options", "predicate", "thisArg", "hasOpts", "ndims", "cache", "clbk", "opts", "ctor", "cidx", "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 8ed7071..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,51 +0,0 @@ - -{{alias}}( x[, options], predicate[, thisArg] ) - Returns a shallow copy of an ndarray containing only those elements which - pass a test implemented by a predicate function. - - The predicate function is provided the following arguments: - - - value: current array element. - - indices: current array element indices. - - arr: the input 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 manor, 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'. - - predicate: Function - Predicate function. - - thisArg: any (optional) - Predicate function execution context. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ); - > function f( v ) { return v > 2.0; }; - > var y = {{alias}}( x, f ); - > {{alias:@stdlib/ndarray/to-array}}( y ) - [ 3.0, 4.0 ] - - See Also - -------- diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 046dffb..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,195 +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 empty = require( '@stdlib/ndarray-base-empty' ); -import zeros = require( '@stdlib/ndarray-base-zeros' ); -import filter = require( './index' ); - -/** -* Predicate function. -* -* @param x - input value -* @returns result -*/ -function predicate( x: any ): boolean { - return Boolean( x ); -} - -// The function returns an ndarray... -{ - const sh = [ 2, 2 ]; - const ord = 'row-major'; - - filter( zeros( 'float64', sh, ord ), predicate ); // $ExpectType float64ndarray - filter( zeros( 'float64', sh, ord ), predicate, {} ); // $ExpectType float64ndarray - filter( zeros( 'float32', sh, ord ), predicate ); // $ExpectType float32ndarray - filter( zeros( 'float32', sh, ord ), predicate, {} ); // $ExpectType float32ndarray - filter( zeros( 'complex64', sh, ord ), predicate ); // $ExpectType complex64ndarray - filter( zeros( 'complex64', sh, ord ), predicate, {} ); // $ExpectType complex64ndarray - filter( zeros( 'complex128', sh, ord ), predicate ); // $ExpectType complex128ndarray - filter( zeros( 'complex128', sh, ord ), predicate, {} ); // $ExpectType complex128ndarray - filter( zeros( 'int32', sh, ord ), predicate ); // $ExpectType int32ndarray - filter( zeros( 'int32', sh, ord ), predicate, {} ); // $ExpectType int32ndarray - filter( zeros( 'int16', sh, ord ), predicate ); // $ExpectType int16ndarray - filter( zeros( 'int16', sh, ord ), predicate, {} ); // $ExpectType int16ndarray - filter( zeros( 'int8', sh, ord ), predicate ); // $ExpectType int8ndarray - filter( zeros( 'int8', sh, ord ), predicate, {} ); // $ExpectType int8ndarray - filter( zeros( 'uint32', sh, ord ), predicate ); // $ExpectType uint32ndarray - filter( zeros( 'uint32', sh, ord ), predicate, {} ); // $ExpectType uint32ndarray - filter( zeros( 'uint16', sh, ord ), predicate ); // $ExpectType uint16ndarray - filter( zeros( 'uint16', sh, ord ), predicate, {} ); // $ExpectType uint16ndarray - filter( zeros( 'uint8', sh, ord ), predicate ); // $ExpectType uint8ndarray - filter( zeros( 'uint8', sh, ord ), predicate, {} ); // $ExpectType uint8ndarray - filter( zeros( 'uint8c', sh, ord ), predicate ); // $ExpectType uint8cndarray - filter( zeros( 'uint8c', sh, ord ), predicate, {} ); // $ExpectType uint8cndarray - filter( empty( 'bool', sh, ord ), predicate ); // $ExpectType boolndarray - filter( empty( 'bool', sh, ord ), predicate, {} ); // $ExpectType boolndarray - filter( zeros( 'generic', sh, ord ), predicate ); // $ExpectType genericndarray - filter( zeros( 'generic', sh, ord ), predicate, {} ); // $ExpectType genericndarray - - - filter( zeros( 'generic', sh, ord ), { 'dtype': 'float64' }, predicate ); // $ExpectType float64ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'float64' }, predicate, {} ); // $ExpectType float64ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'float32' }, predicate ); // $ExpectType float32ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'float32' }, predicate, {} ); // $ExpectType float32ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'complex64' }, predicate ); // $ExpectType complex64ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'complex64' }, predicate, {} ); // $ExpectType complex64ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'complex128' }, predicate ); // $ExpectType complex128ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'complex128' }, predicate, {} ); // $ExpectType complex128ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'int32' }, predicate ); // $ExpectType int32ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'int32' }, predicate, {} ); // $ExpectType int32ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'int16' }, predicate ); // $ExpectType int16ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'int16' }, predicate, {} ); // $ExpectType int16ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'int8' }, predicate ); // $ExpectType int8ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'int8' }, predicate, {} ); // $ExpectType int8ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint32' }, predicate ); // $ExpectType uint32ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint32' }, predicate, {} ); // $ExpectType uint32ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint16' }, predicate ); // $ExpectType uint16ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint16' }, predicate, {} ); // $ExpectType uint16ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint8' }, predicate ); // $ExpectType uint8ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint8' }, predicate, {} ); // $ExpectType uint8ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint8c' }, predicate ); // $ExpectType uint8cndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint8c' }, predicate, {} ); // $ExpectType uint8cndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'bool' }, predicate ); // $ExpectType boolndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'bool' }, predicate, {} ); // $ExpectType boolndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'generic' }, predicate ); // $ExpectType genericndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'generic' }, predicate, {} ); // $ExpectType genericndarray - - - filter( zeros( 'float64', sh, ord ), { 'order': ord }, predicate ); // $ExpectType float64ndarray - filter( zeros( 'float64', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType float64ndarray - filter( zeros( 'float32', sh, ord ), { 'order': ord }, predicate ); // $ExpectType float32ndarray - filter( zeros( 'float32', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType float32ndarray - filter( zeros( 'complex64', sh, ord ), { 'order': ord }, predicate ); // $ExpectType complex64ndarray - filter( zeros( 'complex64', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType complex64ndarray - filter( zeros( 'complex128', sh, ord ), { 'order': ord }, predicate ); // $ExpectType complex128ndarray - filter( zeros( 'complex128', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType complex128ndarray - filter( zeros( 'int32', sh, ord ), { 'order': ord }, predicate ); // $ExpectType int32ndarray - filter( zeros( 'int32', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType int32ndarray - filter( zeros( 'int16', sh, ord ), { 'order': ord }, predicate ); // $ExpectType int16ndarray - filter( zeros( 'int16', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType int16ndarray - filter( zeros( 'int8', sh, ord ), { 'order': ord }, predicate ); // $ExpectType int8ndarray - filter( zeros( 'int8', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType int8ndarray - filter( zeros( 'uint32', sh, ord ), { 'order': ord }, predicate ); // $ExpectType uint32ndarray - filter( zeros( 'uint32', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType uint32ndarray - filter( zeros( 'uint16', sh, ord ), { 'order': ord }, predicate ); // $ExpectType uint16ndarray - filter( zeros( 'uint16', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType uint16ndarray - filter( zeros( 'uint8', sh, ord ), { 'order': ord }, predicate ); // $ExpectType uint8ndarray - filter( zeros( 'uint8', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType uint8ndarray - filter( zeros( 'uint8c', sh, ord ), { 'order': ord }, predicate ); // $ExpectType uint8cndarray - filter( zeros( 'uint8c', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType uint8cndarray - filter( empty( 'bool', sh, ord ), { 'order': ord }, predicate ); // $ExpectType boolndarray - filter( empty( 'bool', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType boolndarray - filter( zeros( 'generic', sh, ord ), { 'order': ord }, predicate ); // $ExpectType genericndarray - filter( zeros( 'generic', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType genericndarray - -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - filter( 5, predicate ); // $ExpectError - filter( true, predicate ); // $ExpectError - filter( false, predicate ); // $ExpectError - filter( null, predicate ); // $ExpectError - filter( undefined, predicate ); // $ExpectError - filter( {}, predicate ); // $ExpectError - filter( [ 1 ], predicate ); // $ExpectError - filter( ( x: number ): number => x, predicate ); // $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' ); - - filter( x, '5' ); // $ExpectError - filter( x, true ); // $ExpectError - filter( x, false ); // $ExpectError - filter( x, null ); // $ExpectError - filter( x, undefined ); // $ExpectError - filter( x, {} ); // $ExpectError - filter( 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' ); - - filter( x, '10', predicate, {} ); // $ExpectError - filter( x, 10, predicate, {} ); // $ExpectError - filter( x, false, predicate, {} ); // $ExpectError - filter( x, true, predicate, {} ); // $ExpectError - filter( x, [], predicate, {} ); // $ExpectError - filter( x, ( x: number ): number => x, predicate, {} ); // $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' ); - - filter( x, { 'dtype': '10' }, predicate ); // $ExpectError - filter( x, { 'dtype': 10 }, predicate ); // $ExpectError - filter( x, { 'dtype': null }, predicate ); // $ExpectError - filter( x, { 'dtype': false }, predicate ); // $ExpectError - filter( x, { 'dtype': true }, predicate ); // $ExpectError - filter( x, { 'dtype': [] }, predicate ); // $ExpectError - filter( x, { 'dtype': {} }, predicate ); // $ExpectError - filter( x, { 'dtype': ( x: number ): number => x }, predicate ); // $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' ); - - filter( x, { 'order': '10' }, predicate ); // $ExpectError - filter( x, { 'order': 10 }, predicate ); // $ExpectError - filter( x, { 'order': null }, predicate ); // $ExpectError - filter( x, { 'order': false }, predicate ); // $ExpectError - filter( x, { 'order': true }, predicate ); // $ExpectError - filter( x, { 'order': [] }, predicate ); // $ExpectError - filter( x, { 'order': {} }, predicate ); // $ExpectError - filter( x, { 'order': ( x: number ): number => x }, predicate ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - filter(); // $ExpectError - filter( zeros( 'float64', [ 2, 2 ], 'row-major' ) ); // $ExpectError - filter( 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 e2dd6cb..0000000 --- a/examples/index.js +++ /dev/null @@ -1,38 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var array = require( '@stdlib/ndarray-array' ); -var isPositive = require( '@stdlib/assert-is-positive-number' ).isPrimitive; -var filter = require( './../lib' ); - -var buffer = discreteUniform( 10, -100, 100, { - 'dtype': 'generic' -}); -var x = array( buffer, { - 'shape': [ 5, 2 ], - 'dtype': 'generic' -}); -console.log( ndarray2array( x ) ); - -var y = filter( x, naryFunction( isPositive, 1 ) ); -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 a39a064..e2a9d07 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..f1c84f4 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import e 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 a from"https://cdn.jsdelivr.net/gh/stdlib-js/blas-base-gcopy@v0.2.1-esm/index.mjs";import h 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,G;if(!e(v))throw new TypeError(h("null5t",v));if(arguments.length<3?w=f:3===arguments.length?s(f)?(w=f,k=b):(g=!0,u=f,w=b):(g=!0,u=f,w=b,k=c),!s(w))throw new TypeError(h("null2b",w));if(g){if(!r(u))throw new TypeError(h("null2V",u));if(q=n(u,"dtype")?u.dtype:m(v),n(u,"order")){if(!t(u.order))throw new TypeError(h("null5C","order",u.order));z=u.order}}else q=m(v);if(null===(E=d(q)))throw new TypeError(h("nullBf","dtype",u.dtype));for(void 0===z&&(z=l(v)),A=o(v),D=p(A),y=A.length,B="row-major"===z?y-1:0,C=i(y),x={length:0},T=-1,G=0;G0&&(C=j(A,z,C,B,C)),F=v.get.apply(v,C),w.call(k,F,C.slice(),v)&&(x.length+=1,x[T+=1]=F);return V=new E(D=x.length),a(D,x,1,V,1),new v.constructor(q,V,[D],[1],0,z)}export{v as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..c68f119 --- /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* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate 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 {boolean} [options.order='row-major'] - index iteration order\n* @param {Callback} predicate - predicate function\n* @param {*} [thisArg] - predicate 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 { isPrimitive as isEven } from '@stdlib/assert-is-even';\n* import Float64Array from '@stdlib/array-float64';\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndarray2array from '@stdlib/ndarray-to-array';\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 = filter( x, isEven );\n* // returns \n*\n* var arr = ndarray2array( y );\n* // returns [ 2.0, 4.0, 8.0, 10.0 ]\n*/\nfunction filter( x, options, predicate, thisArg ) {\n\tvar hasOpts;\n\tvar ndims;\n\tvar cache;\n\tvar clbk;\n\tvar opts;\n\tvar ctor;\n\tvar cidx;\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 = predicate;\n\t\t} else {\n\t\t\thasOpts = true;\n\t\t\topts = options;\n\t\t\tclbk = predicate;\n\t\t}\n\t} else {\n\t\thasOpts = true;\n\t\topts = options;\n\t\tclbk = predicate;\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 predicate 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 elements according to a predicate function...\n\tcidx = -1;\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 = x.get.apply( x, idx );\n\t\tif ( clbk.call( ctx, v, idx.slice(), x ) ) {\n\t\t\tcache.length += 1;\n\t\t\tcidx += 1;\n\t\t\tcache[ cidx ] = v;\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 filter;\n"],"names":["filter","x","options","predicate","thisArg","hasOpts","ndims","cache","clbk","opts","ctor","cidx","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","get","apply","call","slice","gcopy","constructor"],"mappings":";;6zCA0EA,SAASA,EAAQC,EAAGC,EAASC,EAAWC,GACvC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEAC,EACAC,EACJ,IAAMC,EAAerB,GACpB,MAAM,IAAIsB,UAAWC,EAAQ,SAAUvB,IAmBxC,GAjBKwB,UAAUC,OAAS,EACvBlB,EAAON,EACyB,IAArBuB,UAAUC,OAChBC,EAAYzB,IAChBM,EAAON,EACPU,EAAMT,IAENE,GAAU,EACVI,EAAOP,EACPM,EAAOL,IAGRE,GAAU,EACVI,EAAOP,EACPM,EAAOL,EACPS,EAAMR,IAEDuB,EAAYnB,GACjB,MAAM,IAAIe,UAAWC,EAAQ,SAAUhB,IAExC,GAAKH,EAAU,CACd,IAAMuB,EAAenB,GACpB,MAAM,IAAIc,UAAWC,EAAQ,SAAUf,IAOxC,GAJCQ,EADIY,EAAYpB,EAAM,SACjBA,EAAKqB,MAELC,EAAU9B,GAEX4B,EAAYpB,EAAM,SAAY,CAClC,IAAMuB,EAASvB,EAAKwB,OACnB,MAAM,IAAIV,UAAWC,EAAQ,SAAU,QAASf,EAAKwB,QAEtDpB,EAAMJ,EAAKwB,KACX,CACH,MACEhB,EAAKc,EAAU9B,GAIhB,GAAc,QADdS,EAAOwB,EAAOjB,IAGb,MAAM,IAAIM,UAAWC,EAAQ,SAAU,QAASf,EAAKqB,QA+BtD,SA5Ba,IAARjB,IACJA,EAAMsB,EAAUlC,IAGjBiB,EAAKkB,EAAUnC,GAGfkB,EAAIkB,EAAOnB,GAGXZ,EAAQY,EAAGQ,OAIVZ,EADY,cAARD,EACEP,EAAQ,EAER,EAGPS,EAAMuB,EAAOhC,GAGbC,EAAQ,CACPmB,OAAU,GAIXf,GAAQ,EACFU,EAAI,EAAGA,EAAIF,EAAGE,IACdA,EAAI,IACRN,EAAMwB,EAAoBrB,EAAIL,EAAKE,EAAKD,EAAKC,IAE9CK,EAAInB,EAAEuC,IAAIC,MAAOxC,EAAGc,GACfP,EAAKkC,KAAM9B,EAAKQ,EAAGL,EAAI4B,QAAS1C,KACpCM,EAAMmB,QAAU,EAEhBnB,EADAI,GAAQ,GACQS,GAelB,OARAJ,EAAM,IAAIN,EAHVS,EAAIZ,EAAMmB,QAMVkB,EAAOzB,EAAGZ,EAAO,EAAGS,EAAK,GAGrB,IAAIf,EAAE4C,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 46f5998..0000000 --- a/lib/index.js +++ /dev/null @@ -1,55 +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'; - -/** -* Return a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @module @stdlib/ndarray-filter -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var filter = require( '@stdlib/ndarray-filter' ); -* -* 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 = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.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 f66736a..0000000 --- a/lib/main.js +++ /dev/null @@ -1,199 +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/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param {ndarray} x - input ndarray -* @param {Options} [options] - function options -* @param {string} [options.dtype] - output array data type -* @param {boolean} [options.order='row-major'] - index iteration order -* @param {Callback} predicate - predicate function -* @param {*} [thisArg] - predicate 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 isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -function filter( x, options, predicate, thisArg ) { - var hasOpts; - var ndims; - var cache; - var clbk; - var opts; - var ctor; - var cidx; - 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( 'null5t', x ) ); - } - if ( arguments.length < 3 ) { - clbk = options; - } else if ( arguments.length === 3 ) { - if ( isFunction( options ) ) { - clbk = options; - ctx = predicate; - } else { - hasOpts = true; - opts = options; - clbk = predicate; - } - } else { - hasOpts = true; - opts = options; - clbk = predicate; - ctx = thisArg; - } - if ( !isFunction( clbk ) ) { - throw new TypeError( format( 'null2b', clbk ) ); - } - if ( hasOpts ) { - if ( !isPlainObject( opts ) ) { - throw new TypeError( format( 'null2V', opts ) ); - } - if ( hasOwnProp( opts, 'dtype' ) ) { - dt = opts.dtype; - } else { - dt = getDType( x ); - } - if ( hasOwnProp( opts, 'order' ) ) { - if ( !isOrder( opts.order ) ) { - throw new TypeError( format( 'null5C', '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( 'nullBf', '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 predicate 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 elements according to a predicate function... - cidx = -1; - for ( i = 0; i < N; i++ ) { - if ( i > 0 ) { - idx = nextCartesianIndex( sh, ord, idx, dim, idx ); - } - v = x.get.apply( x, idx ); - if ( clbk.call( ctx, v, idx.slice(), x ) ) { - cache.length += 1; - cidx += 1; - cache[ cidx ] = v; - } - } - // 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 = filter; diff --git a/package.json b/package.json index a44b313..2473eda 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Return a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate 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,62 +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/error-tools-fmtprodmsg": "^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-positive-number": "^0.2.2", - "@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", - "@stdlib/utils-nary-function": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "strided", @@ -104,7 +25,6 @@ "select", "take" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..7526b53 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Codestin Search App + + + +
+ + + + + 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 3bea6b3..0000000 --- a/test/test.js +++ /dev/null @@ -1,892 +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 filter = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof filter, '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() { - filter( value, predicate ); - }; - } - - function predicate( z ) { - return ( z > 0.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() { - filter( 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() { - filter( 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() { - filter( x, value, predicate ); - }; - } - - function predicate( z ) { - return ( z > 0.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 - }; - filter( x, opts, predicate ); - }; - } - - function predicate( z ) { - return ( z > 0.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 - }; - filter( x, opts, predicate ); - }; - } - - function predicate( z ) { - return ( z > 0.0 ); - } -}); - -tape( 'the function filters an array according to a predicate 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 = filter( x, predicate ); - - expected = new Float64Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - - t.end(); - - function predicate( z ) { - return ( z > 0.0 ); - } -}); - -tape( 'the function filters an array according to a predicate 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 = filter( x, predicate ); - - expected = new Float64Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - - t.end(); - - function predicate( z ) { - return ( z > 0.0 ); - } -}); - -tape( 'the function filters an array according to a predicate 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 = filter( x, opts, predicate ); - - expected = new Float64Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - - opts = { - 'dtype': 'float32' - }; - y = filter( x, opts, predicate ); - - expected = new Float32Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat32Array( y.data, expected ), true, 'returns expected value' ); - - t.end(); - - function predicate( z ) { - return ( z > 0.0 ); - } -}); - -tape( 'the function filters an array according to a predicate 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 = filter( x, opts, predicate ); - - expected = new Float64Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - - opts = { - 'dtype': 'float32' - }; - y = filter( x, opts, predicate ); - - expected = new Float32Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat32Array( y.data, expected ), true, 'returns expected value' ); - - t.end(); - - function predicate( z ) { - return ( z > 0.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 = filter( x, predicate, ctx ); - - expected = new Float64Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function predicate( z ) { - this.count += 1; // eslint-disable-line no-invalid-this - return ( z > 0.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 = filter( x, {}, predicate, ctx ); - - expected = new Float64Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function predicate( z ) { - this.count += 1; // eslint-disable-line no-invalid-this - return ( z > 0.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 = filter( x, predicate ); - - expected = new Float64Array([ - 1.0, - 3.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 predicate( z, idx, arr ) { - values.push( z ); - indices.push( idx ); - arrays.push( arr ); - return ( z > 0.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 = filter( x, predicate ); - - expected = new Float64Array([ - 1.0, - 3.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 predicate( z, idx, arr ) { - values.push( z ); - indices.push( idx ); - arrays.push( arr ); - return ( z > 0.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 = filter( x, opts, predicate ); - - expected = new Float64Array([ - 1.0, - 3.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 predicate( z, idx, arr ) { - values.push( z ); - indices.push( idx ); - arrays.push( arr ); - return ( z > 0.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 = filter( x, opts, predicate ); - - expected = new Float64Array([ - 1.0, - 3.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 predicate( z, idx, arr ) { - values.push( z ); - indices.push( idx ); - arrays.push( arr ); - return ( z > 0.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 = filter( x, opts, predicate ); - - expected = new Float64Array([ - 1.0, - 3.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 predicate( z, idx, arr ) { - values.push( z ); - indices.push( idx ); - arrays.push( arr ); - return ( z > 0.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 = filter( x, opts, predicate ); - - expected = new Float64Array([ - 1.0, - 3.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 predicate( z, idx, arr ) { - values.push( z ); - indices.push( idx ); - arrays.push( arr ); - return ( z > 0.0 ); - } -}); From d5758affd73696e4e82fb88efd2734d318d95fd3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 14 Dec 2024 05:03:12 +0000 Subject: [PATCH 03/35] Transform error messages --- lib/main.js | 12 ++++++------ package.json | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/main.js b/lib/main.js index 121a6ce..f66736a 100644 --- a/lib/main.js +++ b/lib/main.js @@ -33,7 +33,7 @@ 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' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -92,7 +92,7 @@ function filter( x, options, predicate, thisArg ) { var v; var i; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray-like object. Value: `%s`.', x ) ); + throw new TypeError( format( 'null5t', x ) ); } if ( arguments.length < 3 ) { clbk = options; @@ -112,11 +112,11 @@ function filter( x, options, predicate, thisArg ) { ctx = thisArg; } if ( !isFunction( clbk ) ) { - throw new TypeError( format( 'invalid argument. Callback argument must be a function. Value: `%s`.', clbk ) ); + throw new TypeError( format( 'null2b', clbk ) ); } if ( hasOpts ) { if ( !isPlainObject( opts ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) ); + throw new TypeError( format( 'null2V', opts ) ); } if ( hasOwnProp( opts, 'dtype' ) ) { dt = opts.dtype; @@ -125,7 +125,7 @@ function filter( x, options, predicate, thisArg ) { } 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 ) ); + throw new TypeError( format( 'null5C', 'order', opts.order ) ); } ord = opts.order; } @@ -136,7 +136,7 @@ function filter( x, options, predicate, thisArg ) { 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 ) ); + throw new TypeError( format( 'nullBf', 'dtype', opts.dtype ) ); } // Resolve the iteration order: if ( ord === void 0 ) { diff --git a/package.json b/package.json index 22065aa..a44b313 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@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/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From e2f791f345fd9f3cb14ec3acd58ec6af641e1ab9 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 14 Dec 2024 05:03:29 +0000 Subject: [PATCH 04/35] Remove files --- index.d.ts | 1612 ---------------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 6459 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index e2a9d07..0000000 --- a/index.d.ts +++ /dev/null @@ -1,1612 +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. -*/ - -// TypeScript Version: 4.1 - -/// - -/* eslint-disable max-lines */ - -import { typedndarray, DataType, Order, float64ndarray, float32ndarray, complex128ndarray, complex64ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, boolndarray, genericndarray } from '@stdlib/types/ndarray'; -import { Complex64, Complex128 } from '@stdlib/types/complex'; - -/** -* Returns a boolean indicating whether an element passes a test. -* -* @returns boolean indicating whether an element passes a test -*/ -type Nullary = ( this: V ) => boolean; - -/** -* Returns a boolean indicating whether an element passes a test. -* -* @param value - current array element -* @returns boolean indicating whether an element passes a test -*/ -type Unary = ( this: V, value: T ) => boolean; - -/** -* Returns a boolean indicating whether an element passes a test. -* -* @param value - current array element -* @param indices - current array element indices -* @returns boolean indicating whether an element passes a test -*/ -type Binary = ( this: V, value: T, indices: Array ) => boolean; - -/** -* Returns a boolean indicating whether an element passes a test. -* -* @param value - current array element -* @param indices - current array element indices -* @param arr - input array -* @returns boolean indicating whether an element passes a test -*/ -type Ternary = ( this: V, value: T, indices: Array, arr: typedndarray ) => boolean; - -/** -* Returns a boolean indicating whether an element passes a test. -* -* @param value - current array element -* @param indices - current array element indices -* @param arr - input array -* @returns boolean indicating whether an element passes a test -*/ -type Predicate = Nullary | Unary | Binary | Ternary; - -/** -* Interface describing "base" function options. -*/ -interface BaseOptions { - /** - * Index iteration order. - * - * ## Notes - * - * - By default, the function iterates over elements according to the layout order of the provided ndarray. Accordingly, for row-major input ndarrays, the last dimension indices increment fastest. For column-major input ndarrays, the first dimension indices increment fastest. To override the inferred order and ensure that indices increment in a specific manor, regardless of the input ndarray's layout order, explicitly set the iteration order. Note, however, that iterating according to an order which does not match that of the input ndarray may, in some circumstances, result in performance degradation due to cache misses. - */ - order?: Order; -} - -/** -* Interface describing function options. -*/ -interface OrderOptions { - /** - * Index iteration order. - * - * ## Notes - * - * - By default, the function iterates over elements according to the layout order of the provided ndarray. Accordingly, for row-major input ndarrays, the last dimension indices increment fastest. For column-major input ndarrays, the first dimension indices increment fastest. To override the inferred order and ensure that indices increment in a specific manor, regardless of the input ndarray's layout order, explicitly set the iteration order. Note, however, that iterating according to an order which does not match that of the input ndarray may, in some circumstances, result in performance degradation due to cache misses. - */ - order: Order; -} - -/** -* Interface describing function options. -*/ -interface Options extends BaseOptions { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: DataType; -} - -/** -* Interface describing function options. -*/ -interface Float64Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'float64'; -} - -/** -* Interface describing function options. -*/ -interface Float32Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'float32'; -} - -/** -* Interface describing function options. -*/ -interface Complex128Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'complex128'; -} - -/** -* Interface describing function options. -*/ -interface Complex64Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'complex64'; -} - -/** -* Interface describing function options. -*/ -interface Int32Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'int32'; -} - -/** -* Interface describing function options. -*/ -interface Int16Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'int16'; -} - -/** -* Interface describing function options. -*/ -interface Int8Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'int8'; -} - -/** -* Interface describing function options. -*/ -interface Uint32Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'uint32'; -} - -/** -* Interface describing function options. -*/ -interface Uint16Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'uint16'; -} - -/** -* Interface describing function options. -*/ -interface Uint8Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'uint8'; -} - -/** -* Interface describing function options. -*/ -interface Uint8COptions extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'uint8c'; -} - -/** -* Interface describing function options. -*/ -interface BoolOptions extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'bool'; -} - -/** -* Interface describing function options. -*/ -interface GenericOptions extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'generic'; -} - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: float64ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): float64ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float32Array = require( '@stdlib/array-float32' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Float32Array( [ 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( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: float32ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): float32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var Complex64Array = require( '@stdlib/array-complex64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* function predicate( z, idx ) { -* return idx[ 0 ] > 0; -* } -* -* var buffer = new Complex64Array( [ 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 = [ 3, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, predicate ); -* // returns -*/ -declare function filter( x: complex64ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): complex64ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* function predicate( z, idx ) { -* return idx[ 0 ] > 0; -* } -* -* var buffer = new Complex128Array( [ 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 = [ 3, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, predicate ); -* // returns -*/ -declare function filter( x: complex128ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): complex128ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Int32Array = require( '@stdlib/array-int32' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Int32Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: int32ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): int32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Int16Array = require( '@stdlib/array-int16' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Int16Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: int16ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): int16ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Int8Array = require( '@stdlib/array-int8' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Int8Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: int8ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): int8ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint32Array = require( '@stdlib/array-uint32' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint32Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint32ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): uint32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint16Array = require( '@stdlib/array-uint16' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint16Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint16ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): uint16ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint8Array = require( '@stdlib/array-uint8' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint8Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint8ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): uint8ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint8ClampedArray( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint8cndarray, predicate: Predicate, thisArg?: ThisParameterType> ): uint8cndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var BooleanArray = require( '@stdlib/array-bool' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* function predicate( z ) { -* return z; -* } -* -* var buffer = new BooleanArray( [ false, true, false, true, false, true, false, true, false, true, false, true ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'bool', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, predicate ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ true, true, true, true ] -*/ -declare function filter( x: boolndarray, predicate: Predicate, thisArg?: ThisParameterType> ): boolndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 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( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: genericndarray, predicate: Predicate, thisArg?: ThisParameterType> ): genericndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: float64ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): float64ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float32Array = require( '@stdlib/array-float32' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Float32Array( [ 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( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: float32ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): float32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var Complex64Array = require( '@stdlib/array-complex64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* function predicate( z, idx ) { -* return idx[ 0 ] > 0; -* } -* -* var buffer = new Complex64Array( [ 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 = [ 3, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, predicate ); -* // returns -*/ -declare function filter( x: complex64ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): complex64ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* function predicate( z, idx ) { -* return idx[ 0 ] > 0; -* } -* -* var buffer = new Complex128Array( [ 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 = [ 3, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, predicate ); -* // returns -*/ -declare function filter( x: complex128ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): complex128ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Int32Array = require( '@stdlib/array-int32' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Int32Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: int32ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): int32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Int16Array = require( '@stdlib/array-int16' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Int16Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: int16ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): int16ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Int8Array = require( '@stdlib/array-int8' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Int8Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: int8ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): int8ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint32Array = require( '@stdlib/array-uint32' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint32Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint32ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): uint32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint16Array = require( '@stdlib/array-uint16' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint16Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint16ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): uint16ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint8Array = require( '@stdlib/array-uint8' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint8Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint8ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): uint8ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint8ClampedArray( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint8cndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): uint8cndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var BooleanArray = require( '@stdlib/array-bool' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* function predicate( z ) { -* return z; -* } -* -* var buffer = new BooleanArray( [ false, true, false, true, false, true, false, true, false, true, false, true ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'bool', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, predicate ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ true, true, true, true ] -*/ -declare function filter( x: boolndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): boolndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 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( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: genericndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): genericndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'float64' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: typedndarray, options: Float64Options, predicate: Predicate, thisArg?: ThisParameterType> ): float64ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'float32' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: typedndarray, options: Float32Options, predicate: Predicate, thisArg?: ThisParameterType> ): float32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* function predicate( z, idx ) { -* return idx[ 0 ] > 0; -* } -* -* var buffer = new Complex128Array( [ 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 = [ 3, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'dtype': 'complex128' -* }; -* var y = filter( x, opts, predicate ); -* // returns -*/ -declare function filter( x: typedndarray, options: Complex128Options, predicate: Predicate, thisArg?: ThisParameterType> ): complex128ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* function predicate( z, idx ) { -* return idx[ 0 ] > 0; -* } -* -* var buffer = new Complex128Array( [ 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 = [ 3, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'dtype': 'complex64' -* }; -* var y = filter( x, opts, predicate ); -* // returns -*/ -declare function filter( x: typedndarray, options: Complex64Options, predicate: Predicate, thisArg?: ThisParameterType> ): complex64ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'int32' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: typedndarray, options: Int32Options, predicate: Predicate, thisArg?: ThisParameterType> ): int32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'int16' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: typedndarray, options: Int16Options, predicate: Predicate, thisArg?: ThisParameterType> ): int16ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'int8' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: typedndarray, options: Int8Options, predicate: Predicate, thisArg?: ThisParameterType> ): int8ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'uint32' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: typedndarray, options: Uint32Options, predicate: Predicate, thisArg?: ThisParameterType> ): uint32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'uint16' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: typedndarray, options: Uint16Options, predicate: Predicate, thisArg?: ThisParameterType> ): uint16ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'uint8' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: typedndarray, options: Uint8Options, predicate: Predicate, thisArg?: ThisParameterType> ): uint8ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'uint8c' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: typedndarray, options: Uint8COptions, predicate: Predicate, thisArg?: ThisParameterType> ): uint8cndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'bool' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ true, true, true, true ] -*/ -declare function filter( x: typedndarray, options: BoolOptions, predicate: Predicate, thisArg?: ThisParameterType> ): boolndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'generic' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: typedndarray, options: GenericOptions, predicate: Predicate, thisArg?: ThisParameterType> ): genericndarray; - - -// EXPORTS // - -export = filter; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index f1c84f4..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import e 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 a from"https://cdn.jsdelivr.net/gh/stdlib-js/blas-base-gcopy@v0.2.1-esm/index.mjs";import h 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,G;if(!e(v))throw new TypeError(h("null5t",v));if(arguments.length<3?w=f:3===arguments.length?s(f)?(w=f,k=b):(g=!0,u=f,w=b):(g=!0,u=f,w=b,k=c),!s(w))throw new TypeError(h("null2b",w));if(g){if(!r(u))throw new TypeError(h("null2V",u));if(q=n(u,"dtype")?u.dtype:m(v),n(u,"order")){if(!t(u.order))throw new TypeError(h("null5C","order",u.order));z=u.order}}else q=m(v);if(null===(E=d(q)))throw new TypeError(h("nullBf","dtype",u.dtype));for(void 0===z&&(z=l(v)),A=o(v),D=p(A),y=A.length,B="row-major"===z?y-1:0,C=i(y),x={length:0},T=-1,G=0;G0&&(C=j(A,z,C,B,C)),F=v.get.apply(v,C),w.call(k,F,C.slice(),v)&&(x.length+=1,x[T+=1]=F);return V=new E(D=x.length),a(D,x,1,V,1),new v.constructor(q,V,[D],[1],0,z)}export{v as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index c68f119..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 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* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate 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 {boolean} [options.order='row-major'] - index iteration order\n* @param {Callback} predicate - predicate function\n* @param {*} [thisArg] - predicate 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 { isPrimitive as isEven } from '@stdlib/assert-is-even';\n* import Float64Array from '@stdlib/array-float64';\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndarray2array from '@stdlib/ndarray-to-array';\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 = filter( x, isEven );\n* // returns \n*\n* var arr = ndarray2array( y );\n* // returns [ 2.0, 4.0, 8.0, 10.0 ]\n*/\nfunction filter( x, options, predicate, thisArg ) {\n\tvar hasOpts;\n\tvar ndims;\n\tvar cache;\n\tvar clbk;\n\tvar opts;\n\tvar ctor;\n\tvar cidx;\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 = predicate;\n\t\t} else {\n\t\t\thasOpts = true;\n\t\t\topts = options;\n\t\t\tclbk = predicate;\n\t\t}\n\t} else {\n\t\thasOpts = true;\n\t\topts = options;\n\t\tclbk = predicate;\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 predicate 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 elements according to a predicate function...\n\tcidx = -1;\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 = x.get.apply( x, idx );\n\t\tif ( clbk.call( ctx, v, idx.slice(), x ) ) {\n\t\t\tcache.length += 1;\n\t\t\tcidx += 1;\n\t\t\tcache[ cidx ] = v;\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 filter;\n"],"names":["filter","x","options","predicate","thisArg","hasOpts","ndims","cache","clbk","opts","ctor","cidx","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","get","apply","call","slice","gcopy","constructor"],"mappings":";;6zCA0EA,SAASA,EAAQC,EAAGC,EAASC,EAAWC,GACvC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEAC,EACAC,EACJ,IAAMC,EAAerB,GACpB,MAAM,IAAIsB,UAAWC,EAAQ,SAAUvB,IAmBxC,GAjBKwB,UAAUC,OAAS,EACvBlB,EAAON,EACyB,IAArBuB,UAAUC,OAChBC,EAAYzB,IAChBM,EAAON,EACPU,EAAMT,IAENE,GAAU,EACVI,EAAOP,EACPM,EAAOL,IAGRE,GAAU,EACVI,EAAOP,EACPM,EAAOL,EACPS,EAAMR,IAEDuB,EAAYnB,GACjB,MAAM,IAAIe,UAAWC,EAAQ,SAAUhB,IAExC,GAAKH,EAAU,CACd,IAAMuB,EAAenB,GACpB,MAAM,IAAIc,UAAWC,EAAQ,SAAUf,IAOxC,GAJCQ,EADIY,EAAYpB,EAAM,SACjBA,EAAKqB,MAELC,EAAU9B,GAEX4B,EAAYpB,EAAM,SAAY,CAClC,IAAMuB,EAASvB,EAAKwB,OACnB,MAAM,IAAIV,UAAWC,EAAQ,SAAU,QAASf,EAAKwB,QAEtDpB,EAAMJ,EAAKwB,KACX,CACH,MACEhB,EAAKc,EAAU9B,GAIhB,GAAc,QADdS,EAAOwB,EAAOjB,IAGb,MAAM,IAAIM,UAAWC,EAAQ,SAAU,QAASf,EAAKqB,QA+BtD,SA5Ba,IAARjB,IACJA,EAAMsB,EAAUlC,IAGjBiB,EAAKkB,EAAUnC,GAGfkB,EAAIkB,EAAOnB,GAGXZ,EAAQY,EAAGQ,OAIVZ,EADY,cAARD,EACEP,EAAQ,EAER,EAGPS,EAAMuB,EAAOhC,GAGbC,EAAQ,CACPmB,OAAU,GAIXf,GAAQ,EACFU,EAAI,EAAGA,EAAIF,EAAGE,IACdA,EAAI,IACRN,EAAMwB,EAAoBrB,EAAIL,EAAKE,EAAKD,EAAKC,IAE9CK,EAAInB,EAAEuC,IAAIC,MAAOxC,EAAGc,GACfP,EAAKkC,KAAM9B,EAAKQ,EAAGL,EAAI4B,QAAS1C,KACpCM,EAAMmB,QAAU,EAEhBnB,EADAI,GAAQ,GACQS,GAelB,OARAJ,EAAM,IAAIN,EAHVS,EAAIZ,EAAMmB,QAMVkB,EAAOzB,EAAGZ,EAAO,EAAGS,EAAK,GAGrB,IAAIf,EAAE4C,YAAa5B,EAAID,EAAK,CAAEG,GAAK,CAAE,GAAK,EAAGN,EAGlD"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 7526b53..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Codestin Search App - - - -
- - - - - From 3082627b2fc112ca31cf003603f098031abf0e6a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 14 Dec 2024 05:03:52 +0000 Subject: [PATCH 05/35] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 49 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 65 +- SECURITY.md | 5 - benchmark/benchmark.1d.js | 150 - benchmark/benchmark.2d.js | 161 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 51 - docs/types/test.ts | 195 - examples/index.js | 38 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 55 - lib/main.js | 199 - package.json | 84 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 892 ---- 44 files changed, 4878 insertions(+), 5313 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.1d.js delete mode 100644 benchmark/benchmark.2d.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 03a0613..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) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 48af73a..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) 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 443f7ec..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: '9 21 * * 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 + + ```
@@ -212,7 +203,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]. @@ -275,11 +266,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-filter/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 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 6958f29..0000000 --- a/benchmark/benchmark.1d.js +++ /dev/null @@ -1,150 +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 filter = require( './../lib' ); - - -// VARIABLES // - -var xtypes = [ 'generic' ]; -var ytypes = [ 'float64' ]; -var orders = [ 'row-major', 'column-major' ]; - - -// FUNCTIONS // - -/** -* Predicate function. -* -* @private -* @param {number} value - array element -* @param {NonNegativeIntegerArray} indices - element indices -* @param {ndarray} arr - input array -* @returns {boolean} result -*/ -function predicate( value ) { - return value > 0.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 = filter( x, opts, predicate ); - 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 e848b15..0000000 --- a/benchmark/benchmark.2d.js +++ /dev/null @@ -1,161 +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 map = require( './../lib' ); - - -// VARIABLES // - -var xtypes = [ 'generic' ]; -var ytypes = [ 'float64' ]; -var orders = [ 'row-major', 'column-major' ]; - - -// FUNCTIONS // - -/** -* Predicate function. -* -* @private -* @param {number} value - array element -* @param {NonNegativeIntegerArray} indices - element indices -* @param {ndarray} arr - input array -* @returns {boolean} result -*/ -function predicate( value ) { - return value > 0.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 = map( x, opts, predicate ); - 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 51e4f91..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" -%% click B href "https://github.com/stdlib-js/ndarray-filter/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-filter/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-filter/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-filter/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-filter/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/filter -[production-url]: https://github.com/stdlib-js/ndarray-filter/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-filter/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-filter/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-filter/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-filter/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-filter/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-filter/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 aafb9cb..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import filter from '../docs/types/index'; -export = filter; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 558b3a7..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var V=function(r,a){return function(){return a||r((a={exports:{}}).exports,a),a.exports}};var k=V(function(K,j){"use strict";var C=require("@stdlib/assert-is-plain-object"),O=require("@stdlib/assert-is-function"),F=require("@stdlib/assert-is-ndarray-like"),P=require("@stdlib/ndarray-base-assert-is-order"),T=require("@stdlib/assert-has-own-property"),D=require("@stdlib/ndarray-base-buffer-ctors"),I=require("@stdlib/array-base-zeros"),L=require("@stdlib/ndarray-shape"),E=require("@stdlib/ndarray-dtype"),N=require("@stdlib/ndarray-order"),S=require("@stdlib/ndarray-base-numel"),A=require("@stdlib/ndarray-base-next-cartesian-index").assign,B=require("@stdlib/blas-base-gcopy"),v=require("@stdlib/string-format");function G(r,a,g,z){var c,f,o,i,e,p,m,h,t,y,n,q,s,l,u,b,w,d;if(!F(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?O(a)?(i=a,h=g):(c=!0,e=a,i=g):(c=!0,e=a,i=g,h=z),!O(i))throw new TypeError(v("invalid argument. Callback argument must be a function. Value: `%s`.",i));if(c){if(!C(e))throw new TypeError(v("invalid argument. Options argument must be an object. Value: `%s`.",e));if(T(e,"dtype")?s=e.dtype:s=E(r),T(e,"order")){if(!P(e.order))throw new TypeError(v("invalid option. `%s` option must be a recognized order. Option: `%s`.","order",e.order));t=e.order}}else s=E(r);if(p=D(s),p===null)throw new TypeError(v("invalid option. `%s` option must be a recognized data type. Option: `%s`.","dtype",e.dtype));for(t===void 0&&(t=N(r)),l=L(r),u=S(l),f=l.length,t==="row-major"?y=f-1:y=0,n=I(f),o={length:0},m=-1,d=0;d0&&(n=A(l,t,n,y,n)),w=r.get.apply(r,n),i.call(h,w,n.slice(),r)&&(o.length+=1,m+=1,o[m]=w);return u=o.length,q=new p(u),B(u,o,1,q,1),b=new r.constructor(s,q,[u],[1],0,t),b}j.exports=G});var H=k();module.exports=H; -/** -* @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 92b21c3..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* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate 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 {boolean} [options.order='row-major'] - index iteration order\n* @param {Callback} predicate - predicate function\n* @param {*} [thisArg] - predicate 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 isEven = require( '@stdlib/assert-is-even' ).isPrimitive;\n* var Float64Array = require( '@stdlib/array-float64' );\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\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 = filter( x, isEven );\n* // returns \n*\n* var arr = ndarray2array( y );\n* // returns [ 2.0, 4.0, 8.0, 10.0 ]\n*/\nfunction filter( x, options, predicate, thisArg ) {\n\tvar hasOpts;\n\tvar ndims;\n\tvar cache;\n\tvar clbk;\n\tvar opts;\n\tvar ctor;\n\tvar cidx;\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 = predicate;\n\t\t} else {\n\t\t\thasOpts = true;\n\t\t\topts = options;\n\t\t\tclbk = predicate;\n\t\t}\n\t} else {\n\t\thasOpts = true;\n\t\topts = options;\n\t\tclbk = predicate;\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 predicate 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 elements according to a predicate function...\n\tcidx = -1;\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 = x.get.apply( x, idx );\n\t\tif ( clbk.call( ctx, v, idx.slice(), x ) ) {\n\t\t\tcache.length += 1;\n\t\t\tcidx += 1;\n\t\t\tcache[ cidx ] = v;\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 = filter;\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* Return a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function.\n*\n* @module @stdlib/ndarray-filter\n*\n* @example\n* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive;\n* var Float64Array = require( '@stdlib/array-float64' );\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var filter = require( '@stdlib/ndarray-filter' );\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 = filter( x, isEven );\n* // returns \n*\n* var arr = ndarray2array( y );\n* // returns [ 2.0, 4.0, 8.0, 10.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,EAuC9C,SAASC,EAAQC,EAAGC,EAASC,EAAWC,EAAU,CACjD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,GAAK,CAAClC,EAAea,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,gFAAiFE,CAAE,CAAE,EAmBnH,GAjBK,UAAU,OAAS,EACvBO,EAAON,EACI,UAAU,SAAW,EAC3Bf,EAAYe,CAAQ,GACxBM,EAAON,EACPU,EAAMT,IAENE,EAAU,GACVI,EAAOP,EACPM,EAAOL,IAGRE,EAAU,GACVI,EAAOP,EACPM,EAAOL,EACPS,EAAMR,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,EAC9BQ,EAAKR,EAAK,MAEVQ,EAAKvB,EAAUO,CAAE,EAEbX,EAAYmB,EAAM,OAAQ,EAAI,CAClC,GAAK,CAACpB,EAASoB,EAAK,KAAM,EACzB,MAAM,IAAI,UAAWV,EAAQ,wEAAyE,QAASU,EAAK,KAAM,CAAE,EAE7HI,EAAMJ,EAAK,KACZ,CACD,MACCQ,EAAKvB,EAAUO,CAAE,EAIlB,GADAS,EAAOnB,EAAO0B,CAAG,EACZP,IAAS,KAEb,MAAM,IAAI,UAAWX,EAAQ,4EAA6E,QAASU,EAAK,KAAM,CAAE,EA+BjI,IA5BKI,IAAQ,SACZA,EAAMlB,EAAUM,CAAE,GAGnBiB,EAAKzB,EAAUQ,CAAE,EAGjBkB,EAAIvB,EAAOsB,CAAG,EAGdZ,EAAQY,EAAG,OAGNL,IAAQ,YACZC,EAAMR,EAAQ,EAEdQ,EAAM,EAGPC,EAAMvB,EAAOc,CAAM,EAGnBC,EAAQ,CACP,OAAU,CACX,EAGAI,EAAO,GACDW,EAAI,EAAGA,EAAIH,EAAGG,IACdA,EAAI,IACRP,EAAMlB,EAAoBqB,EAAIL,EAAKE,EAAKD,EAAKC,CAAI,GAElDM,EAAIpB,EAAE,IAAI,MAAOA,EAAGc,CAAI,EACnBP,EAAK,KAAMI,EAAKS,EAAGN,EAAI,MAAM,EAAGd,CAAE,IACtCM,EAAM,QAAU,EAChBI,GAAQ,EACRJ,EAAOI,CAAK,EAAIU,GAIlB,OAAAF,EAAIZ,EAAM,OAGVS,EAAM,IAAIN,EAAMS,CAAE,EAGlBrB,EAAOqB,EAAGZ,EAAO,EAAGS,EAAK,CAAE,EAG3BI,EAAI,IAAInB,EAAE,YAAagB,EAAID,EAAK,CAAEG,CAAE,EAAG,CAAE,CAAE,EAAG,EAAGN,CAAI,EAE9CO,CACR,CAKAnC,EAAO,QAAUe,ICrJjB,IAAIuB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isPlainObject", "isFunction", "isndarrayLike", "isOrder", "hasOwnProp", "ctors", "zeros", "getShape", "getDType", "getOrder", "numel", "nextCartesianIndex", "gcopy", "format", "filter", "x", "options", "predicate", "thisArg", "hasOpts", "ndims", "cache", "clbk", "opts", "ctor", "cidx", "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 8ed7071..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,51 +0,0 @@ - -{{alias}}( x[, options], predicate[, thisArg] ) - Returns a shallow copy of an ndarray containing only those elements which - pass a test implemented by a predicate function. - - The predicate function is provided the following arguments: - - - value: current array element. - - indices: current array element indices. - - arr: the input 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 manor, 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'. - - predicate: Function - Predicate function. - - thisArg: any (optional) - Predicate function execution context. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ); - > function f( v ) { return v > 2.0; }; - > var y = {{alias}}( x, f ); - > {{alias:@stdlib/ndarray/to-array}}( y ) - [ 3.0, 4.0 ] - - See Also - -------- diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 046dffb..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,195 +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 empty = require( '@stdlib/ndarray-base-empty' ); -import zeros = require( '@stdlib/ndarray-base-zeros' ); -import filter = require( './index' ); - -/** -* Predicate function. -* -* @param x - input value -* @returns result -*/ -function predicate( x: any ): boolean { - return Boolean( x ); -} - -// The function returns an ndarray... -{ - const sh = [ 2, 2 ]; - const ord = 'row-major'; - - filter( zeros( 'float64', sh, ord ), predicate ); // $ExpectType float64ndarray - filter( zeros( 'float64', sh, ord ), predicate, {} ); // $ExpectType float64ndarray - filter( zeros( 'float32', sh, ord ), predicate ); // $ExpectType float32ndarray - filter( zeros( 'float32', sh, ord ), predicate, {} ); // $ExpectType float32ndarray - filter( zeros( 'complex64', sh, ord ), predicate ); // $ExpectType complex64ndarray - filter( zeros( 'complex64', sh, ord ), predicate, {} ); // $ExpectType complex64ndarray - filter( zeros( 'complex128', sh, ord ), predicate ); // $ExpectType complex128ndarray - filter( zeros( 'complex128', sh, ord ), predicate, {} ); // $ExpectType complex128ndarray - filter( zeros( 'int32', sh, ord ), predicate ); // $ExpectType int32ndarray - filter( zeros( 'int32', sh, ord ), predicate, {} ); // $ExpectType int32ndarray - filter( zeros( 'int16', sh, ord ), predicate ); // $ExpectType int16ndarray - filter( zeros( 'int16', sh, ord ), predicate, {} ); // $ExpectType int16ndarray - filter( zeros( 'int8', sh, ord ), predicate ); // $ExpectType int8ndarray - filter( zeros( 'int8', sh, ord ), predicate, {} ); // $ExpectType int8ndarray - filter( zeros( 'uint32', sh, ord ), predicate ); // $ExpectType uint32ndarray - filter( zeros( 'uint32', sh, ord ), predicate, {} ); // $ExpectType uint32ndarray - filter( zeros( 'uint16', sh, ord ), predicate ); // $ExpectType uint16ndarray - filter( zeros( 'uint16', sh, ord ), predicate, {} ); // $ExpectType uint16ndarray - filter( zeros( 'uint8', sh, ord ), predicate ); // $ExpectType uint8ndarray - filter( zeros( 'uint8', sh, ord ), predicate, {} ); // $ExpectType uint8ndarray - filter( zeros( 'uint8c', sh, ord ), predicate ); // $ExpectType uint8cndarray - filter( zeros( 'uint8c', sh, ord ), predicate, {} ); // $ExpectType uint8cndarray - filter( empty( 'bool', sh, ord ), predicate ); // $ExpectType boolndarray - filter( empty( 'bool', sh, ord ), predicate, {} ); // $ExpectType boolndarray - filter( zeros( 'generic', sh, ord ), predicate ); // $ExpectType genericndarray - filter( zeros( 'generic', sh, ord ), predicate, {} ); // $ExpectType genericndarray - - - filter( zeros( 'generic', sh, ord ), { 'dtype': 'float64' }, predicate ); // $ExpectType float64ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'float64' }, predicate, {} ); // $ExpectType float64ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'float32' }, predicate ); // $ExpectType float32ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'float32' }, predicate, {} ); // $ExpectType float32ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'complex64' }, predicate ); // $ExpectType complex64ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'complex64' }, predicate, {} ); // $ExpectType complex64ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'complex128' }, predicate ); // $ExpectType complex128ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'complex128' }, predicate, {} ); // $ExpectType complex128ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'int32' }, predicate ); // $ExpectType int32ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'int32' }, predicate, {} ); // $ExpectType int32ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'int16' }, predicate ); // $ExpectType int16ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'int16' }, predicate, {} ); // $ExpectType int16ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'int8' }, predicate ); // $ExpectType int8ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'int8' }, predicate, {} ); // $ExpectType int8ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint32' }, predicate ); // $ExpectType uint32ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint32' }, predicate, {} ); // $ExpectType uint32ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint16' }, predicate ); // $ExpectType uint16ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint16' }, predicate, {} ); // $ExpectType uint16ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint8' }, predicate ); // $ExpectType uint8ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint8' }, predicate, {} ); // $ExpectType uint8ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint8c' }, predicate ); // $ExpectType uint8cndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint8c' }, predicate, {} ); // $ExpectType uint8cndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'bool' }, predicate ); // $ExpectType boolndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'bool' }, predicate, {} ); // $ExpectType boolndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'generic' }, predicate ); // $ExpectType genericndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'generic' }, predicate, {} ); // $ExpectType genericndarray - - - filter( zeros( 'float64', sh, ord ), { 'order': ord }, predicate ); // $ExpectType float64ndarray - filter( zeros( 'float64', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType float64ndarray - filter( zeros( 'float32', sh, ord ), { 'order': ord }, predicate ); // $ExpectType float32ndarray - filter( zeros( 'float32', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType float32ndarray - filter( zeros( 'complex64', sh, ord ), { 'order': ord }, predicate ); // $ExpectType complex64ndarray - filter( zeros( 'complex64', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType complex64ndarray - filter( zeros( 'complex128', sh, ord ), { 'order': ord }, predicate ); // $ExpectType complex128ndarray - filter( zeros( 'complex128', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType complex128ndarray - filter( zeros( 'int32', sh, ord ), { 'order': ord }, predicate ); // $ExpectType int32ndarray - filter( zeros( 'int32', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType int32ndarray - filter( zeros( 'int16', sh, ord ), { 'order': ord }, predicate ); // $ExpectType int16ndarray - filter( zeros( 'int16', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType int16ndarray - filter( zeros( 'int8', sh, ord ), { 'order': ord }, predicate ); // $ExpectType int8ndarray - filter( zeros( 'int8', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType int8ndarray - filter( zeros( 'uint32', sh, ord ), { 'order': ord }, predicate ); // $ExpectType uint32ndarray - filter( zeros( 'uint32', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType uint32ndarray - filter( zeros( 'uint16', sh, ord ), { 'order': ord }, predicate ); // $ExpectType uint16ndarray - filter( zeros( 'uint16', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType uint16ndarray - filter( zeros( 'uint8', sh, ord ), { 'order': ord }, predicate ); // $ExpectType uint8ndarray - filter( zeros( 'uint8', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType uint8ndarray - filter( zeros( 'uint8c', sh, ord ), { 'order': ord }, predicate ); // $ExpectType uint8cndarray - filter( zeros( 'uint8c', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType uint8cndarray - filter( empty( 'bool', sh, ord ), { 'order': ord }, predicate ); // $ExpectType boolndarray - filter( empty( 'bool', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType boolndarray - filter( zeros( 'generic', sh, ord ), { 'order': ord }, predicate ); // $ExpectType genericndarray - filter( zeros( 'generic', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType genericndarray - -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - filter( 5, predicate ); // $ExpectError - filter( true, predicate ); // $ExpectError - filter( false, predicate ); // $ExpectError - filter( null, predicate ); // $ExpectError - filter( undefined, predicate ); // $ExpectError - filter( {}, predicate ); // $ExpectError - filter( [ 1 ], predicate ); // $ExpectError - filter( ( x: number ): number => x, predicate ); // $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' ); - - filter( x, '5' ); // $ExpectError - filter( x, true ); // $ExpectError - filter( x, false ); // $ExpectError - filter( x, null ); // $ExpectError - filter( x, undefined ); // $ExpectError - filter( x, {} ); // $ExpectError - filter( 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' ); - - filter( x, '10', predicate, {} ); // $ExpectError - filter( x, 10, predicate, {} ); // $ExpectError - filter( x, false, predicate, {} ); // $ExpectError - filter( x, true, predicate, {} ); // $ExpectError - filter( x, [], predicate, {} ); // $ExpectError - filter( x, ( x: number ): number => x, predicate, {} ); // $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' ); - - filter( x, { 'dtype': '10' }, predicate ); // $ExpectError - filter( x, { 'dtype': 10 }, predicate ); // $ExpectError - filter( x, { 'dtype': null }, predicate ); // $ExpectError - filter( x, { 'dtype': false }, predicate ); // $ExpectError - filter( x, { 'dtype': true }, predicate ); // $ExpectError - filter( x, { 'dtype': [] }, predicate ); // $ExpectError - filter( x, { 'dtype': {} }, predicate ); // $ExpectError - filter( x, { 'dtype': ( x: number ): number => x }, predicate ); // $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' ); - - filter( x, { 'order': '10' }, predicate ); // $ExpectError - filter( x, { 'order': 10 }, predicate ); // $ExpectError - filter( x, { 'order': null }, predicate ); // $ExpectError - filter( x, { 'order': false }, predicate ); // $ExpectError - filter( x, { 'order': true }, predicate ); // $ExpectError - filter( x, { 'order': [] }, predicate ); // $ExpectError - filter( x, { 'order': {} }, predicate ); // $ExpectError - filter( x, { 'order': ( x: number ): number => x }, predicate ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - filter(); // $ExpectError - filter( zeros( 'float64', [ 2, 2 ], 'row-major' ) ); // $ExpectError - filter( 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 e2dd6cb..0000000 --- a/examples/index.js +++ /dev/null @@ -1,38 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var array = require( '@stdlib/ndarray-array' ); -var isPositive = require( '@stdlib/assert-is-positive-number' ).isPrimitive; -var filter = require( './../lib' ); - -var buffer = discreteUniform( 10, -100, 100, { - 'dtype': 'generic' -}); -var x = array( buffer, { - 'shape': [ 5, 2 ], - 'dtype': 'generic' -}); -console.log( ndarray2array( x ) ); - -var y = filter( x, naryFunction( isPositive, 1 ) ); -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 a39a064..e2a9d07 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..f1c84f4 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import e 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 a from"https://cdn.jsdelivr.net/gh/stdlib-js/blas-base-gcopy@v0.2.1-esm/index.mjs";import h 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,G;if(!e(v))throw new TypeError(h("null5t",v));if(arguments.length<3?w=f:3===arguments.length?s(f)?(w=f,k=b):(g=!0,u=f,w=b):(g=!0,u=f,w=b,k=c),!s(w))throw new TypeError(h("null2b",w));if(g){if(!r(u))throw new TypeError(h("null2V",u));if(q=n(u,"dtype")?u.dtype:m(v),n(u,"order")){if(!t(u.order))throw new TypeError(h("null5C","order",u.order));z=u.order}}else q=m(v);if(null===(E=d(q)))throw new TypeError(h("nullBf","dtype",u.dtype));for(void 0===z&&(z=l(v)),A=o(v),D=p(A),y=A.length,B="row-major"===z?y-1:0,C=i(y),x={length:0},T=-1,G=0;G0&&(C=j(A,z,C,B,C)),F=v.get.apply(v,C),w.call(k,F,C.slice(),v)&&(x.length+=1,x[T+=1]=F);return V=new E(D=x.length),a(D,x,1,V,1),new v.constructor(q,V,[D],[1],0,z)}export{v as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..c68f119 --- /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* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate 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 {boolean} [options.order='row-major'] - index iteration order\n* @param {Callback} predicate - predicate function\n* @param {*} [thisArg] - predicate 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 { isPrimitive as isEven } from '@stdlib/assert-is-even';\n* import Float64Array from '@stdlib/array-float64';\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndarray2array from '@stdlib/ndarray-to-array';\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 = filter( x, isEven );\n* // returns \n*\n* var arr = ndarray2array( y );\n* // returns [ 2.0, 4.0, 8.0, 10.0 ]\n*/\nfunction filter( x, options, predicate, thisArg ) {\n\tvar hasOpts;\n\tvar ndims;\n\tvar cache;\n\tvar clbk;\n\tvar opts;\n\tvar ctor;\n\tvar cidx;\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 = predicate;\n\t\t} else {\n\t\t\thasOpts = true;\n\t\t\topts = options;\n\t\t\tclbk = predicate;\n\t\t}\n\t} else {\n\t\thasOpts = true;\n\t\topts = options;\n\t\tclbk = predicate;\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 predicate 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 elements according to a predicate function...\n\tcidx = -1;\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 = x.get.apply( x, idx );\n\t\tif ( clbk.call( ctx, v, idx.slice(), x ) ) {\n\t\t\tcache.length += 1;\n\t\t\tcidx += 1;\n\t\t\tcache[ cidx ] = v;\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 filter;\n"],"names":["filter","x","options","predicate","thisArg","hasOpts","ndims","cache","clbk","opts","ctor","cidx","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","get","apply","call","slice","gcopy","constructor"],"mappings":";;6zCA0EA,SAASA,EAAQC,EAAGC,EAASC,EAAWC,GACvC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEAC,EACAC,EACJ,IAAMC,EAAerB,GACpB,MAAM,IAAIsB,UAAWC,EAAQ,SAAUvB,IAmBxC,GAjBKwB,UAAUC,OAAS,EACvBlB,EAAON,EACyB,IAArBuB,UAAUC,OAChBC,EAAYzB,IAChBM,EAAON,EACPU,EAAMT,IAENE,GAAU,EACVI,EAAOP,EACPM,EAAOL,IAGRE,GAAU,EACVI,EAAOP,EACPM,EAAOL,EACPS,EAAMR,IAEDuB,EAAYnB,GACjB,MAAM,IAAIe,UAAWC,EAAQ,SAAUhB,IAExC,GAAKH,EAAU,CACd,IAAMuB,EAAenB,GACpB,MAAM,IAAIc,UAAWC,EAAQ,SAAUf,IAOxC,GAJCQ,EADIY,EAAYpB,EAAM,SACjBA,EAAKqB,MAELC,EAAU9B,GAEX4B,EAAYpB,EAAM,SAAY,CAClC,IAAMuB,EAASvB,EAAKwB,OACnB,MAAM,IAAIV,UAAWC,EAAQ,SAAU,QAASf,EAAKwB,QAEtDpB,EAAMJ,EAAKwB,KACX,CACH,MACEhB,EAAKc,EAAU9B,GAIhB,GAAc,QADdS,EAAOwB,EAAOjB,IAGb,MAAM,IAAIM,UAAWC,EAAQ,SAAU,QAASf,EAAKqB,QA+BtD,SA5Ba,IAARjB,IACJA,EAAMsB,EAAUlC,IAGjBiB,EAAKkB,EAAUnC,GAGfkB,EAAIkB,EAAOnB,GAGXZ,EAAQY,EAAGQ,OAIVZ,EADY,cAARD,EACEP,EAAQ,EAER,EAGPS,EAAMuB,EAAOhC,GAGbC,EAAQ,CACPmB,OAAU,GAIXf,GAAQ,EACFU,EAAI,EAAGA,EAAIF,EAAGE,IACdA,EAAI,IACRN,EAAMwB,EAAoBrB,EAAIL,EAAKE,EAAKD,EAAKC,IAE9CK,EAAInB,EAAEuC,IAAIC,MAAOxC,EAAGc,GACfP,EAAKkC,KAAM9B,EAAKQ,EAAGL,EAAI4B,QAAS1C,KACpCM,EAAMmB,QAAU,EAEhBnB,EADAI,GAAQ,GACQS,GAelB,OARAJ,EAAM,IAAIN,EAHVS,EAAIZ,EAAMmB,QAMVkB,EAAOzB,EAAGZ,EAAO,EAAGS,EAAK,GAGrB,IAAIf,EAAE4C,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 46f5998..0000000 --- a/lib/index.js +++ /dev/null @@ -1,55 +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'; - -/** -* Return a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @module @stdlib/ndarray-filter -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var filter = require( '@stdlib/ndarray-filter' ); -* -* 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 = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.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 f66736a..0000000 --- a/lib/main.js +++ /dev/null @@ -1,199 +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/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param {ndarray} x - input ndarray -* @param {Options} [options] - function options -* @param {string} [options.dtype] - output array data type -* @param {boolean} [options.order='row-major'] - index iteration order -* @param {Callback} predicate - predicate function -* @param {*} [thisArg] - predicate 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 isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -function filter( x, options, predicate, thisArg ) { - var hasOpts; - var ndims; - var cache; - var clbk; - var opts; - var ctor; - var cidx; - 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( 'null5t', x ) ); - } - if ( arguments.length < 3 ) { - clbk = options; - } else if ( arguments.length === 3 ) { - if ( isFunction( options ) ) { - clbk = options; - ctx = predicate; - } else { - hasOpts = true; - opts = options; - clbk = predicate; - } - } else { - hasOpts = true; - opts = options; - clbk = predicate; - ctx = thisArg; - } - if ( !isFunction( clbk ) ) { - throw new TypeError( format( 'null2b', clbk ) ); - } - if ( hasOpts ) { - if ( !isPlainObject( opts ) ) { - throw new TypeError( format( 'null2V', opts ) ); - } - if ( hasOwnProp( opts, 'dtype' ) ) { - dt = opts.dtype; - } else { - dt = getDType( x ); - } - if ( hasOwnProp( opts, 'order' ) ) { - if ( !isOrder( opts.order ) ) { - throw new TypeError( format( 'null5C', '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( 'nullBf', '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 predicate 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 elements according to a predicate function... - cidx = -1; - for ( i = 0; i < N; i++ ) { - if ( i > 0 ) { - idx = nextCartesianIndex( sh, ord, idx, dim, idx ); - } - v = x.get.apply( x, idx ); - if ( clbk.call( ctx, v, idx.slice(), x ) ) { - cache.length += 1; - cidx += 1; - cache[ cidx ] = v; - } - } - // 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 = filter; diff --git a/package.json b/package.json index a44b313..2473eda 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Return a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate 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,62 +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/error-tools-fmtprodmsg": "^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-positive-number": "^0.2.2", - "@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", - "@stdlib/utils-nary-function": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "strided", @@ -104,7 +25,6 @@ "select", "take" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..7526b53 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Codestin Search App + + + +
+ + + + + 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 3bea6b3..0000000 --- a/test/test.js +++ /dev/null @@ -1,892 +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 filter = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof filter, '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() { - filter( value, predicate ); - }; - } - - function predicate( z ) { - return ( z > 0.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() { - filter( 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() { - filter( 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() { - filter( x, value, predicate ); - }; - } - - function predicate( z ) { - return ( z > 0.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 - }; - filter( x, opts, predicate ); - }; - } - - function predicate( z ) { - return ( z > 0.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 - }; - filter( x, opts, predicate ); - }; - } - - function predicate( z ) { - return ( z > 0.0 ); - } -}); - -tape( 'the function filters an array according to a predicate 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 = filter( x, predicate ); - - expected = new Float64Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - - t.end(); - - function predicate( z ) { - return ( z > 0.0 ); - } -}); - -tape( 'the function filters an array according to a predicate 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 = filter( x, predicate ); - - expected = new Float64Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - - t.end(); - - function predicate( z ) { - return ( z > 0.0 ); - } -}); - -tape( 'the function filters an array according to a predicate 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 = filter( x, opts, predicate ); - - expected = new Float64Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - - opts = { - 'dtype': 'float32' - }; - y = filter( x, opts, predicate ); - - expected = new Float32Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat32Array( y.data, expected ), true, 'returns expected value' ); - - t.end(); - - function predicate( z ) { - return ( z > 0.0 ); - } -}); - -tape( 'the function filters an array according to a predicate 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 = filter( x, opts, predicate ); - - expected = new Float64Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - - opts = { - 'dtype': 'float32' - }; - y = filter( x, opts, predicate ); - - expected = new Float32Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat32Array( y.data, expected ), true, 'returns expected value' ); - - t.end(); - - function predicate( z ) { - return ( z > 0.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 = filter( x, predicate, ctx ); - - expected = new Float64Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function predicate( z ) { - this.count += 1; // eslint-disable-line no-invalid-this - return ( z > 0.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 = filter( x, {}, predicate, ctx ); - - expected = new Float64Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function predicate( z ) { - this.count += 1; // eslint-disable-line no-invalid-this - return ( z > 0.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 = filter( x, predicate ); - - expected = new Float64Array([ - 1.0, - 3.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 predicate( z, idx, arr ) { - values.push( z ); - indices.push( idx ); - arrays.push( arr ); - return ( z > 0.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 = filter( x, predicate ); - - expected = new Float64Array([ - 1.0, - 3.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 predicate( z, idx, arr ) { - values.push( z ); - indices.push( idx ); - arrays.push( arr ); - return ( z > 0.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 = filter( x, opts, predicate ); - - expected = new Float64Array([ - 1.0, - 3.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 predicate( z, idx, arr ) { - values.push( z ); - indices.push( idx ); - arrays.push( arr ); - return ( z > 0.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 = filter( x, opts, predicate ); - - expected = new Float64Array([ - 1.0, - 3.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 predicate( z, idx, arr ) { - values.push( z ); - indices.push( idx ); - arrays.push( arr ); - return ( z > 0.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 = filter( x, opts, predicate ); - - expected = new Float64Array([ - 1.0, - 3.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 predicate( z, idx, arr ) { - values.push( z ); - indices.push( idx ); - arrays.push( arr ); - return ( z > 0.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 = filter( x, opts, predicate ); - - expected = new Float64Array([ - 1.0, - 3.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 predicate( z, idx, arr ) { - values.push( z ); - indices.push( idx ); - arrays.push( arr ); - return ( z > 0.0 ); - } -}); From 91573903cee84c812faf51b46574c4e1b487f070 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 14 Dec 2024 05:09:05 +0000 Subject: [PATCH 06/35] Transform error messages --- lib/main.js | 12 ++++++------ package.json | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/main.js b/lib/main.js index 121a6ce..f66736a 100644 --- a/lib/main.js +++ b/lib/main.js @@ -33,7 +33,7 @@ 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' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -92,7 +92,7 @@ function filter( x, options, predicate, thisArg ) { var v; var i; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray-like object. Value: `%s`.', x ) ); + throw new TypeError( format( 'null5t', x ) ); } if ( arguments.length < 3 ) { clbk = options; @@ -112,11 +112,11 @@ function filter( x, options, predicate, thisArg ) { ctx = thisArg; } if ( !isFunction( clbk ) ) { - throw new TypeError( format( 'invalid argument. Callback argument must be a function. Value: `%s`.', clbk ) ); + throw new TypeError( format( 'null2b', clbk ) ); } if ( hasOpts ) { if ( !isPlainObject( opts ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) ); + throw new TypeError( format( 'null2V', opts ) ); } if ( hasOwnProp( opts, 'dtype' ) ) { dt = opts.dtype; @@ -125,7 +125,7 @@ function filter( x, options, predicate, thisArg ) { } 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 ) ); + throw new TypeError( format( 'null5C', 'order', opts.order ) ); } ord = opts.order; } @@ -136,7 +136,7 @@ function filter( x, options, predicate, thisArg ) { 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 ) ); + throw new TypeError( format( 'nullBf', 'dtype', opts.dtype ) ); } // Resolve the iteration order: if ( ord === void 0 ) { diff --git a/package.json b/package.json index 22065aa..a44b313 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@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/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From 5fcc77f31d79d448169a92b742b080a4d20b8ef1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 14 Dec 2024 05:10:19 +0000 Subject: [PATCH 07/35] Remove files --- index.d.ts | 1612 ---------------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 6459 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index e2a9d07..0000000 --- a/index.d.ts +++ /dev/null @@ -1,1612 +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. -*/ - -// TypeScript Version: 4.1 - -/// - -/* eslint-disable max-lines */ - -import { typedndarray, DataType, Order, float64ndarray, float32ndarray, complex128ndarray, complex64ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, boolndarray, genericndarray } from '@stdlib/types/ndarray'; -import { Complex64, Complex128 } from '@stdlib/types/complex'; - -/** -* Returns a boolean indicating whether an element passes a test. -* -* @returns boolean indicating whether an element passes a test -*/ -type Nullary = ( this: V ) => boolean; - -/** -* Returns a boolean indicating whether an element passes a test. -* -* @param value - current array element -* @returns boolean indicating whether an element passes a test -*/ -type Unary = ( this: V, value: T ) => boolean; - -/** -* Returns a boolean indicating whether an element passes a test. -* -* @param value - current array element -* @param indices - current array element indices -* @returns boolean indicating whether an element passes a test -*/ -type Binary = ( this: V, value: T, indices: Array ) => boolean; - -/** -* Returns a boolean indicating whether an element passes a test. -* -* @param value - current array element -* @param indices - current array element indices -* @param arr - input array -* @returns boolean indicating whether an element passes a test -*/ -type Ternary = ( this: V, value: T, indices: Array, arr: typedndarray ) => boolean; - -/** -* Returns a boolean indicating whether an element passes a test. -* -* @param value - current array element -* @param indices - current array element indices -* @param arr - input array -* @returns boolean indicating whether an element passes a test -*/ -type Predicate = Nullary | Unary | Binary | Ternary; - -/** -* Interface describing "base" function options. -*/ -interface BaseOptions { - /** - * Index iteration order. - * - * ## Notes - * - * - By default, the function iterates over elements according to the layout order of the provided ndarray. Accordingly, for row-major input ndarrays, the last dimension indices increment fastest. For column-major input ndarrays, the first dimension indices increment fastest. To override the inferred order and ensure that indices increment in a specific manor, regardless of the input ndarray's layout order, explicitly set the iteration order. Note, however, that iterating according to an order which does not match that of the input ndarray may, in some circumstances, result in performance degradation due to cache misses. - */ - order?: Order; -} - -/** -* Interface describing function options. -*/ -interface OrderOptions { - /** - * Index iteration order. - * - * ## Notes - * - * - By default, the function iterates over elements according to the layout order of the provided ndarray. Accordingly, for row-major input ndarrays, the last dimension indices increment fastest. For column-major input ndarrays, the first dimension indices increment fastest. To override the inferred order and ensure that indices increment in a specific manor, regardless of the input ndarray's layout order, explicitly set the iteration order. Note, however, that iterating according to an order which does not match that of the input ndarray may, in some circumstances, result in performance degradation due to cache misses. - */ - order: Order; -} - -/** -* Interface describing function options. -*/ -interface Options extends BaseOptions { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: DataType; -} - -/** -* Interface describing function options. -*/ -interface Float64Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'float64'; -} - -/** -* Interface describing function options. -*/ -interface Float32Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'float32'; -} - -/** -* Interface describing function options. -*/ -interface Complex128Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'complex128'; -} - -/** -* Interface describing function options. -*/ -interface Complex64Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'complex64'; -} - -/** -* Interface describing function options. -*/ -interface Int32Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'int32'; -} - -/** -* Interface describing function options. -*/ -interface Int16Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'int16'; -} - -/** -* Interface describing function options. -*/ -interface Int8Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'int8'; -} - -/** -* Interface describing function options. -*/ -interface Uint32Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'uint32'; -} - -/** -* Interface describing function options. -*/ -interface Uint16Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'uint16'; -} - -/** -* Interface describing function options. -*/ -interface Uint8Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'uint8'; -} - -/** -* Interface describing function options. -*/ -interface Uint8COptions extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'uint8c'; -} - -/** -* Interface describing function options. -*/ -interface BoolOptions extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'bool'; -} - -/** -* Interface describing function options. -*/ -interface GenericOptions extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'generic'; -} - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: float64ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): float64ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float32Array = require( '@stdlib/array-float32' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Float32Array( [ 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( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: float32ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): float32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var Complex64Array = require( '@stdlib/array-complex64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* function predicate( z, idx ) { -* return idx[ 0 ] > 0; -* } -* -* var buffer = new Complex64Array( [ 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 = [ 3, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, predicate ); -* // returns -*/ -declare function filter( x: complex64ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): complex64ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* function predicate( z, idx ) { -* return idx[ 0 ] > 0; -* } -* -* var buffer = new Complex128Array( [ 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 = [ 3, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, predicate ); -* // returns -*/ -declare function filter( x: complex128ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): complex128ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Int32Array = require( '@stdlib/array-int32' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Int32Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: int32ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): int32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Int16Array = require( '@stdlib/array-int16' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Int16Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: int16ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): int16ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Int8Array = require( '@stdlib/array-int8' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Int8Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: int8ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): int8ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint32Array = require( '@stdlib/array-uint32' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint32Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint32ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): uint32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint16Array = require( '@stdlib/array-uint16' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint16Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint16ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): uint16ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint8Array = require( '@stdlib/array-uint8' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint8Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint8ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): uint8ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint8ClampedArray( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint8cndarray, predicate: Predicate, thisArg?: ThisParameterType> ): uint8cndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var BooleanArray = require( '@stdlib/array-bool' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* function predicate( z ) { -* return z; -* } -* -* var buffer = new BooleanArray( [ false, true, false, true, false, true, false, true, false, true, false, true ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'bool', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, predicate ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ true, true, true, true ] -*/ -declare function filter( x: boolndarray, predicate: Predicate, thisArg?: ThisParameterType> ): boolndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 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( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: genericndarray, predicate: Predicate, thisArg?: ThisParameterType> ): genericndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: float64ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): float64ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float32Array = require( '@stdlib/array-float32' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Float32Array( [ 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( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: float32ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): float32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var Complex64Array = require( '@stdlib/array-complex64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* function predicate( z, idx ) { -* return idx[ 0 ] > 0; -* } -* -* var buffer = new Complex64Array( [ 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 = [ 3, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, predicate ); -* // returns -*/ -declare function filter( x: complex64ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): complex64ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* function predicate( z, idx ) { -* return idx[ 0 ] > 0; -* } -* -* var buffer = new Complex128Array( [ 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 = [ 3, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, predicate ); -* // returns -*/ -declare function filter( x: complex128ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): complex128ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Int32Array = require( '@stdlib/array-int32' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Int32Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: int32ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): int32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Int16Array = require( '@stdlib/array-int16' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Int16Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: int16ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): int16ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Int8Array = require( '@stdlib/array-int8' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Int8Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: int8ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): int8ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint32Array = require( '@stdlib/array-uint32' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint32Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint32ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): uint32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint16Array = require( '@stdlib/array-uint16' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint16Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint16ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): uint16ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint8Array = require( '@stdlib/array-uint8' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint8Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint8ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): uint8ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint8ClampedArray( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint8cndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): uint8cndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var BooleanArray = require( '@stdlib/array-bool' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* function predicate( z ) { -* return z; -* } -* -* var buffer = new BooleanArray( [ false, true, false, true, false, true, false, true, false, true, false, true ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'bool', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, predicate ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ true, true, true, true ] -*/ -declare function filter( x: boolndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): boolndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 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( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: genericndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): genericndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'float64' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: typedndarray, options: Float64Options, predicate: Predicate, thisArg?: ThisParameterType> ): float64ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'float32' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: typedndarray, options: Float32Options, predicate: Predicate, thisArg?: ThisParameterType> ): float32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* function predicate( z, idx ) { -* return idx[ 0 ] > 0; -* } -* -* var buffer = new Complex128Array( [ 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 = [ 3, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'dtype': 'complex128' -* }; -* var y = filter( x, opts, predicate ); -* // returns -*/ -declare function filter( x: typedndarray, options: Complex128Options, predicate: Predicate, thisArg?: ThisParameterType> ): complex128ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* function predicate( z, idx ) { -* return idx[ 0 ] > 0; -* } -* -* var buffer = new Complex128Array( [ 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 = [ 3, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'dtype': 'complex64' -* }; -* var y = filter( x, opts, predicate ); -* // returns -*/ -declare function filter( x: typedndarray, options: Complex64Options, predicate: Predicate, thisArg?: ThisParameterType> ): complex64ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'int32' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: typedndarray, options: Int32Options, predicate: Predicate, thisArg?: ThisParameterType> ): int32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'int16' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: typedndarray, options: Int16Options, predicate: Predicate, thisArg?: ThisParameterType> ): int16ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'int8' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: typedndarray, options: Int8Options, predicate: Predicate, thisArg?: ThisParameterType> ): int8ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'uint32' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: typedndarray, options: Uint32Options, predicate: Predicate, thisArg?: ThisParameterType> ): uint32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'uint16' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: typedndarray, options: Uint16Options, predicate: Predicate, thisArg?: ThisParameterType> ): uint16ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'uint8' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: typedndarray, options: Uint8Options, predicate: Predicate, thisArg?: ThisParameterType> ): uint8ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'uint8c' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: typedndarray, options: Uint8COptions, predicate: Predicate, thisArg?: ThisParameterType> ): uint8cndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'bool' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ true, true, true, true ] -*/ -declare function filter( x: typedndarray, options: BoolOptions, predicate: Predicate, thisArg?: ThisParameterType> ): boolndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'generic' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: typedndarray, options: GenericOptions, predicate: Predicate, thisArg?: ThisParameterType> ): genericndarray; - - -// EXPORTS // - -export = filter; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index f1c84f4..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import e 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 a from"https://cdn.jsdelivr.net/gh/stdlib-js/blas-base-gcopy@v0.2.1-esm/index.mjs";import h 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,G;if(!e(v))throw new TypeError(h("null5t",v));if(arguments.length<3?w=f:3===arguments.length?s(f)?(w=f,k=b):(g=!0,u=f,w=b):(g=!0,u=f,w=b,k=c),!s(w))throw new TypeError(h("null2b",w));if(g){if(!r(u))throw new TypeError(h("null2V",u));if(q=n(u,"dtype")?u.dtype:m(v),n(u,"order")){if(!t(u.order))throw new TypeError(h("null5C","order",u.order));z=u.order}}else q=m(v);if(null===(E=d(q)))throw new TypeError(h("nullBf","dtype",u.dtype));for(void 0===z&&(z=l(v)),A=o(v),D=p(A),y=A.length,B="row-major"===z?y-1:0,C=i(y),x={length:0},T=-1,G=0;G0&&(C=j(A,z,C,B,C)),F=v.get.apply(v,C),w.call(k,F,C.slice(),v)&&(x.length+=1,x[T+=1]=F);return V=new E(D=x.length),a(D,x,1,V,1),new v.constructor(q,V,[D],[1],0,z)}export{v as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index c68f119..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 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* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate 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 {boolean} [options.order='row-major'] - index iteration order\n* @param {Callback} predicate - predicate function\n* @param {*} [thisArg] - predicate 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 { isPrimitive as isEven } from '@stdlib/assert-is-even';\n* import Float64Array from '@stdlib/array-float64';\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndarray2array from '@stdlib/ndarray-to-array';\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 = filter( x, isEven );\n* // returns \n*\n* var arr = ndarray2array( y );\n* // returns [ 2.0, 4.0, 8.0, 10.0 ]\n*/\nfunction filter( x, options, predicate, thisArg ) {\n\tvar hasOpts;\n\tvar ndims;\n\tvar cache;\n\tvar clbk;\n\tvar opts;\n\tvar ctor;\n\tvar cidx;\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 = predicate;\n\t\t} else {\n\t\t\thasOpts = true;\n\t\t\topts = options;\n\t\t\tclbk = predicate;\n\t\t}\n\t} else {\n\t\thasOpts = true;\n\t\topts = options;\n\t\tclbk = predicate;\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 predicate 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 elements according to a predicate function...\n\tcidx = -1;\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 = x.get.apply( x, idx );\n\t\tif ( clbk.call( ctx, v, idx.slice(), x ) ) {\n\t\t\tcache.length += 1;\n\t\t\tcidx += 1;\n\t\t\tcache[ cidx ] = v;\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 filter;\n"],"names":["filter","x","options","predicate","thisArg","hasOpts","ndims","cache","clbk","opts","ctor","cidx","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","get","apply","call","slice","gcopy","constructor"],"mappings":";;6zCA0EA,SAASA,EAAQC,EAAGC,EAASC,EAAWC,GACvC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEAC,EACAC,EACJ,IAAMC,EAAerB,GACpB,MAAM,IAAIsB,UAAWC,EAAQ,SAAUvB,IAmBxC,GAjBKwB,UAAUC,OAAS,EACvBlB,EAAON,EACyB,IAArBuB,UAAUC,OAChBC,EAAYzB,IAChBM,EAAON,EACPU,EAAMT,IAENE,GAAU,EACVI,EAAOP,EACPM,EAAOL,IAGRE,GAAU,EACVI,EAAOP,EACPM,EAAOL,EACPS,EAAMR,IAEDuB,EAAYnB,GACjB,MAAM,IAAIe,UAAWC,EAAQ,SAAUhB,IAExC,GAAKH,EAAU,CACd,IAAMuB,EAAenB,GACpB,MAAM,IAAIc,UAAWC,EAAQ,SAAUf,IAOxC,GAJCQ,EADIY,EAAYpB,EAAM,SACjBA,EAAKqB,MAELC,EAAU9B,GAEX4B,EAAYpB,EAAM,SAAY,CAClC,IAAMuB,EAASvB,EAAKwB,OACnB,MAAM,IAAIV,UAAWC,EAAQ,SAAU,QAASf,EAAKwB,QAEtDpB,EAAMJ,EAAKwB,KACX,CACH,MACEhB,EAAKc,EAAU9B,GAIhB,GAAc,QADdS,EAAOwB,EAAOjB,IAGb,MAAM,IAAIM,UAAWC,EAAQ,SAAU,QAASf,EAAKqB,QA+BtD,SA5Ba,IAARjB,IACJA,EAAMsB,EAAUlC,IAGjBiB,EAAKkB,EAAUnC,GAGfkB,EAAIkB,EAAOnB,GAGXZ,EAAQY,EAAGQ,OAIVZ,EADY,cAARD,EACEP,EAAQ,EAER,EAGPS,EAAMuB,EAAOhC,GAGbC,EAAQ,CACPmB,OAAU,GAIXf,GAAQ,EACFU,EAAI,EAAGA,EAAIF,EAAGE,IACdA,EAAI,IACRN,EAAMwB,EAAoBrB,EAAIL,EAAKE,EAAKD,EAAKC,IAE9CK,EAAInB,EAAEuC,IAAIC,MAAOxC,EAAGc,GACfP,EAAKkC,KAAM9B,EAAKQ,EAAGL,EAAI4B,QAAS1C,KACpCM,EAAMmB,QAAU,EAEhBnB,EADAI,GAAQ,GACQS,GAelB,OARAJ,EAAM,IAAIN,EAHVS,EAAIZ,EAAMmB,QAMVkB,EAAOzB,EAAGZ,EAAO,EAAGS,EAAK,GAGrB,IAAIf,EAAE4C,YAAa5B,EAAID,EAAK,CAAEG,GAAK,CAAE,GAAK,EAAGN,EAGlD"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 7526b53..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Codestin Search App - - - -
- - - - - From 959e0956e4e91b2850044ee92f650520e80c96d3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 14 Dec 2024 05:10:38 +0000 Subject: [PATCH 08/35] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 50 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 65 +- SECURITY.md | 5 - benchmark/benchmark.1d.js | 150 - benchmark/benchmark.2d.js | 161 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 51 - docs/types/test.ts | 195 - examples/index.js | 38 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 55 - lib/main.js | 199 - package.json | 84 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 892 ---- 44 files changed, 4878 insertions(+), 5314 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.1d.js delete mode 100644 benchmark/benchmark.2d.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 03a0613..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) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 48af73a..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) 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 443f7ec..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: '9 21 * * 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 + + ```
@@ -213,7 +204,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]. @@ -276,11 +267,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-filter/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 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 6958f29..0000000 --- a/benchmark/benchmark.1d.js +++ /dev/null @@ -1,150 +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 filter = require( './../lib' ); - - -// VARIABLES // - -var xtypes = [ 'generic' ]; -var ytypes = [ 'float64' ]; -var orders = [ 'row-major', 'column-major' ]; - - -// FUNCTIONS // - -/** -* Predicate function. -* -* @private -* @param {number} value - array element -* @param {NonNegativeIntegerArray} indices - element indices -* @param {ndarray} arr - input array -* @returns {boolean} result -*/ -function predicate( value ) { - return value > 0.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 = filter( x, opts, predicate ); - 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 e848b15..0000000 --- a/benchmark/benchmark.2d.js +++ /dev/null @@ -1,161 +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 map = require( './../lib' ); - - -// VARIABLES // - -var xtypes = [ 'generic' ]; -var ytypes = [ 'float64' ]; -var orders = [ 'row-major', 'column-major' ]; - - -// FUNCTIONS // - -/** -* Predicate function. -* -* @private -* @param {number} value - array element -* @param {NonNegativeIntegerArray} indices - element indices -* @param {ndarray} arr - input array -* @returns {boolean} result -*/ -function predicate( value ) { - return value > 0.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 = map( x, opts, predicate ); - 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 51e4f91..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" -%% click B href "https://github.com/stdlib-js/ndarray-filter/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-filter/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-filter/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-filter/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-filter/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/filter -[production-url]: https://github.com/stdlib-js/ndarray-filter/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-filter/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-filter/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-filter/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-filter/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-filter/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-filter/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 aafb9cb..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import filter from '../docs/types/index'; -export = filter; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 558b3a7..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var V=function(r,a){return function(){return a||r((a={exports:{}}).exports,a),a.exports}};var k=V(function(K,j){"use strict";var C=require("@stdlib/assert-is-plain-object"),O=require("@stdlib/assert-is-function"),F=require("@stdlib/assert-is-ndarray-like"),P=require("@stdlib/ndarray-base-assert-is-order"),T=require("@stdlib/assert-has-own-property"),D=require("@stdlib/ndarray-base-buffer-ctors"),I=require("@stdlib/array-base-zeros"),L=require("@stdlib/ndarray-shape"),E=require("@stdlib/ndarray-dtype"),N=require("@stdlib/ndarray-order"),S=require("@stdlib/ndarray-base-numel"),A=require("@stdlib/ndarray-base-next-cartesian-index").assign,B=require("@stdlib/blas-base-gcopy"),v=require("@stdlib/string-format");function G(r,a,g,z){var c,f,o,i,e,p,m,h,t,y,n,q,s,l,u,b,w,d;if(!F(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?O(a)?(i=a,h=g):(c=!0,e=a,i=g):(c=!0,e=a,i=g,h=z),!O(i))throw new TypeError(v("invalid argument. Callback argument must be a function. Value: `%s`.",i));if(c){if(!C(e))throw new TypeError(v("invalid argument. Options argument must be an object. Value: `%s`.",e));if(T(e,"dtype")?s=e.dtype:s=E(r),T(e,"order")){if(!P(e.order))throw new TypeError(v("invalid option. `%s` option must be a recognized order. Option: `%s`.","order",e.order));t=e.order}}else s=E(r);if(p=D(s),p===null)throw new TypeError(v("invalid option. `%s` option must be a recognized data type. Option: `%s`.","dtype",e.dtype));for(t===void 0&&(t=N(r)),l=L(r),u=S(l),f=l.length,t==="row-major"?y=f-1:y=0,n=I(f),o={length:0},m=-1,d=0;d0&&(n=A(l,t,n,y,n)),w=r.get.apply(r,n),i.call(h,w,n.slice(),r)&&(o.length+=1,m+=1,o[m]=w);return u=o.length,q=new p(u),B(u,o,1,q,1),b=new r.constructor(s,q,[u],[1],0,t),b}j.exports=G});var H=k();module.exports=H; -/** -* @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 92b21c3..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* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate 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 {boolean} [options.order='row-major'] - index iteration order\n* @param {Callback} predicate - predicate function\n* @param {*} [thisArg] - predicate 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 isEven = require( '@stdlib/assert-is-even' ).isPrimitive;\n* var Float64Array = require( '@stdlib/array-float64' );\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\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 = filter( x, isEven );\n* // returns \n*\n* var arr = ndarray2array( y );\n* // returns [ 2.0, 4.0, 8.0, 10.0 ]\n*/\nfunction filter( x, options, predicate, thisArg ) {\n\tvar hasOpts;\n\tvar ndims;\n\tvar cache;\n\tvar clbk;\n\tvar opts;\n\tvar ctor;\n\tvar cidx;\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 = predicate;\n\t\t} else {\n\t\t\thasOpts = true;\n\t\t\topts = options;\n\t\t\tclbk = predicate;\n\t\t}\n\t} else {\n\t\thasOpts = true;\n\t\topts = options;\n\t\tclbk = predicate;\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 predicate 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 elements according to a predicate function...\n\tcidx = -1;\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 = x.get.apply( x, idx );\n\t\tif ( clbk.call( ctx, v, idx.slice(), x ) ) {\n\t\t\tcache.length += 1;\n\t\t\tcidx += 1;\n\t\t\tcache[ cidx ] = v;\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 = filter;\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* Return a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function.\n*\n* @module @stdlib/ndarray-filter\n*\n* @example\n* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive;\n* var Float64Array = require( '@stdlib/array-float64' );\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var filter = require( '@stdlib/ndarray-filter' );\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 = filter( x, isEven );\n* // returns \n*\n* var arr = ndarray2array( y );\n* // returns [ 2.0, 4.0, 8.0, 10.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,EAuC9C,SAASC,EAAQC,EAAGC,EAASC,EAAWC,EAAU,CACjD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,GAAK,CAAClC,EAAea,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,gFAAiFE,CAAE,CAAE,EAmBnH,GAjBK,UAAU,OAAS,EACvBO,EAAON,EACI,UAAU,SAAW,EAC3Bf,EAAYe,CAAQ,GACxBM,EAAON,EACPU,EAAMT,IAENE,EAAU,GACVI,EAAOP,EACPM,EAAOL,IAGRE,EAAU,GACVI,EAAOP,EACPM,EAAOL,EACPS,EAAMR,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,EAC9BQ,EAAKR,EAAK,MAEVQ,EAAKvB,EAAUO,CAAE,EAEbX,EAAYmB,EAAM,OAAQ,EAAI,CAClC,GAAK,CAACpB,EAASoB,EAAK,KAAM,EACzB,MAAM,IAAI,UAAWV,EAAQ,wEAAyE,QAASU,EAAK,KAAM,CAAE,EAE7HI,EAAMJ,EAAK,KACZ,CACD,MACCQ,EAAKvB,EAAUO,CAAE,EAIlB,GADAS,EAAOnB,EAAO0B,CAAG,EACZP,IAAS,KAEb,MAAM,IAAI,UAAWX,EAAQ,4EAA6E,QAASU,EAAK,KAAM,CAAE,EA+BjI,IA5BKI,IAAQ,SACZA,EAAMlB,EAAUM,CAAE,GAGnBiB,EAAKzB,EAAUQ,CAAE,EAGjBkB,EAAIvB,EAAOsB,CAAG,EAGdZ,EAAQY,EAAG,OAGNL,IAAQ,YACZC,EAAMR,EAAQ,EAEdQ,EAAM,EAGPC,EAAMvB,EAAOc,CAAM,EAGnBC,EAAQ,CACP,OAAU,CACX,EAGAI,EAAO,GACDW,EAAI,EAAGA,EAAIH,EAAGG,IACdA,EAAI,IACRP,EAAMlB,EAAoBqB,EAAIL,EAAKE,EAAKD,EAAKC,CAAI,GAElDM,EAAIpB,EAAE,IAAI,MAAOA,EAAGc,CAAI,EACnBP,EAAK,KAAMI,EAAKS,EAAGN,EAAI,MAAM,EAAGd,CAAE,IACtCM,EAAM,QAAU,EAChBI,GAAQ,EACRJ,EAAOI,CAAK,EAAIU,GAIlB,OAAAF,EAAIZ,EAAM,OAGVS,EAAM,IAAIN,EAAMS,CAAE,EAGlBrB,EAAOqB,EAAGZ,EAAO,EAAGS,EAAK,CAAE,EAG3BI,EAAI,IAAInB,EAAE,YAAagB,EAAID,EAAK,CAAEG,CAAE,EAAG,CAAE,CAAE,EAAG,EAAGN,CAAI,EAE9CO,CACR,CAKAnC,EAAO,QAAUe,ICrJjB,IAAIuB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isPlainObject", "isFunction", "isndarrayLike", "isOrder", "hasOwnProp", "ctors", "zeros", "getShape", "getDType", "getOrder", "numel", "nextCartesianIndex", "gcopy", "format", "filter", "x", "options", "predicate", "thisArg", "hasOpts", "ndims", "cache", "clbk", "opts", "ctor", "cidx", "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 8ed7071..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,51 +0,0 @@ - -{{alias}}( x[, options], predicate[, thisArg] ) - Returns a shallow copy of an ndarray containing only those elements which - pass a test implemented by a predicate function. - - The predicate function is provided the following arguments: - - - value: current array element. - - indices: current array element indices. - - arr: the input 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 manor, 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'. - - predicate: Function - Predicate function. - - thisArg: any (optional) - Predicate function execution context. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ); - > function f( v ) { return v > 2.0; }; - > var y = {{alias}}( x, f ); - > {{alias:@stdlib/ndarray/to-array}}( y ) - [ 3.0, 4.0 ] - - See Also - -------- diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 046dffb..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,195 +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 empty = require( '@stdlib/ndarray-base-empty' ); -import zeros = require( '@stdlib/ndarray-base-zeros' ); -import filter = require( './index' ); - -/** -* Predicate function. -* -* @param x - input value -* @returns result -*/ -function predicate( x: any ): boolean { - return Boolean( x ); -} - -// The function returns an ndarray... -{ - const sh = [ 2, 2 ]; - const ord = 'row-major'; - - filter( zeros( 'float64', sh, ord ), predicate ); // $ExpectType float64ndarray - filter( zeros( 'float64', sh, ord ), predicate, {} ); // $ExpectType float64ndarray - filter( zeros( 'float32', sh, ord ), predicate ); // $ExpectType float32ndarray - filter( zeros( 'float32', sh, ord ), predicate, {} ); // $ExpectType float32ndarray - filter( zeros( 'complex64', sh, ord ), predicate ); // $ExpectType complex64ndarray - filter( zeros( 'complex64', sh, ord ), predicate, {} ); // $ExpectType complex64ndarray - filter( zeros( 'complex128', sh, ord ), predicate ); // $ExpectType complex128ndarray - filter( zeros( 'complex128', sh, ord ), predicate, {} ); // $ExpectType complex128ndarray - filter( zeros( 'int32', sh, ord ), predicate ); // $ExpectType int32ndarray - filter( zeros( 'int32', sh, ord ), predicate, {} ); // $ExpectType int32ndarray - filter( zeros( 'int16', sh, ord ), predicate ); // $ExpectType int16ndarray - filter( zeros( 'int16', sh, ord ), predicate, {} ); // $ExpectType int16ndarray - filter( zeros( 'int8', sh, ord ), predicate ); // $ExpectType int8ndarray - filter( zeros( 'int8', sh, ord ), predicate, {} ); // $ExpectType int8ndarray - filter( zeros( 'uint32', sh, ord ), predicate ); // $ExpectType uint32ndarray - filter( zeros( 'uint32', sh, ord ), predicate, {} ); // $ExpectType uint32ndarray - filter( zeros( 'uint16', sh, ord ), predicate ); // $ExpectType uint16ndarray - filter( zeros( 'uint16', sh, ord ), predicate, {} ); // $ExpectType uint16ndarray - filter( zeros( 'uint8', sh, ord ), predicate ); // $ExpectType uint8ndarray - filter( zeros( 'uint8', sh, ord ), predicate, {} ); // $ExpectType uint8ndarray - filter( zeros( 'uint8c', sh, ord ), predicate ); // $ExpectType uint8cndarray - filter( zeros( 'uint8c', sh, ord ), predicate, {} ); // $ExpectType uint8cndarray - filter( empty( 'bool', sh, ord ), predicate ); // $ExpectType boolndarray - filter( empty( 'bool', sh, ord ), predicate, {} ); // $ExpectType boolndarray - filter( zeros( 'generic', sh, ord ), predicate ); // $ExpectType genericndarray - filter( zeros( 'generic', sh, ord ), predicate, {} ); // $ExpectType genericndarray - - - filter( zeros( 'generic', sh, ord ), { 'dtype': 'float64' }, predicate ); // $ExpectType float64ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'float64' }, predicate, {} ); // $ExpectType float64ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'float32' }, predicate ); // $ExpectType float32ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'float32' }, predicate, {} ); // $ExpectType float32ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'complex64' }, predicate ); // $ExpectType complex64ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'complex64' }, predicate, {} ); // $ExpectType complex64ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'complex128' }, predicate ); // $ExpectType complex128ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'complex128' }, predicate, {} ); // $ExpectType complex128ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'int32' }, predicate ); // $ExpectType int32ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'int32' }, predicate, {} ); // $ExpectType int32ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'int16' }, predicate ); // $ExpectType int16ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'int16' }, predicate, {} ); // $ExpectType int16ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'int8' }, predicate ); // $ExpectType int8ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'int8' }, predicate, {} ); // $ExpectType int8ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint32' }, predicate ); // $ExpectType uint32ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint32' }, predicate, {} ); // $ExpectType uint32ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint16' }, predicate ); // $ExpectType uint16ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint16' }, predicate, {} ); // $ExpectType uint16ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint8' }, predicate ); // $ExpectType uint8ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint8' }, predicate, {} ); // $ExpectType uint8ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint8c' }, predicate ); // $ExpectType uint8cndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint8c' }, predicate, {} ); // $ExpectType uint8cndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'bool' }, predicate ); // $ExpectType boolndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'bool' }, predicate, {} ); // $ExpectType boolndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'generic' }, predicate ); // $ExpectType genericndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'generic' }, predicate, {} ); // $ExpectType genericndarray - - - filter( zeros( 'float64', sh, ord ), { 'order': ord }, predicate ); // $ExpectType float64ndarray - filter( zeros( 'float64', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType float64ndarray - filter( zeros( 'float32', sh, ord ), { 'order': ord }, predicate ); // $ExpectType float32ndarray - filter( zeros( 'float32', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType float32ndarray - filter( zeros( 'complex64', sh, ord ), { 'order': ord }, predicate ); // $ExpectType complex64ndarray - filter( zeros( 'complex64', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType complex64ndarray - filter( zeros( 'complex128', sh, ord ), { 'order': ord }, predicate ); // $ExpectType complex128ndarray - filter( zeros( 'complex128', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType complex128ndarray - filter( zeros( 'int32', sh, ord ), { 'order': ord }, predicate ); // $ExpectType int32ndarray - filter( zeros( 'int32', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType int32ndarray - filter( zeros( 'int16', sh, ord ), { 'order': ord }, predicate ); // $ExpectType int16ndarray - filter( zeros( 'int16', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType int16ndarray - filter( zeros( 'int8', sh, ord ), { 'order': ord }, predicate ); // $ExpectType int8ndarray - filter( zeros( 'int8', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType int8ndarray - filter( zeros( 'uint32', sh, ord ), { 'order': ord }, predicate ); // $ExpectType uint32ndarray - filter( zeros( 'uint32', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType uint32ndarray - filter( zeros( 'uint16', sh, ord ), { 'order': ord }, predicate ); // $ExpectType uint16ndarray - filter( zeros( 'uint16', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType uint16ndarray - filter( zeros( 'uint8', sh, ord ), { 'order': ord }, predicate ); // $ExpectType uint8ndarray - filter( zeros( 'uint8', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType uint8ndarray - filter( zeros( 'uint8c', sh, ord ), { 'order': ord }, predicate ); // $ExpectType uint8cndarray - filter( zeros( 'uint8c', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType uint8cndarray - filter( empty( 'bool', sh, ord ), { 'order': ord }, predicate ); // $ExpectType boolndarray - filter( empty( 'bool', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType boolndarray - filter( zeros( 'generic', sh, ord ), { 'order': ord }, predicate ); // $ExpectType genericndarray - filter( zeros( 'generic', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType genericndarray - -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - filter( 5, predicate ); // $ExpectError - filter( true, predicate ); // $ExpectError - filter( false, predicate ); // $ExpectError - filter( null, predicate ); // $ExpectError - filter( undefined, predicate ); // $ExpectError - filter( {}, predicate ); // $ExpectError - filter( [ 1 ], predicate ); // $ExpectError - filter( ( x: number ): number => x, predicate ); // $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' ); - - filter( x, '5' ); // $ExpectError - filter( x, true ); // $ExpectError - filter( x, false ); // $ExpectError - filter( x, null ); // $ExpectError - filter( x, undefined ); // $ExpectError - filter( x, {} ); // $ExpectError - filter( 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' ); - - filter( x, '10', predicate, {} ); // $ExpectError - filter( x, 10, predicate, {} ); // $ExpectError - filter( x, false, predicate, {} ); // $ExpectError - filter( x, true, predicate, {} ); // $ExpectError - filter( x, [], predicate, {} ); // $ExpectError - filter( x, ( x: number ): number => x, predicate, {} ); // $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' ); - - filter( x, { 'dtype': '10' }, predicate ); // $ExpectError - filter( x, { 'dtype': 10 }, predicate ); // $ExpectError - filter( x, { 'dtype': null }, predicate ); // $ExpectError - filter( x, { 'dtype': false }, predicate ); // $ExpectError - filter( x, { 'dtype': true }, predicate ); // $ExpectError - filter( x, { 'dtype': [] }, predicate ); // $ExpectError - filter( x, { 'dtype': {} }, predicate ); // $ExpectError - filter( x, { 'dtype': ( x: number ): number => x }, predicate ); // $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' ); - - filter( x, { 'order': '10' }, predicate ); // $ExpectError - filter( x, { 'order': 10 }, predicate ); // $ExpectError - filter( x, { 'order': null }, predicate ); // $ExpectError - filter( x, { 'order': false }, predicate ); // $ExpectError - filter( x, { 'order': true }, predicate ); // $ExpectError - filter( x, { 'order': [] }, predicate ); // $ExpectError - filter( x, { 'order': {} }, predicate ); // $ExpectError - filter( x, { 'order': ( x: number ): number => x }, predicate ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - filter(); // $ExpectError - filter( zeros( 'float64', [ 2, 2 ], 'row-major' ) ); // $ExpectError - filter( 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 e2dd6cb..0000000 --- a/examples/index.js +++ /dev/null @@ -1,38 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var array = require( '@stdlib/ndarray-array' ); -var isPositive = require( '@stdlib/assert-is-positive-number' ).isPrimitive; -var filter = require( './../lib' ); - -var buffer = discreteUniform( 10, -100, 100, { - 'dtype': 'generic' -}); -var x = array( buffer, { - 'shape': [ 5, 2 ], - 'dtype': 'generic' -}); -console.log( ndarray2array( x ) ); - -var y = filter( x, naryFunction( isPositive, 1 ) ); -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 a39a064..e2a9d07 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..f1c84f4 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import e 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 a from"https://cdn.jsdelivr.net/gh/stdlib-js/blas-base-gcopy@v0.2.1-esm/index.mjs";import h 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,G;if(!e(v))throw new TypeError(h("null5t",v));if(arguments.length<3?w=f:3===arguments.length?s(f)?(w=f,k=b):(g=!0,u=f,w=b):(g=!0,u=f,w=b,k=c),!s(w))throw new TypeError(h("null2b",w));if(g){if(!r(u))throw new TypeError(h("null2V",u));if(q=n(u,"dtype")?u.dtype:m(v),n(u,"order")){if(!t(u.order))throw new TypeError(h("null5C","order",u.order));z=u.order}}else q=m(v);if(null===(E=d(q)))throw new TypeError(h("nullBf","dtype",u.dtype));for(void 0===z&&(z=l(v)),A=o(v),D=p(A),y=A.length,B="row-major"===z?y-1:0,C=i(y),x={length:0},T=-1,G=0;G0&&(C=j(A,z,C,B,C)),F=v.get.apply(v,C),w.call(k,F,C.slice(),v)&&(x.length+=1,x[T+=1]=F);return V=new E(D=x.length),a(D,x,1,V,1),new v.constructor(q,V,[D],[1],0,z)}export{v as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..c68f119 --- /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* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate 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 {boolean} [options.order='row-major'] - index iteration order\n* @param {Callback} predicate - predicate function\n* @param {*} [thisArg] - predicate 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 { isPrimitive as isEven } from '@stdlib/assert-is-even';\n* import Float64Array from '@stdlib/array-float64';\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndarray2array from '@stdlib/ndarray-to-array';\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 = filter( x, isEven );\n* // returns \n*\n* var arr = ndarray2array( y );\n* // returns [ 2.0, 4.0, 8.0, 10.0 ]\n*/\nfunction filter( x, options, predicate, thisArg ) {\n\tvar hasOpts;\n\tvar ndims;\n\tvar cache;\n\tvar clbk;\n\tvar opts;\n\tvar ctor;\n\tvar cidx;\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 = predicate;\n\t\t} else {\n\t\t\thasOpts = true;\n\t\t\topts = options;\n\t\t\tclbk = predicate;\n\t\t}\n\t} else {\n\t\thasOpts = true;\n\t\topts = options;\n\t\tclbk = predicate;\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 predicate 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 elements according to a predicate function...\n\tcidx = -1;\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 = x.get.apply( x, idx );\n\t\tif ( clbk.call( ctx, v, idx.slice(), x ) ) {\n\t\t\tcache.length += 1;\n\t\t\tcidx += 1;\n\t\t\tcache[ cidx ] = v;\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 filter;\n"],"names":["filter","x","options","predicate","thisArg","hasOpts","ndims","cache","clbk","opts","ctor","cidx","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","get","apply","call","slice","gcopy","constructor"],"mappings":";;6zCA0EA,SAASA,EAAQC,EAAGC,EAASC,EAAWC,GACvC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEAC,EACAC,EACJ,IAAMC,EAAerB,GACpB,MAAM,IAAIsB,UAAWC,EAAQ,SAAUvB,IAmBxC,GAjBKwB,UAAUC,OAAS,EACvBlB,EAAON,EACyB,IAArBuB,UAAUC,OAChBC,EAAYzB,IAChBM,EAAON,EACPU,EAAMT,IAENE,GAAU,EACVI,EAAOP,EACPM,EAAOL,IAGRE,GAAU,EACVI,EAAOP,EACPM,EAAOL,EACPS,EAAMR,IAEDuB,EAAYnB,GACjB,MAAM,IAAIe,UAAWC,EAAQ,SAAUhB,IAExC,GAAKH,EAAU,CACd,IAAMuB,EAAenB,GACpB,MAAM,IAAIc,UAAWC,EAAQ,SAAUf,IAOxC,GAJCQ,EADIY,EAAYpB,EAAM,SACjBA,EAAKqB,MAELC,EAAU9B,GAEX4B,EAAYpB,EAAM,SAAY,CAClC,IAAMuB,EAASvB,EAAKwB,OACnB,MAAM,IAAIV,UAAWC,EAAQ,SAAU,QAASf,EAAKwB,QAEtDpB,EAAMJ,EAAKwB,KACX,CACH,MACEhB,EAAKc,EAAU9B,GAIhB,GAAc,QADdS,EAAOwB,EAAOjB,IAGb,MAAM,IAAIM,UAAWC,EAAQ,SAAU,QAASf,EAAKqB,QA+BtD,SA5Ba,IAARjB,IACJA,EAAMsB,EAAUlC,IAGjBiB,EAAKkB,EAAUnC,GAGfkB,EAAIkB,EAAOnB,GAGXZ,EAAQY,EAAGQ,OAIVZ,EADY,cAARD,EACEP,EAAQ,EAER,EAGPS,EAAMuB,EAAOhC,GAGbC,EAAQ,CACPmB,OAAU,GAIXf,GAAQ,EACFU,EAAI,EAAGA,EAAIF,EAAGE,IACdA,EAAI,IACRN,EAAMwB,EAAoBrB,EAAIL,EAAKE,EAAKD,EAAKC,IAE9CK,EAAInB,EAAEuC,IAAIC,MAAOxC,EAAGc,GACfP,EAAKkC,KAAM9B,EAAKQ,EAAGL,EAAI4B,QAAS1C,KACpCM,EAAMmB,QAAU,EAEhBnB,EADAI,GAAQ,GACQS,GAelB,OARAJ,EAAM,IAAIN,EAHVS,EAAIZ,EAAMmB,QAMVkB,EAAOzB,EAAGZ,EAAO,EAAGS,EAAK,GAGrB,IAAIf,EAAE4C,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 46f5998..0000000 --- a/lib/index.js +++ /dev/null @@ -1,55 +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'; - -/** -* Return a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @module @stdlib/ndarray-filter -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var filter = require( '@stdlib/ndarray-filter' ); -* -* 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 = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.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 f66736a..0000000 --- a/lib/main.js +++ /dev/null @@ -1,199 +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/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param {ndarray} x - input ndarray -* @param {Options} [options] - function options -* @param {string} [options.dtype] - output array data type -* @param {boolean} [options.order='row-major'] - index iteration order -* @param {Callback} predicate - predicate function -* @param {*} [thisArg] - predicate 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 isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -function filter( x, options, predicate, thisArg ) { - var hasOpts; - var ndims; - var cache; - var clbk; - var opts; - var ctor; - var cidx; - 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( 'null5t', x ) ); - } - if ( arguments.length < 3 ) { - clbk = options; - } else if ( arguments.length === 3 ) { - if ( isFunction( options ) ) { - clbk = options; - ctx = predicate; - } else { - hasOpts = true; - opts = options; - clbk = predicate; - } - } else { - hasOpts = true; - opts = options; - clbk = predicate; - ctx = thisArg; - } - if ( !isFunction( clbk ) ) { - throw new TypeError( format( 'null2b', clbk ) ); - } - if ( hasOpts ) { - if ( !isPlainObject( opts ) ) { - throw new TypeError( format( 'null2V', opts ) ); - } - if ( hasOwnProp( opts, 'dtype' ) ) { - dt = opts.dtype; - } else { - dt = getDType( x ); - } - if ( hasOwnProp( opts, 'order' ) ) { - if ( !isOrder( opts.order ) ) { - throw new TypeError( format( 'null5C', '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( 'nullBf', '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 predicate 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 elements according to a predicate function... - cidx = -1; - for ( i = 0; i < N; i++ ) { - if ( i > 0 ) { - idx = nextCartesianIndex( sh, ord, idx, dim, idx ); - } - v = x.get.apply( x, idx ); - if ( clbk.call( ctx, v, idx.slice(), x ) ) { - cache.length += 1; - cidx += 1; - cache[ cidx ] = v; - } - } - // 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 = filter; diff --git a/package.json b/package.json index a44b313..2473eda 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Return a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate 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,62 +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/error-tools-fmtprodmsg": "^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-positive-number": "^0.2.2", - "@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", - "@stdlib/utils-nary-function": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "strided", @@ -104,7 +25,6 @@ "select", "take" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..7526b53 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Codestin Search App + + + +
+ + + + + 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 3bea6b3..0000000 --- a/test/test.js +++ /dev/null @@ -1,892 +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 filter = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof filter, '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() { - filter( value, predicate ); - }; - } - - function predicate( z ) { - return ( z > 0.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() { - filter( 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() { - filter( 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() { - filter( x, value, predicate ); - }; - } - - function predicate( z ) { - return ( z > 0.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 - }; - filter( x, opts, predicate ); - }; - } - - function predicate( z ) { - return ( z > 0.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 - }; - filter( x, opts, predicate ); - }; - } - - function predicate( z ) { - return ( z > 0.0 ); - } -}); - -tape( 'the function filters an array according to a predicate 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 = filter( x, predicate ); - - expected = new Float64Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - - t.end(); - - function predicate( z ) { - return ( z > 0.0 ); - } -}); - -tape( 'the function filters an array according to a predicate 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 = filter( x, predicate ); - - expected = new Float64Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - - t.end(); - - function predicate( z ) { - return ( z > 0.0 ); - } -}); - -tape( 'the function filters an array according to a predicate 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 = filter( x, opts, predicate ); - - expected = new Float64Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - - opts = { - 'dtype': 'float32' - }; - y = filter( x, opts, predicate ); - - expected = new Float32Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat32Array( y.data, expected ), true, 'returns expected value' ); - - t.end(); - - function predicate( z ) { - return ( z > 0.0 ); - } -}); - -tape( 'the function filters an array according to a predicate 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 = filter( x, opts, predicate ); - - expected = new Float64Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - - opts = { - 'dtype': 'float32' - }; - y = filter( x, opts, predicate ); - - expected = new Float32Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat32Array( y.data, expected ), true, 'returns expected value' ); - - t.end(); - - function predicate( z ) { - return ( z > 0.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 = filter( x, predicate, ctx ); - - expected = new Float64Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function predicate( z ) { - this.count += 1; // eslint-disable-line no-invalid-this - return ( z > 0.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 = filter( x, {}, predicate, ctx ); - - expected = new Float64Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function predicate( z ) { - this.count += 1; // eslint-disable-line no-invalid-this - return ( z > 0.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 = filter( x, predicate ); - - expected = new Float64Array([ - 1.0, - 3.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 predicate( z, idx, arr ) { - values.push( z ); - indices.push( idx ); - arrays.push( arr ); - return ( z > 0.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 = filter( x, predicate ); - - expected = new Float64Array([ - 1.0, - 3.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 predicate( z, idx, arr ) { - values.push( z ); - indices.push( idx ); - arrays.push( arr ); - return ( z > 0.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 = filter( x, opts, predicate ); - - expected = new Float64Array([ - 1.0, - 3.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 predicate( z, idx, arr ) { - values.push( z ); - indices.push( idx ); - arrays.push( arr ); - return ( z > 0.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 = filter( x, opts, predicate ); - - expected = new Float64Array([ - 1.0, - 3.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 predicate( z, idx, arr ) { - values.push( z ); - indices.push( idx ); - arrays.push( arr ); - return ( z > 0.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 = filter( x, opts, predicate ); - - expected = new Float64Array([ - 1.0, - 3.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 predicate( z, idx, arr ) { - values.push( z ); - indices.push( idx ); - arrays.push( arr ); - return ( z > 0.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 = filter( x, opts, predicate ); - - expected = new Float64Array([ - 1.0, - 3.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 predicate( z, idx, arr ) { - values.push( z ); - indices.push( idx ); - arrays.push( arr ); - return ( z > 0.0 ); - } -}); From e0ae43c2acf4b6b47e31b7c82eda197792e21024 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 14 Dec 2024 09:06:06 +0000 Subject: [PATCH 09/35] Transform error messages --- lib/main.js | 12 ++++++------ package.json | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/main.js b/lib/main.js index 18a75ea..f101a98 100644 --- a/lib/main.js +++ b/lib/main.js @@ -33,7 +33,7 @@ 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' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -92,7 +92,7 @@ function filter( x, options, predicate, thisArg ) { var v; var i; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray-like object. Value: `%s`.', x ) ); + throw new TypeError( format( 'null5t', x ) ); } if ( arguments.length < 3 ) { clbk = options; @@ -112,11 +112,11 @@ function filter( x, options, predicate, thisArg ) { ctx = thisArg; } if ( !isFunction( clbk ) ) { - throw new TypeError( format( 'invalid argument. Callback argument must be a function. Value: `%s`.', clbk ) ); + throw new TypeError( format( 'null2b', clbk ) ); } if ( hasOpts ) { if ( !isPlainObject( opts ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) ); + throw new TypeError( format( 'null2V', opts ) ); } if ( hasOwnProp( opts, 'dtype' ) ) { dt = opts.dtype; @@ -125,7 +125,7 @@ function filter( x, options, predicate, thisArg ) { } 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 ) ); + throw new TypeError( format( 'null5C', 'order', opts.order ) ); } ord = opts.order; } @@ -136,7 +136,7 @@ function filter( x, options, predicate, thisArg ) { 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 ) ); + throw new TypeError( format( 'nullBf', 'dtype', opts.dtype ) ); } // Resolve the iteration order: if ( ord === void 0 ) { diff --git a/package.json b/package.json index 22065aa..a44b313 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@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/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From 1d9f55f55148a4759946d83e6ab9e4b50544f009 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 14 Dec 2024 09:10:31 +0000 Subject: [PATCH 10/35] Remove files --- index.d.ts | 1612 ---------------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 6459 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index e2a9d07..0000000 --- a/index.d.ts +++ /dev/null @@ -1,1612 +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. -*/ - -// TypeScript Version: 4.1 - -/// - -/* eslint-disable max-lines */ - -import { typedndarray, DataType, Order, float64ndarray, float32ndarray, complex128ndarray, complex64ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, boolndarray, genericndarray } from '@stdlib/types/ndarray'; -import { Complex64, Complex128 } from '@stdlib/types/complex'; - -/** -* Returns a boolean indicating whether an element passes a test. -* -* @returns boolean indicating whether an element passes a test -*/ -type Nullary = ( this: V ) => boolean; - -/** -* Returns a boolean indicating whether an element passes a test. -* -* @param value - current array element -* @returns boolean indicating whether an element passes a test -*/ -type Unary = ( this: V, value: T ) => boolean; - -/** -* Returns a boolean indicating whether an element passes a test. -* -* @param value - current array element -* @param indices - current array element indices -* @returns boolean indicating whether an element passes a test -*/ -type Binary = ( this: V, value: T, indices: Array ) => boolean; - -/** -* Returns a boolean indicating whether an element passes a test. -* -* @param value - current array element -* @param indices - current array element indices -* @param arr - input array -* @returns boolean indicating whether an element passes a test -*/ -type Ternary = ( this: V, value: T, indices: Array, arr: typedndarray ) => boolean; - -/** -* Returns a boolean indicating whether an element passes a test. -* -* @param value - current array element -* @param indices - current array element indices -* @param arr - input array -* @returns boolean indicating whether an element passes a test -*/ -type Predicate = Nullary | Unary | Binary | Ternary; - -/** -* Interface describing "base" function options. -*/ -interface BaseOptions { - /** - * Index iteration order. - * - * ## Notes - * - * - By default, the function iterates over elements according to the layout order of the provided ndarray. Accordingly, for row-major input ndarrays, the last dimension indices increment fastest. For column-major input ndarrays, the first dimension indices increment fastest. To override the inferred order and ensure that indices increment in a specific manor, regardless of the input ndarray's layout order, explicitly set the iteration order. Note, however, that iterating according to an order which does not match that of the input ndarray may, in some circumstances, result in performance degradation due to cache misses. - */ - order?: Order; -} - -/** -* Interface describing function options. -*/ -interface OrderOptions { - /** - * Index iteration order. - * - * ## Notes - * - * - By default, the function iterates over elements according to the layout order of the provided ndarray. Accordingly, for row-major input ndarrays, the last dimension indices increment fastest. For column-major input ndarrays, the first dimension indices increment fastest. To override the inferred order and ensure that indices increment in a specific manor, regardless of the input ndarray's layout order, explicitly set the iteration order. Note, however, that iterating according to an order which does not match that of the input ndarray may, in some circumstances, result in performance degradation due to cache misses. - */ - order: Order; -} - -/** -* Interface describing function options. -*/ -interface Options extends BaseOptions { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: DataType; -} - -/** -* Interface describing function options. -*/ -interface Float64Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'float64'; -} - -/** -* Interface describing function options. -*/ -interface Float32Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'float32'; -} - -/** -* Interface describing function options. -*/ -interface Complex128Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'complex128'; -} - -/** -* Interface describing function options. -*/ -interface Complex64Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'complex64'; -} - -/** -* Interface describing function options. -*/ -interface Int32Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'int32'; -} - -/** -* Interface describing function options. -*/ -interface Int16Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'int16'; -} - -/** -* Interface describing function options. -*/ -interface Int8Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'int8'; -} - -/** -* Interface describing function options. -*/ -interface Uint32Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'uint32'; -} - -/** -* Interface describing function options. -*/ -interface Uint16Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'uint16'; -} - -/** -* Interface describing function options. -*/ -interface Uint8Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'uint8'; -} - -/** -* Interface describing function options. -*/ -interface Uint8COptions extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'uint8c'; -} - -/** -* Interface describing function options. -*/ -interface BoolOptions extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'bool'; -} - -/** -* Interface describing function options. -*/ -interface GenericOptions extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'generic'; -} - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: float64ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): float64ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float32Array = require( '@stdlib/array-float32' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Float32Array( [ 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( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: float32ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): float32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var Complex64Array = require( '@stdlib/array-complex64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* function predicate( z, idx ) { -* return idx[ 0 ] > 0; -* } -* -* var buffer = new Complex64Array( [ 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 = [ 3, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, predicate ); -* // returns -*/ -declare function filter( x: complex64ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): complex64ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* function predicate( z, idx ) { -* return idx[ 0 ] > 0; -* } -* -* var buffer = new Complex128Array( [ 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 = [ 3, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, predicate ); -* // returns -*/ -declare function filter( x: complex128ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): complex128ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Int32Array = require( '@stdlib/array-int32' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Int32Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: int32ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): int32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Int16Array = require( '@stdlib/array-int16' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Int16Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: int16ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): int16ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Int8Array = require( '@stdlib/array-int8' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Int8Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: int8ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): int8ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint32Array = require( '@stdlib/array-uint32' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint32Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint32ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): uint32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint16Array = require( '@stdlib/array-uint16' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint16Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint16ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): uint16ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint8Array = require( '@stdlib/array-uint8' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint8Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint8ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): uint8ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint8ClampedArray( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint8cndarray, predicate: Predicate, thisArg?: ThisParameterType> ): uint8cndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var BooleanArray = require( '@stdlib/array-bool' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* function predicate( z ) { -* return z; -* } -* -* var buffer = new BooleanArray( [ false, true, false, true, false, true, false, true, false, true, false, true ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'bool', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, predicate ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ true, true, true, true ] -*/ -declare function filter( x: boolndarray, predicate: Predicate, thisArg?: ThisParameterType> ): boolndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 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( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: genericndarray, predicate: Predicate, thisArg?: ThisParameterType> ): genericndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: float64ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): float64ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float32Array = require( '@stdlib/array-float32' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Float32Array( [ 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( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: float32ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): float32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var Complex64Array = require( '@stdlib/array-complex64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* function predicate( z, idx ) { -* return idx[ 0 ] > 0; -* } -* -* var buffer = new Complex64Array( [ 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 = [ 3, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, predicate ); -* // returns -*/ -declare function filter( x: complex64ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): complex64ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* function predicate( z, idx ) { -* return idx[ 0 ] > 0; -* } -* -* var buffer = new Complex128Array( [ 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 = [ 3, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, predicate ); -* // returns -*/ -declare function filter( x: complex128ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): complex128ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Int32Array = require( '@stdlib/array-int32' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Int32Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: int32ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): int32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Int16Array = require( '@stdlib/array-int16' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Int16Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: int16ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): int16ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Int8Array = require( '@stdlib/array-int8' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Int8Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: int8ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): int8ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint32Array = require( '@stdlib/array-uint32' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint32Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint32ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): uint32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint16Array = require( '@stdlib/array-uint16' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint16Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint16ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): uint16ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint8Array = require( '@stdlib/array-uint8' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint8Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint8ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): uint8ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint8ClampedArray( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint8cndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): uint8cndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var BooleanArray = require( '@stdlib/array-bool' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* function predicate( z ) { -* return z; -* } -* -* var buffer = new BooleanArray( [ false, true, false, true, false, true, false, true, false, true, false, true ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'bool', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, predicate ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ true, true, true, true ] -*/ -declare function filter( x: boolndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): boolndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 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( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: genericndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): genericndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'float64' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: typedndarray, options: Float64Options, predicate: Predicate, thisArg?: ThisParameterType> ): float64ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'float32' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: typedndarray, options: Float32Options, predicate: Predicate, thisArg?: ThisParameterType> ): float32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* function predicate( z, idx ) { -* return idx[ 0 ] > 0; -* } -* -* var buffer = new Complex128Array( [ 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 = [ 3, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'dtype': 'complex128' -* }; -* var y = filter( x, opts, predicate ); -* // returns -*/ -declare function filter( x: typedndarray, options: Complex128Options, predicate: Predicate, thisArg?: ThisParameterType> ): complex128ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* function predicate( z, idx ) { -* return idx[ 0 ] > 0; -* } -* -* var buffer = new Complex128Array( [ 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 = [ 3, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'dtype': 'complex64' -* }; -* var y = filter( x, opts, predicate ); -* // returns -*/ -declare function filter( x: typedndarray, options: Complex64Options, predicate: Predicate, thisArg?: ThisParameterType> ): complex64ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'int32' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: typedndarray, options: Int32Options, predicate: Predicate, thisArg?: ThisParameterType> ): int32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'int16' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: typedndarray, options: Int16Options, predicate: Predicate, thisArg?: ThisParameterType> ): int16ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'int8' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: typedndarray, options: Int8Options, predicate: Predicate, thisArg?: ThisParameterType> ): int8ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'uint32' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: typedndarray, options: Uint32Options, predicate: Predicate, thisArg?: ThisParameterType> ): uint32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'uint16' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: typedndarray, options: Uint16Options, predicate: Predicate, thisArg?: ThisParameterType> ): uint16ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'uint8' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: typedndarray, options: Uint8Options, predicate: Predicate, thisArg?: ThisParameterType> ): uint8ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'uint8c' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: typedndarray, options: Uint8COptions, predicate: Predicate, thisArg?: ThisParameterType> ): uint8cndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'bool' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ true, true, true, true ] -*/ -declare function filter( x: typedndarray, options: BoolOptions, predicate: Predicate, thisArg?: ThisParameterType> ): boolndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'generic' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: typedndarray, options: GenericOptions, predicate: Predicate, thisArg?: ThisParameterType> ): genericndarray; - - -// EXPORTS // - -export = filter; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index f1c84f4..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import e 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 a from"https://cdn.jsdelivr.net/gh/stdlib-js/blas-base-gcopy@v0.2.1-esm/index.mjs";import h 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,G;if(!e(v))throw new TypeError(h("null5t",v));if(arguments.length<3?w=f:3===arguments.length?s(f)?(w=f,k=b):(g=!0,u=f,w=b):(g=!0,u=f,w=b,k=c),!s(w))throw new TypeError(h("null2b",w));if(g){if(!r(u))throw new TypeError(h("null2V",u));if(q=n(u,"dtype")?u.dtype:m(v),n(u,"order")){if(!t(u.order))throw new TypeError(h("null5C","order",u.order));z=u.order}}else q=m(v);if(null===(E=d(q)))throw new TypeError(h("nullBf","dtype",u.dtype));for(void 0===z&&(z=l(v)),A=o(v),D=p(A),y=A.length,B="row-major"===z?y-1:0,C=i(y),x={length:0},T=-1,G=0;G0&&(C=j(A,z,C,B,C)),F=v.get.apply(v,C),w.call(k,F,C.slice(),v)&&(x.length+=1,x[T+=1]=F);return V=new E(D=x.length),a(D,x,1,V,1),new v.constructor(q,V,[D],[1],0,z)}export{v as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index c68f119..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 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* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate 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 {boolean} [options.order='row-major'] - index iteration order\n* @param {Callback} predicate - predicate function\n* @param {*} [thisArg] - predicate 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 { isPrimitive as isEven } from '@stdlib/assert-is-even';\n* import Float64Array from '@stdlib/array-float64';\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndarray2array from '@stdlib/ndarray-to-array';\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 = filter( x, isEven );\n* // returns \n*\n* var arr = ndarray2array( y );\n* // returns [ 2.0, 4.0, 8.0, 10.0 ]\n*/\nfunction filter( x, options, predicate, thisArg ) {\n\tvar hasOpts;\n\tvar ndims;\n\tvar cache;\n\tvar clbk;\n\tvar opts;\n\tvar ctor;\n\tvar cidx;\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 = predicate;\n\t\t} else {\n\t\t\thasOpts = true;\n\t\t\topts = options;\n\t\t\tclbk = predicate;\n\t\t}\n\t} else {\n\t\thasOpts = true;\n\t\topts = options;\n\t\tclbk = predicate;\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 predicate 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 elements according to a predicate function...\n\tcidx = -1;\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 = x.get.apply( x, idx );\n\t\tif ( clbk.call( ctx, v, idx.slice(), x ) ) {\n\t\t\tcache.length += 1;\n\t\t\tcidx += 1;\n\t\t\tcache[ cidx ] = v;\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 filter;\n"],"names":["filter","x","options","predicate","thisArg","hasOpts","ndims","cache","clbk","opts","ctor","cidx","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","get","apply","call","slice","gcopy","constructor"],"mappings":";;6zCA0EA,SAASA,EAAQC,EAAGC,EAASC,EAAWC,GACvC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEAC,EACAC,EACJ,IAAMC,EAAerB,GACpB,MAAM,IAAIsB,UAAWC,EAAQ,SAAUvB,IAmBxC,GAjBKwB,UAAUC,OAAS,EACvBlB,EAAON,EACyB,IAArBuB,UAAUC,OAChBC,EAAYzB,IAChBM,EAAON,EACPU,EAAMT,IAENE,GAAU,EACVI,EAAOP,EACPM,EAAOL,IAGRE,GAAU,EACVI,EAAOP,EACPM,EAAOL,EACPS,EAAMR,IAEDuB,EAAYnB,GACjB,MAAM,IAAIe,UAAWC,EAAQ,SAAUhB,IAExC,GAAKH,EAAU,CACd,IAAMuB,EAAenB,GACpB,MAAM,IAAIc,UAAWC,EAAQ,SAAUf,IAOxC,GAJCQ,EADIY,EAAYpB,EAAM,SACjBA,EAAKqB,MAELC,EAAU9B,GAEX4B,EAAYpB,EAAM,SAAY,CAClC,IAAMuB,EAASvB,EAAKwB,OACnB,MAAM,IAAIV,UAAWC,EAAQ,SAAU,QAASf,EAAKwB,QAEtDpB,EAAMJ,EAAKwB,KACX,CACH,MACEhB,EAAKc,EAAU9B,GAIhB,GAAc,QADdS,EAAOwB,EAAOjB,IAGb,MAAM,IAAIM,UAAWC,EAAQ,SAAU,QAASf,EAAKqB,QA+BtD,SA5Ba,IAARjB,IACJA,EAAMsB,EAAUlC,IAGjBiB,EAAKkB,EAAUnC,GAGfkB,EAAIkB,EAAOnB,GAGXZ,EAAQY,EAAGQ,OAIVZ,EADY,cAARD,EACEP,EAAQ,EAER,EAGPS,EAAMuB,EAAOhC,GAGbC,EAAQ,CACPmB,OAAU,GAIXf,GAAQ,EACFU,EAAI,EAAGA,EAAIF,EAAGE,IACdA,EAAI,IACRN,EAAMwB,EAAoBrB,EAAIL,EAAKE,EAAKD,EAAKC,IAE9CK,EAAInB,EAAEuC,IAAIC,MAAOxC,EAAGc,GACfP,EAAKkC,KAAM9B,EAAKQ,EAAGL,EAAI4B,QAAS1C,KACpCM,EAAMmB,QAAU,EAEhBnB,EADAI,GAAQ,GACQS,GAelB,OARAJ,EAAM,IAAIN,EAHVS,EAAIZ,EAAMmB,QAMVkB,EAAOzB,EAAGZ,EAAO,EAAGS,EAAK,GAGrB,IAAIf,EAAE4C,YAAa5B,EAAID,EAAK,CAAEG,GAAK,CAAE,GAAK,EAAGN,EAGlD"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 7526b53..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Codestin Search App - - - -
- - - - - From abd146d1f6c31c401d43a5d717eb4d3dc931399f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 14 Dec 2024 09:10:48 +0000 Subject: [PATCH 11/35] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 52 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 65 +- SECURITY.md | 5 - benchmark/benchmark.1d.js | 150 - benchmark/benchmark.2d.js | 161 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 51 - docs/types/test.ts | 195 - examples/index.js | 38 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 55 - lib/main.js | 199 - package.json | 84 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 892 ---- 44 files changed, 4878 insertions(+), 5316 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.1d.js delete mode 100644 benchmark/benchmark.2d.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 03a0613..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) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 48af73a..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) 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 443f7ec..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: '9 21 * * 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 + + ```
@@ -213,7 +204,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]. @@ -276,11 +267,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-filter/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 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 6958f29..0000000 --- a/benchmark/benchmark.1d.js +++ /dev/null @@ -1,150 +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 filter = require( './../lib' ); - - -// VARIABLES // - -var xtypes = [ 'generic' ]; -var ytypes = [ 'float64' ]; -var orders = [ 'row-major', 'column-major' ]; - - -// FUNCTIONS // - -/** -* Predicate function. -* -* @private -* @param {number} value - array element -* @param {NonNegativeIntegerArray} indices - element indices -* @param {ndarray} arr - input array -* @returns {boolean} result -*/ -function predicate( value ) { - return value > 0.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 = filter( x, opts, predicate ); - 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 c70a9f1..0000000 --- a/benchmark/benchmark.2d.js +++ /dev/null @@ -1,161 +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 filter = require( './../lib' ); - - -// VARIABLES // - -var xtypes = [ 'generic' ]; -var ytypes = [ 'float64' ]; -var orders = [ 'row-major', 'column-major' ]; - - -// FUNCTIONS // - -/** -* Predicate function. -* -* @private -* @param {number} value - array element -* @param {NonNegativeIntegerArray} indices - element indices -* @param {ndarray} arr - input array -* @returns {boolean} result -*/ -function predicate( value ) { - return value > 0.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 = filter( x, opts, predicate ); - 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 51e4f91..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" -%% click B href "https://github.com/stdlib-js/ndarray-filter/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-filter/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-filter/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-filter/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-filter/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/filter -[production-url]: https://github.com/stdlib-js/ndarray-filter/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-filter/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-filter/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-filter/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-filter/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-filter/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-filter/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 aafb9cb..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import filter from '../docs/types/index'; -export = filter; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 558b3a7..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var V=function(r,a){return function(){return a||r((a={exports:{}}).exports,a),a.exports}};var k=V(function(K,j){"use strict";var C=require("@stdlib/assert-is-plain-object"),O=require("@stdlib/assert-is-function"),F=require("@stdlib/assert-is-ndarray-like"),P=require("@stdlib/ndarray-base-assert-is-order"),T=require("@stdlib/assert-has-own-property"),D=require("@stdlib/ndarray-base-buffer-ctors"),I=require("@stdlib/array-base-zeros"),L=require("@stdlib/ndarray-shape"),E=require("@stdlib/ndarray-dtype"),N=require("@stdlib/ndarray-order"),S=require("@stdlib/ndarray-base-numel"),A=require("@stdlib/ndarray-base-next-cartesian-index").assign,B=require("@stdlib/blas-base-gcopy"),v=require("@stdlib/string-format");function G(r,a,g,z){var c,f,o,i,e,p,m,h,t,y,n,q,s,l,u,b,w,d;if(!F(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?O(a)?(i=a,h=g):(c=!0,e=a,i=g):(c=!0,e=a,i=g,h=z),!O(i))throw new TypeError(v("invalid argument. Callback argument must be a function. Value: `%s`.",i));if(c){if(!C(e))throw new TypeError(v("invalid argument. Options argument must be an object. Value: `%s`.",e));if(T(e,"dtype")?s=e.dtype:s=E(r),T(e,"order")){if(!P(e.order))throw new TypeError(v("invalid option. `%s` option must be a recognized order. Option: `%s`.","order",e.order));t=e.order}}else s=E(r);if(p=D(s),p===null)throw new TypeError(v("invalid option. `%s` option must be a recognized data type. Option: `%s`.","dtype",e.dtype));for(t===void 0&&(t=N(r)),l=L(r),u=S(l),f=l.length,t==="row-major"?y=f-1:y=0,n=I(f),o={length:0},m=-1,d=0;d0&&(n=A(l,t,n,y,n)),w=r.get.apply(r,n),i.call(h,w,n.slice(),r)&&(o.length+=1,m+=1,o[m]=w);return u=o.length,q=new p(u),B(u,o,1,q,1),b=new r.constructor(s,q,[u],[1],0,t),b}j.exports=G});var H=k();module.exports=H; -/** -* @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 d4c9544..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* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate 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 {boolean} [options.order] - index iteration order\n* @param {Callback} predicate - predicate function\n* @param {*} [thisArg] - predicate 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 isEven = require( '@stdlib/assert-is-even' ).isPrimitive;\n* var Float64Array = require( '@stdlib/array-float64' );\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\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 = filter( x, isEven );\n* // returns \n*\n* var arr = ndarray2array( y );\n* // returns [ 2.0, 4.0, 8.0, 10.0 ]\n*/\nfunction filter( x, options, predicate, thisArg ) {\n\tvar hasOpts;\n\tvar ndims;\n\tvar cache;\n\tvar clbk;\n\tvar opts;\n\tvar ctor;\n\tvar cidx;\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 = predicate;\n\t\t} else {\n\t\t\thasOpts = true;\n\t\t\topts = options;\n\t\t\tclbk = predicate;\n\t\t}\n\t} else {\n\t\thasOpts = true;\n\t\topts = options;\n\t\tclbk = predicate;\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 predicate 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 elements according to a predicate function...\n\tcidx = -1;\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 = x.get.apply( x, idx );\n\t\tif ( clbk.call( ctx, v, idx.slice(), x ) ) {\n\t\t\tcache.length += 1;\n\t\t\tcidx += 1;\n\t\t\tcache[ cidx ] = v;\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 = filter;\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* Return a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function.\n*\n* @module @stdlib/ndarray-filter\n*\n* @example\n* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive;\n* var Float64Array = require( '@stdlib/array-float64' );\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var filter = require( '@stdlib/ndarray-filter' );\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 = filter( x, isEven );\n* // returns \n*\n* var arr = ndarray2array( y );\n* // returns [ 2.0, 4.0, 8.0, 10.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,EAuC9C,SAASC,EAAQC,EAAGC,EAASC,EAAWC,EAAU,CACjD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,GAAK,CAAClC,EAAea,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,gFAAiFE,CAAE,CAAE,EAmBnH,GAjBK,UAAU,OAAS,EACvBO,EAAON,EACI,UAAU,SAAW,EAC3Bf,EAAYe,CAAQ,GACxBM,EAAON,EACPU,EAAMT,IAENE,EAAU,GACVI,EAAOP,EACPM,EAAOL,IAGRE,EAAU,GACVI,EAAOP,EACPM,EAAOL,EACPS,EAAMR,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,EAC9BQ,EAAKR,EAAK,MAEVQ,EAAKvB,EAAUO,CAAE,EAEbX,EAAYmB,EAAM,OAAQ,EAAI,CAClC,GAAK,CAACpB,EAASoB,EAAK,KAAM,EACzB,MAAM,IAAI,UAAWV,EAAQ,wEAAyE,QAASU,EAAK,KAAM,CAAE,EAE7HI,EAAMJ,EAAK,KACZ,CACD,MACCQ,EAAKvB,EAAUO,CAAE,EAIlB,GADAS,EAAOnB,EAAO0B,CAAG,EACZP,IAAS,KAEb,MAAM,IAAI,UAAWX,EAAQ,4EAA6E,QAASU,EAAK,KAAM,CAAE,EA+BjI,IA5BKI,IAAQ,SACZA,EAAMlB,EAAUM,CAAE,GAGnBiB,EAAKzB,EAAUQ,CAAE,EAGjBkB,EAAIvB,EAAOsB,CAAG,EAGdZ,EAAQY,EAAG,OAGNL,IAAQ,YACZC,EAAMR,EAAQ,EAEdQ,EAAM,EAGPC,EAAMvB,EAAOc,CAAM,EAGnBC,EAAQ,CACP,OAAU,CACX,EAGAI,EAAO,GACDW,EAAI,EAAGA,EAAIH,EAAGG,IACdA,EAAI,IACRP,EAAMlB,EAAoBqB,EAAIL,EAAKE,EAAKD,EAAKC,CAAI,GAElDM,EAAIpB,EAAE,IAAI,MAAOA,EAAGc,CAAI,EACnBP,EAAK,KAAMI,EAAKS,EAAGN,EAAI,MAAM,EAAGd,CAAE,IACtCM,EAAM,QAAU,EAChBI,GAAQ,EACRJ,EAAOI,CAAK,EAAIU,GAIlB,OAAAF,EAAIZ,EAAM,OAGVS,EAAM,IAAIN,EAAMS,CAAE,EAGlBrB,EAAOqB,EAAGZ,EAAO,EAAGS,EAAK,CAAE,EAG3BI,EAAI,IAAInB,EAAE,YAAagB,EAAID,EAAK,CAAEG,CAAE,EAAG,CAAE,CAAE,EAAG,EAAGN,CAAI,EAE9CO,CACR,CAKAnC,EAAO,QAAUe,ICrJjB,IAAIuB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isPlainObject", "isFunction", "isndarrayLike", "isOrder", "hasOwnProp", "ctors", "zeros", "getShape", "getDType", "getOrder", "numel", "nextCartesianIndex", "gcopy", "format", "filter", "x", "options", "predicate", "thisArg", "hasOpts", "ndims", "cache", "clbk", "opts", "ctor", "cidx", "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 8ed7071..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,51 +0,0 @@ - -{{alias}}( x[, options], predicate[, thisArg] ) - Returns a shallow copy of an ndarray containing only those elements which - pass a test implemented by a predicate function. - - The predicate function is provided the following arguments: - - - value: current array element. - - indices: current array element indices. - - arr: the input 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 manor, 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'. - - predicate: Function - Predicate function. - - thisArg: any (optional) - Predicate function execution context. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ); - > function f( v ) { return v > 2.0; }; - > var y = {{alias}}( x, f ); - > {{alias:@stdlib/ndarray/to-array}}( y ) - [ 3.0, 4.0 ] - - See Also - -------- diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 046dffb..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,195 +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 empty = require( '@stdlib/ndarray-base-empty' ); -import zeros = require( '@stdlib/ndarray-base-zeros' ); -import filter = require( './index' ); - -/** -* Predicate function. -* -* @param x - input value -* @returns result -*/ -function predicate( x: any ): boolean { - return Boolean( x ); -} - -// The function returns an ndarray... -{ - const sh = [ 2, 2 ]; - const ord = 'row-major'; - - filter( zeros( 'float64', sh, ord ), predicate ); // $ExpectType float64ndarray - filter( zeros( 'float64', sh, ord ), predicate, {} ); // $ExpectType float64ndarray - filter( zeros( 'float32', sh, ord ), predicate ); // $ExpectType float32ndarray - filter( zeros( 'float32', sh, ord ), predicate, {} ); // $ExpectType float32ndarray - filter( zeros( 'complex64', sh, ord ), predicate ); // $ExpectType complex64ndarray - filter( zeros( 'complex64', sh, ord ), predicate, {} ); // $ExpectType complex64ndarray - filter( zeros( 'complex128', sh, ord ), predicate ); // $ExpectType complex128ndarray - filter( zeros( 'complex128', sh, ord ), predicate, {} ); // $ExpectType complex128ndarray - filter( zeros( 'int32', sh, ord ), predicate ); // $ExpectType int32ndarray - filter( zeros( 'int32', sh, ord ), predicate, {} ); // $ExpectType int32ndarray - filter( zeros( 'int16', sh, ord ), predicate ); // $ExpectType int16ndarray - filter( zeros( 'int16', sh, ord ), predicate, {} ); // $ExpectType int16ndarray - filter( zeros( 'int8', sh, ord ), predicate ); // $ExpectType int8ndarray - filter( zeros( 'int8', sh, ord ), predicate, {} ); // $ExpectType int8ndarray - filter( zeros( 'uint32', sh, ord ), predicate ); // $ExpectType uint32ndarray - filter( zeros( 'uint32', sh, ord ), predicate, {} ); // $ExpectType uint32ndarray - filter( zeros( 'uint16', sh, ord ), predicate ); // $ExpectType uint16ndarray - filter( zeros( 'uint16', sh, ord ), predicate, {} ); // $ExpectType uint16ndarray - filter( zeros( 'uint8', sh, ord ), predicate ); // $ExpectType uint8ndarray - filter( zeros( 'uint8', sh, ord ), predicate, {} ); // $ExpectType uint8ndarray - filter( zeros( 'uint8c', sh, ord ), predicate ); // $ExpectType uint8cndarray - filter( zeros( 'uint8c', sh, ord ), predicate, {} ); // $ExpectType uint8cndarray - filter( empty( 'bool', sh, ord ), predicate ); // $ExpectType boolndarray - filter( empty( 'bool', sh, ord ), predicate, {} ); // $ExpectType boolndarray - filter( zeros( 'generic', sh, ord ), predicate ); // $ExpectType genericndarray - filter( zeros( 'generic', sh, ord ), predicate, {} ); // $ExpectType genericndarray - - - filter( zeros( 'generic', sh, ord ), { 'dtype': 'float64' }, predicate ); // $ExpectType float64ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'float64' }, predicate, {} ); // $ExpectType float64ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'float32' }, predicate ); // $ExpectType float32ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'float32' }, predicate, {} ); // $ExpectType float32ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'complex64' }, predicate ); // $ExpectType complex64ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'complex64' }, predicate, {} ); // $ExpectType complex64ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'complex128' }, predicate ); // $ExpectType complex128ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'complex128' }, predicate, {} ); // $ExpectType complex128ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'int32' }, predicate ); // $ExpectType int32ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'int32' }, predicate, {} ); // $ExpectType int32ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'int16' }, predicate ); // $ExpectType int16ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'int16' }, predicate, {} ); // $ExpectType int16ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'int8' }, predicate ); // $ExpectType int8ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'int8' }, predicate, {} ); // $ExpectType int8ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint32' }, predicate ); // $ExpectType uint32ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint32' }, predicate, {} ); // $ExpectType uint32ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint16' }, predicate ); // $ExpectType uint16ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint16' }, predicate, {} ); // $ExpectType uint16ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint8' }, predicate ); // $ExpectType uint8ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint8' }, predicate, {} ); // $ExpectType uint8ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint8c' }, predicate ); // $ExpectType uint8cndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint8c' }, predicate, {} ); // $ExpectType uint8cndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'bool' }, predicate ); // $ExpectType boolndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'bool' }, predicate, {} ); // $ExpectType boolndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'generic' }, predicate ); // $ExpectType genericndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'generic' }, predicate, {} ); // $ExpectType genericndarray - - - filter( zeros( 'float64', sh, ord ), { 'order': ord }, predicate ); // $ExpectType float64ndarray - filter( zeros( 'float64', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType float64ndarray - filter( zeros( 'float32', sh, ord ), { 'order': ord }, predicate ); // $ExpectType float32ndarray - filter( zeros( 'float32', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType float32ndarray - filter( zeros( 'complex64', sh, ord ), { 'order': ord }, predicate ); // $ExpectType complex64ndarray - filter( zeros( 'complex64', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType complex64ndarray - filter( zeros( 'complex128', sh, ord ), { 'order': ord }, predicate ); // $ExpectType complex128ndarray - filter( zeros( 'complex128', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType complex128ndarray - filter( zeros( 'int32', sh, ord ), { 'order': ord }, predicate ); // $ExpectType int32ndarray - filter( zeros( 'int32', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType int32ndarray - filter( zeros( 'int16', sh, ord ), { 'order': ord }, predicate ); // $ExpectType int16ndarray - filter( zeros( 'int16', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType int16ndarray - filter( zeros( 'int8', sh, ord ), { 'order': ord }, predicate ); // $ExpectType int8ndarray - filter( zeros( 'int8', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType int8ndarray - filter( zeros( 'uint32', sh, ord ), { 'order': ord }, predicate ); // $ExpectType uint32ndarray - filter( zeros( 'uint32', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType uint32ndarray - filter( zeros( 'uint16', sh, ord ), { 'order': ord }, predicate ); // $ExpectType uint16ndarray - filter( zeros( 'uint16', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType uint16ndarray - filter( zeros( 'uint8', sh, ord ), { 'order': ord }, predicate ); // $ExpectType uint8ndarray - filter( zeros( 'uint8', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType uint8ndarray - filter( zeros( 'uint8c', sh, ord ), { 'order': ord }, predicate ); // $ExpectType uint8cndarray - filter( zeros( 'uint8c', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType uint8cndarray - filter( empty( 'bool', sh, ord ), { 'order': ord }, predicate ); // $ExpectType boolndarray - filter( empty( 'bool', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType boolndarray - filter( zeros( 'generic', sh, ord ), { 'order': ord }, predicate ); // $ExpectType genericndarray - filter( zeros( 'generic', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType genericndarray - -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - filter( 5, predicate ); // $ExpectError - filter( true, predicate ); // $ExpectError - filter( false, predicate ); // $ExpectError - filter( null, predicate ); // $ExpectError - filter( undefined, predicate ); // $ExpectError - filter( {}, predicate ); // $ExpectError - filter( [ 1 ], predicate ); // $ExpectError - filter( ( x: number ): number => x, predicate ); // $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' ); - - filter( x, '5' ); // $ExpectError - filter( x, true ); // $ExpectError - filter( x, false ); // $ExpectError - filter( x, null ); // $ExpectError - filter( x, undefined ); // $ExpectError - filter( x, {} ); // $ExpectError - filter( 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' ); - - filter( x, '10', predicate, {} ); // $ExpectError - filter( x, 10, predicate, {} ); // $ExpectError - filter( x, false, predicate, {} ); // $ExpectError - filter( x, true, predicate, {} ); // $ExpectError - filter( x, [], predicate, {} ); // $ExpectError - filter( x, ( x: number ): number => x, predicate, {} ); // $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' ); - - filter( x, { 'dtype': '10' }, predicate ); // $ExpectError - filter( x, { 'dtype': 10 }, predicate ); // $ExpectError - filter( x, { 'dtype': null }, predicate ); // $ExpectError - filter( x, { 'dtype': false }, predicate ); // $ExpectError - filter( x, { 'dtype': true }, predicate ); // $ExpectError - filter( x, { 'dtype': [] }, predicate ); // $ExpectError - filter( x, { 'dtype': {} }, predicate ); // $ExpectError - filter( x, { 'dtype': ( x: number ): number => x }, predicate ); // $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' ); - - filter( x, { 'order': '10' }, predicate ); // $ExpectError - filter( x, { 'order': 10 }, predicate ); // $ExpectError - filter( x, { 'order': null }, predicate ); // $ExpectError - filter( x, { 'order': false }, predicate ); // $ExpectError - filter( x, { 'order': true }, predicate ); // $ExpectError - filter( x, { 'order': [] }, predicate ); // $ExpectError - filter( x, { 'order': {} }, predicate ); // $ExpectError - filter( x, { 'order': ( x: number ): number => x }, predicate ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - filter(); // $ExpectError - filter( zeros( 'float64', [ 2, 2 ], 'row-major' ) ); // $ExpectError - filter( 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 e2dd6cb..0000000 --- a/examples/index.js +++ /dev/null @@ -1,38 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var array = require( '@stdlib/ndarray-array' ); -var isPositive = require( '@stdlib/assert-is-positive-number' ).isPrimitive; -var filter = require( './../lib' ); - -var buffer = discreteUniform( 10, -100, 100, { - 'dtype': 'generic' -}); -var x = array( buffer, { - 'shape': [ 5, 2 ], - 'dtype': 'generic' -}); -console.log( ndarray2array( x ) ); - -var y = filter( x, naryFunction( isPositive, 1 ) ); -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 a39a064..e2a9d07 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..f1c84f4 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import e 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 a from"https://cdn.jsdelivr.net/gh/stdlib-js/blas-base-gcopy@v0.2.1-esm/index.mjs";import h 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,G;if(!e(v))throw new TypeError(h("null5t",v));if(arguments.length<3?w=f:3===arguments.length?s(f)?(w=f,k=b):(g=!0,u=f,w=b):(g=!0,u=f,w=b,k=c),!s(w))throw new TypeError(h("null2b",w));if(g){if(!r(u))throw new TypeError(h("null2V",u));if(q=n(u,"dtype")?u.dtype:m(v),n(u,"order")){if(!t(u.order))throw new TypeError(h("null5C","order",u.order));z=u.order}}else q=m(v);if(null===(E=d(q)))throw new TypeError(h("nullBf","dtype",u.dtype));for(void 0===z&&(z=l(v)),A=o(v),D=p(A),y=A.length,B="row-major"===z?y-1:0,C=i(y),x={length:0},T=-1,G=0;G0&&(C=j(A,z,C,B,C)),F=v.get.apply(v,C),w.call(k,F,C.slice(),v)&&(x.length+=1,x[T+=1]=F);return V=new E(D=x.length),a(D,x,1,V,1),new v.constructor(q,V,[D],[1],0,z)}export{v as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..b080961 --- /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* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate 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 {boolean} [options.order] - index iteration order\n* @param {Callback} predicate - predicate function\n* @param {*} [thisArg] - predicate 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 { isPrimitive as isEven } from '@stdlib/assert-is-even';\n* import Float64Array from '@stdlib/array-float64';\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndarray2array from '@stdlib/ndarray-to-array';\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 = filter( x, isEven );\n* // returns \n*\n* var arr = ndarray2array( y );\n* // returns [ 2.0, 4.0, 8.0, 10.0 ]\n*/\nfunction filter( x, options, predicate, thisArg ) {\n\tvar hasOpts;\n\tvar ndims;\n\tvar cache;\n\tvar clbk;\n\tvar opts;\n\tvar ctor;\n\tvar cidx;\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 = predicate;\n\t\t} else {\n\t\t\thasOpts = true;\n\t\t\topts = options;\n\t\t\tclbk = predicate;\n\t\t}\n\t} else {\n\t\thasOpts = true;\n\t\topts = options;\n\t\tclbk = predicate;\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 predicate 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 elements according to a predicate function...\n\tcidx = -1;\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 = x.get.apply( x, idx );\n\t\tif ( clbk.call( ctx, v, idx.slice(), x ) ) {\n\t\t\tcache.length += 1;\n\t\t\tcidx += 1;\n\t\t\tcache[ cidx ] = v;\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 filter;\n"],"names":["filter","x","options","predicate","thisArg","hasOpts","ndims","cache","clbk","opts","ctor","cidx","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","get","apply","call","slice","gcopy","constructor"],"mappings":";;6zCA0EA,SAASA,EAAQC,EAAGC,EAASC,EAAWC,GACvC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEAC,EACAC,EACJ,IAAMC,EAAerB,GACpB,MAAM,IAAIsB,UAAWC,EAAQ,SAAUvB,IAmBxC,GAjBKwB,UAAUC,OAAS,EACvBlB,EAAON,EACyB,IAArBuB,UAAUC,OAChBC,EAAYzB,IAChBM,EAAON,EACPU,EAAMT,IAENE,GAAU,EACVI,EAAOP,EACPM,EAAOL,IAGRE,GAAU,EACVI,EAAOP,EACPM,EAAOL,EACPS,EAAMR,IAEDuB,EAAYnB,GACjB,MAAM,IAAIe,UAAWC,EAAQ,SAAUhB,IAExC,GAAKH,EAAU,CACd,IAAMuB,EAAenB,GACpB,MAAM,IAAIc,UAAWC,EAAQ,SAAUf,IAOxC,GAJCQ,EADIY,EAAYpB,EAAM,SACjBA,EAAKqB,MAELC,EAAU9B,GAEX4B,EAAYpB,EAAM,SAAY,CAClC,IAAMuB,EAASvB,EAAKwB,OACnB,MAAM,IAAIV,UAAWC,EAAQ,SAAU,QAASf,EAAKwB,QAEtDpB,EAAMJ,EAAKwB,KACX,CACH,MACEhB,EAAKc,EAAU9B,GAIhB,GAAc,QADdS,EAAOwB,EAAOjB,IAGb,MAAM,IAAIM,UAAWC,EAAQ,SAAU,QAASf,EAAKqB,QA+BtD,SA5Ba,IAARjB,IACJA,EAAMsB,EAAUlC,IAGjBiB,EAAKkB,EAAUnC,GAGfkB,EAAIkB,EAAOnB,GAGXZ,EAAQY,EAAGQ,OAIVZ,EADY,cAARD,EACEP,EAAQ,EAER,EAGPS,EAAMuB,EAAOhC,GAGbC,EAAQ,CACPmB,OAAU,GAIXf,GAAQ,EACFU,EAAI,EAAGA,EAAIF,EAAGE,IACdA,EAAI,IACRN,EAAMwB,EAAoBrB,EAAIL,EAAKE,EAAKD,EAAKC,IAE9CK,EAAInB,EAAEuC,IAAIC,MAAOxC,EAAGc,GACfP,EAAKkC,KAAM9B,EAAKQ,EAAGL,EAAI4B,QAAS1C,KACpCM,EAAMmB,QAAU,EAEhBnB,EADAI,GAAQ,GACQS,GAelB,OARAJ,EAAM,IAAIN,EAHVS,EAAIZ,EAAMmB,QAMVkB,EAAOzB,EAAGZ,EAAO,EAAGS,EAAK,GAGrB,IAAIf,EAAE4C,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 46f5998..0000000 --- a/lib/index.js +++ /dev/null @@ -1,55 +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'; - -/** -* Return a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @module @stdlib/ndarray-filter -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var filter = require( '@stdlib/ndarray-filter' ); -* -* 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 = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.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 f101a98..0000000 --- a/lib/main.js +++ /dev/null @@ -1,199 +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/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param {ndarray} x - input ndarray -* @param {Options} [options] - function options -* @param {string} [options.dtype] - output array data type -* @param {boolean} [options.order] - index iteration order -* @param {Callback} predicate - predicate function -* @param {*} [thisArg] - predicate 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 isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -function filter( x, options, predicate, thisArg ) { - var hasOpts; - var ndims; - var cache; - var clbk; - var opts; - var ctor; - var cidx; - 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( 'null5t', x ) ); - } - if ( arguments.length < 3 ) { - clbk = options; - } else if ( arguments.length === 3 ) { - if ( isFunction( options ) ) { - clbk = options; - ctx = predicate; - } else { - hasOpts = true; - opts = options; - clbk = predicate; - } - } else { - hasOpts = true; - opts = options; - clbk = predicate; - ctx = thisArg; - } - if ( !isFunction( clbk ) ) { - throw new TypeError( format( 'null2b', clbk ) ); - } - if ( hasOpts ) { - if ( !isPlainObject( opts ) ) { - throw new TypeError( format( 'null2V', opts ) ); - } - if ( hasOwnProp( opts, 'dtype' ) ) { - dt = opts.dtype; - } else { - dt = getDType( x ); - } - if ( hasOwnProp( opts, 'order' ) ) { - if ( !isOrder( opts.order ) ) { - throw new TypeError( format( 'null5C', '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( 'nullBf', '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 predicate 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 elements according to a predicate function... - cidx = -1; - for ( i = 0; i < N; i++ ) { - if ( i > 0 ) { - idx = nextCartesianIndex( sh, ord, idx, dim, idx ); - } - v = x.get.apply( x, idx ); - if ( clbk.call( ctx, v, idx.slice(), x ) ) { - cache.length += 1; - cidx += 1; - cache[ cidx ] = v; - } - } - // 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 = filter; diff --git a/package.json b/package.json index a44b313..2473eda 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Return a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate 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,62 +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/error-tools-fmtprodmsg": "^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-positive-number": "^0.2.2", - "@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", - "@stdlib/utils-nary-function": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "strided", @@ -104,7 +25,6 @@ "select", "take" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..1f3c75d --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Codestin Search App + + + +
+ + + + + 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 3bea6b3..0000000 --- a/test/test.js +++ /dev/null @@ -1,892 +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 filter = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof filter, '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() { - filter( value, predicate ); - }; - } - - function predicate( z ) { - return ( z > 0.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() { - filter( 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() { - filter( 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() { - filter( x, value, predicate ); - }; - } - - function predicate( z ) { - return ( z > 0.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 - }; - filter( x, opts, predicate ); - }; - } - - function predicate( z ) { - return ( z > 0.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 - }; - filter( x, opts, predicate ); - }; - } - - function predicate( z ) { - return ( z > 0.0 ); - } -}); - -tape( 'the function filters an array according to a predicate 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 = filter( x, predicate ); - - expected = new Float64Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - - t.end(); - - function predicate( z ) { - return ( z > 0.0 ); - } -}); - -tape( 'the function filters an array according to a predicate 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 = filter( x, predicate ); - - expected = new Float64Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - - t.end(); - - function predicate( z ) { - return ( z > 0.0 ); - } -}); - -tape( 'the function filters an array according to a predicate 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 = filter( x, opts, predicate ); - - expected = new Float64Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - - opts = { - 'dtype': 'float32' - }; - y = filter( x, opts, predicate ); - - expected = new Float32Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat32Array( y.data, expected ), true, 'returns expected value' ); - - t.end(); - - function predicate( z ) { - return ( z > 0.0 ); - } -}); - -tape( 'the function filters an array according to a predicate 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 = filter( x, opts, predicate ); - - expected = new Float64Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - - opts = { - 'dtype': 'float32' - }; - y = filter( x, opts, predicate ); - - expected = new Float32Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat32Array( y.data, expected ), true, 'returns expected value' ); - - t.end(); - - function predicate( z ) { - return ( z > 0.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 = filter( x, predicate, ctx ); - - expected = new Float64Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function predicate( z ) { - this.count += 1; // eslint-disable-line no-invalid-this - return ( z > 0.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 = filter( x, {}, predicate, ctx ); - - expected = new Float64Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function predicate( z ) { - this.count += 1; // eslint-disable-line no-invalid-this - return ( z > 0.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 = filter( x, predicate ); - - expected = new Float64Array([ - 1.0, - 3.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 predicate( z, idx, arr ) { - values.push( z ); - indices.push( idx ); - arrays.push( arr ); - return ( z > 0.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 = filter( x, predicate ); - - expected = new Float64Array([ - 1.0, - 3.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 predicate( z, idx, arr ) { - values.push( z ); - indices.push( idx ); - arrays.push( arr ); - return ( z > 0.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 = filter( x, opts, predicate ); - - expected = new Float64Array([ - 1.0, - 3.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 predicate( z, idx, arr ) { - values.push( z ); - indices.push( idx ); - arrays.push( arr ); - return ( z > 0.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 = filter( x, opts, predicate ); - - expected = new Float64Array([ - 1.0, - 3.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 predicate( z, idx, arr ) { - values.push( z ); - indices.push( idx ); - arrays.push( arr ); - return ( z > 0.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 = filter( x, opts, predicate ); - - expected = new Float64Array([ - 1.0, - 3.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 predicate( z, idx, arr ) { - values.push( z ); - indices.push( idx ); - arrays.push( arr ); - return ( z > 0.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 = filter( x, opts, predicate ); - - expected = new Float64Array([ - 1.0, - 3.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 predicate( z, idx, arr ) { - values.push( z ); - indices.push( idx ); - arrays.push( arr ); - return ( z > 0.0 ); - } -}); From 29970ee6594d90c94937ee23789d0f92dd5ed4a8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 14 Dec 2024 09:19:22 +0000 Subject: [PATCH 12/35] Transform error messages --- lib/main.js | 12 ++++++------ package.json | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/main.js b/lib/main.js index 18a75ea..f101a98 100644 --- a/lib/main.js +++ b/lib/main.js @@ -33,7 +33,7 @@ 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' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -92,7 +92,7 @@ function filter( x, options, predicate, thisArg ) { var v; var i; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray-like object. Value: `%s`.', x ) ); + throw new TypeError( format( 'null5t', x ) ); } if ( arguments.length < 3 ) { clbk = options; @@ -112,11 +112,11 @@ function filter( x, options, predicate, thisArg ) { ctx = thisArg; } if ( !isFunction( clbk ) ) { - throw new TypeError( format( 'invalid argument. Callback argument must be a function. Value: `%s`.', clbk ) ); + throw new TypeError( format( 'null2b', clbk ) ); } if ( hasOpts ) { if ( !isPlainObject( opts ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) ); + throw new TypeError( format( 'null2V', opts ) ); } if ( hasOwnProp( opts, 'dtype' ) ) { dt = opts.dtype; @@ -125,7 +125,7 @@ function filter( x, options, predicate, thisArg ) { } 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 ) ); + throw new TypeError( format( 'null5C', 'order', opts.order ) ); } ord = opts.order; } @@ -136,7 +136,7 @@ function filter( x, options, predicate, thisArg ) { 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 ) ); + throw new TypeError( format( 'nullBf', 'dtype', opts.dtype ) ); } // Resolve the iteration order: if ( ord === void 0 ) { diff --git a/package.json b/package.json index 22065aa..a44b313 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@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/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From 7878e15cc892c46db05c8b8effe3572db8392b41 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 14 Dec 2024 09:19:48 +0000 Subject: [PATCH 13/35] Remove files --- index.d.ts | 1612 ---------------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 6459 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index e2a9d07..0000000 --- a/index.d.ts +++ /dev/null @@ -1,1612 +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. -*/ - -// TypeScript Version: 4.1 - -/// - -/* eslint-disable max-lines */ - -import { typedndarray, DataType, Order, float64ndarray, float32ndarray, complex128ndarray, complex64ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, boolndarray, genericndarray } from '@stdlib/types/ndarray'; -import { Complex64, Complex128 } from '@stdlib/types/complex'; - -/** -* Returns a boolean indicating whether an element passes a test. -* -* @returns boolean indicating whether an element passes a test -*/ -type Nullary = ( this: V ) => boolean; - -/** -* Returns a boolean indicating whether an element passes a test. -* -* @param value - current array element -* @returns boolean indicating whether an element passes a test -*/ -type Unary = ( this: V, value: T ) => boolean; - -/** -* Returns a boolean indicating whether an element passes a test. -* -* @param value - current array element -* @param indices - current array element indices -* @returns boolean indicating whether an element passes a test -*/ -type Binary = ( this: V, value: T, indices: Array ) => boolean; - -/** -* Returns a boolean indicating whether an element passes a test. -* -* @param value - current array element -* @param indices - current array element indices -* @param arr - input array -* @returns boolean indicating whether an element passes a test -*/ -type Ternary = ( this: V, value: T, indices: Array, arr: typedndarray ) => boolean; - -/** -* Returns a boolean indicating whether an element passes a test. -* -* @param value - current array element -* @param indices - current array element indices -* @param arr - input array -* @returns boolean indicating whether an element passes a test -*/ -type Predicate = Nullary | Unary | Binary | Ternary; - -/** -* Interface describing "base" function options. -*/ -interface BaseOptions { - /** - * Index iteration order. - * - * ## Notes - * - * - By default, the function iterates over elements according to the layout order of the provided ndarray. Accordingly, for row-major input ndarrays, the last dimension indices increment fastest. For column-major input ndarrays, the first dimension indices increment fastest. To override the inferred order and ensure that indices increment in a specific manor, regardless of the input ndarray's layout order, explicitly set the iteration order. Note, however, that iterating according to an order which does not match that of the input ndarray may, in some circumstances, result in performance degradation due to cache misses. - */ - order?: Order; -} - -/** -* Interface describing function options. -*/ -interface OrderOptions { - /** - * Index iteration order. - * - * ## Notes - * - * - By default, the function iterates over elements according to the layout order of the provided ndarray. Accordingly, for row-major input ndarrays, the last dimension indices increment fastest. For column-major input ndarrays, the first dimension indices increment fastest. To override the inferred order and ensure that indices increment in a specific manor, regardless of the input ndarray's layout order, explicitly set the iteration order. Note, however, that iterating according to an order which does not match that of the input ndarray may, in some circumstances, result in performance degradation due to cache misses. - */ - order: Order; -} - -/** -* Interface describing function options. -*/ -interface Options extends BaseOptions { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: DataType; -} - -/** -* Interface describing function options. -*/ -interface Float64Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'float64'; -} - -/** -* Interface describing function options. -*/ -interface Float32Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'float32'; -} - -/** -* Interface describing function options. -*/ -interface Complex128Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'complex128'; -} - -/** -* Interface describing function options. -*/ -interface Complex64Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'complex64'; -} - -/** -* Interface describing function options. -*/ -interface Int32Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'int32'; -} - -/** -* Interface describing function options. -*/ -interface Int16Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'int16'; -} - -/** -* Interface describing function options. -*/ -interface Int8Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'int8'; -} - -/** -* Interface describing function options. -*/ -interface Uint32Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'uint32'; -} - -/** -* Interface describing function options. -*/ -interface Uint16Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'uint16'; -} - -/** -* Interface describing function options. -*/ -interface Uint8Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'uint8'; -} - -/** -* Interface describing function options. -*/ -interface Uint8COptions extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'uint8c'; -} - -/** -* Interface describing function options. -*/ -interface BoolOptions extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'bool'; -} - -/** -* Interface describing function options. -*/ -interface GenericOptions extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'generic'; -} - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: float64ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): float64ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float32Array = require( '@stdlib/array-float32' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Float32Array( [ 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( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: float32ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): float32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var Complex64Array = require( '@stdlib/array-complex64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* function predicate( z, idx ) { -* return idx[ 0 ] > 0; -* } -* -* var buffer = new Complex64Array( [ 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 = [ 3, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, predicate ); -* // returns -*/ -declare function filter( x: complex64ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): complex64ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* function predicate( z, idx ) { -* return idx[ 0 ] > 0; -* } -* -* var buffer = new Complex128Array( [ 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 = [ 3, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, predicate ); -* // returns -*/ -declare function filter( x: complex128ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): complex128ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Int32Array = require( '@stdlib/array-int32' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Int32Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: int32ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): int32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Int16Array = require( '@stdlib/array-int16' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Int16Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: int16ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): int16ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Int8Array = require( '@stdlib/array-int8' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Int8Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: int8ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): int8ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint32Array = require( '@stdlib/array-uint32' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint32Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint32ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): uint32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint16Array = require( '@stdlib/array-uint16' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint16Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint16ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): uint16ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint8Array = require( '@stdlib/array-uint8' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint8Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint8ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): uint8ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint8ClampedArray( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint8cndarray, predicate: Predicate, thisArg?: ThisParameterType> ): uint8cndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var BooleanArray = require( '@stdlib/array-bool' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* function predicate( z ) { -* return z; -* } -* -* var buffer = new BooleanArray( [ false, true, false, true, false, true, false, true, false, true, false, true ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'bool', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, predicate ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ true, true, true, true ] -*/ -declare function filter( x: boolndarray, predicate: Predicate, thisArg?: ThisParameterType> ): boolndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 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( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: genericndarray, predicate: Predicate, thisArg?: ThisParameterType> ): genericndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: float64ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): float64ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float32Array = require( '@stdlib/array-float32' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Float32Array( [ 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( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: float32ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): float32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var Complex64Array = require( '@stdlib/array-complex64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* function predicate( z, idx ) { -* return idx[ 0 ] > 0; -* } -* -* var buffer = new Complex64Array( [ 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 = [ 3, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, predicate ); -* // returns -*/ -declare function filter( x: complex64ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): complex64ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* function predicate( z, idx ) { -* return idx[ 0 ] > 0; -* } -* -* var buffer = new Complex128Array( [ 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 = [ 3, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, predicate ); -* // returns -*/ -declare function filter( x: complex128ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): complex128ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Int32Array = require( '@stdlib/array-int32' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Int32Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: int32ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): int32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Int16Array = require( '@stdlib/array-int16' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Int16Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: int16ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): int16ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Int8Array = require( '@stdlib/array-int8' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Int8Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: int8ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): int8ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint32Array = require( '@stdlib/array-uint32' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint32Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint32ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): uint32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint16Array = require( '@stdlib/array-uint16' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint16Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint16ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): uint16ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint8Array = require( '@stdlib/array-uint8' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint8Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint8ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): uint8ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint8ClampedArray( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint8cndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): uint8cndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var BooleanArray = require( '@stdlib/array-bool' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* function predicate( z ) { -* return z; -* } -* -* var buffer = new BooleanArray( [ false, true, false, true, false, true, false, true, false, true, false, true ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'bool', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, predicate ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ true, true, true, true ] -*/ -declare function filter( x: boolndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): boolndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 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( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: genericndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): genericndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'float64' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: typedndarray, options: Float64Options, predicate: Predicate, thisArg?: ThisParameterType> ): float64ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'float32' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: typedndarray, options: Float32Options, predicate: Predicate, thisArg?: ThisParameterType> ): float32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* function predicate( z, idx ) { -* return idx[ 0 ] > 0; -* } -* -* var buffer = new Complex128Array( [ 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 = [ 3, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'dtype': 'complex128' -* }; -* var y = filter( x, opts, predicate ); -* // returns -*/ -declare function filter( x: typedndarray, options: Complex128Options, predicate: Predicate, thisArg?: ThisParameterType> ): complex128ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* function predicate( z, idx ) { -* return idx[ 0 ] > 0; -* } -* -* var buffer = new Complex128Array( [ 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 = [ 3, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'dtype': 'complex64' -* }; -* var y = filter( x, opts, predicate ); -* // returns -*/ -declare function filter( x: typedndarray, options: Complex64Options, predicate: Predicate, thisArg?: ThisParameterType> ): complex64ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'int32' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: typedndarray, options: Int32Options, predicate: Predicate, thisArg?: ThisParameterType> ): int32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'int16' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: typedndarray, options: Int16Options, predicate: Predicate, thisArg?: ThisParameterType> ): int16ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'int8' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: typedndarray, options: Int8Options, predicate: Predicate, thisArg?: ThisParameterType> ): int8ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'uint32' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: typedndarray, options: Uint32Options, predicate: Predicate, thisArg?: ThisParameterType> ): uint32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'uint16' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: typedndarray, options: Uint16Options, predicate: Predicate, thisArg?: ThisParameterType> ): uint16ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'uint8' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: typedndarray, options: Uint8Options, predicate: Predicate, thisArg?: ThisParameterType> ): uint8ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'uint8c' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: typedndarray, options: Uint8COptions, predicate: Predicate, thisArg?: ThisParameterType> ): uint8cndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'bool' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ true, true, true, true ] -*/ -declare function filter( x: typedndarray, options: BoolOptions, predicate: Predicate, thisArg?: ThisParameterType> ): boolndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'generic' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: typedndarray, options: GenericOptions, predicate: Predicate, thisArg?: ThisParameterType> ): genericndarray; - - -// EXPORTS // - -export = filter; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index f1c84f4..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import e 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 a from"https://cdn.jsdelivr.net/gh/stdlib-js/blas-base-gcopy@v0.2.1-esm/index.mjs";import h 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,G;if(!e(v))throw new TypeError(h("null5t",v));if(arguments.length<3?w=f:3===arguments.length?s(f)?(w=f,k=b):(g=!0,u=f,w=b):(g=!0,u=f,w=b,k=c),!s(w))throw new TypeError(h("null2b",w));if(g){if(!r(u))throw new TypeError(h("null2V",u));if(q=n(u,"dtype")?u.dtype:m(v),n(u,"order")){if(!t(u.order))throw new TypeError(h("null5C","order",u.order));z=u.order}}else q=m(v);if(null===(E=d(q)))throw new TypeError(h("nullBf","dtype",u.dtype));for(void 0===z&&(z=l(v)),A=o(v),D=p(A),y=A.length,B="row-major"===z?y-1:0,C=i(y),x={length:0},T=-1,G=0;G0&&(C=j(A,z,C,B,C)),F=v.get.apply(v,C),w.call(k,F,C.slice(),v)&&(x.length+=1,x[T+=1]=F);return V=new E(D=x.length),a(D,x,1,V,1),new v.constructor(q,V,[D],[1],0,z)}export{v as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index b080961..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 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* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate 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 {boolean} [options.order] - index iteration order\n* @param {Callback} predicate - predicate function\n* @param {*} [thisArg] - predicate 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 { isPrimitive as isEven } from '@stdlib/assert-is-even';\n* import Float64Array from '@stdlib/array-float64';\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndarray2array from '@stdlib/ndarray-to-array';\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 = filter( x, isEven );\n* // returns \n*\n* var arr = ndarray2array( y );\n* // returns [ 2.0, 4.0, 8.0, 10.0 ]\n*/\nfunction filter( x, options, predicate, thisArg ) {\n\tvar hasOpts;\n\tvar ndims;\n\tvar cache;\n\tvar clbk;\n\tvar opts;\n\tvar ctor;\n\tvar cidx;\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 = predicate;\n\t\t} else {\n\t\t\thasOpts = true;\n\t\t\topts = options;\n\t\t\tclbk = predicate;\n\t\t}\n\t} else {\n\t\thasOpts = true;\n\t\topts = options;\n\t\tclbk = predicate;\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 predicate 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 elements according to a predicate function...\n\tcidx = -1;\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 = x.get.apply( x, idx );\n\t\tif ( clbk.call( ctx, v, idx.slice(), x ) ) {\n\t\t\tcache.length += 1;\n\t\t\tcidx += 1;\n\t\t\tcache[ cidx ] = v;\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 filter;\n"],"names":["filter","x","options","predicate","thisArg","hasOpts","ndims","cache","clbk","opts","ctor","cidx","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","get","apply","call","slice","gcopy","constructor"],"mappings":";;6zCA0EA,SAASA,EAAQC,EAAGC,EAASC,EAAWC,GACvC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEAC,EACAC,EACJ,IAAMC,EAAerB,GACpB,MAAM,IAAIsB,UAAWC,EAAQ,SAAUvB,IAmBxC,GAjBKwB,UAAUC,OAAS,EACvBlB,EAAON,EACyB,IAArBuB,UAAUC,OAChBC,EAAYzB,IAChBM,EAAON,EACPU,EAAMT,IAENE,GAAU,EACVI,EAAOP,EACPM,EAAOL,IAGRE,GAAU,EACVI,EAAOP,EACPM,EAAOL,EACPS,EAAMR,IAEDuB,EAAYnB,GACjB,MAAM,IAAIe,UAAWC,EAAQ,SAAUhB,IAExC,GAAKH,EAAU,CACd,IAAMuB,EAAenB,GACpB,MAAM,IAAIc,UAAWC,EAAQ,SAAUf,IAOxC,GAJCQ,EADIY,EAAYpB,EAAM,SACjBA,EAAKqB,MAELC,EAAU9B,GAEX4B,EAAYpB,EAAM,SAAY,CAClC,IAAMuB,EAASvB,EAAKwB,OACnB,MAAM,IAAIV,UAAWC,EAAQ,SAAU,QAASf,EAAKwB,QAEtDpB,EAAMJ,EAAKwB,KACX,CACH,MACEhB,EAAKc,EAAU9B,GAIhB,GAAc,QADdS,EAAOwB,EAAOjB,IAGb,MAAM,IAAIM,UAAWC,EAAQ,SAAU,QAASf,EAAKqB,QA+BtD,SA5Ba,IAARjB,IACJA,EAAMsB,EAAUlC,IAGjBiB,EAAKkB,EAAUnC,GAGfkB,EAAIkB,EAAOnB,GAGXZ,EAAQY,EAAGQ,OAIVZ,EADY,cAARD,EACEP,EAAQ,EAER,EAGPS,EAAMuB,EAAOhC,GAGbC,EAAQ,CACPmB,OAAU,GAIXf,GAAQ,EACFU,EAAI,EAAGA,EAAIF,EAAGE,IACdA,EAAI,IACRN,EAAMwB,EAAoBrB,EAAIL,EAAKE,EAAKD,EAAKC,IAE9CK,EAAInB,EAAEuC,IAAIC,MAAOxC,EAAGc,GACfP,EAAKkC,KAAM9B,EAAKQ,EAAGL,EAAI4B,QAAS1C,KACpCM,EAAMmB,QAAU,EAEhBnB,EADAI,GAAQ,GACQS,GAelB,OARAJ,EAAM,IAAIN,EAHVS,EAAIZ,EAAMmB,QAMVkB,EAAOzB,EAAGZ,EAAO,EAAGS,EAAK,GAGrB,IAAIf,EAAE4C,YAAa5B,EAAID,EAAK,CAAEG,GAAK,CAAE,GAAK,EAAGN,EAGlD"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 1f3c75d..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Codestin Search App - - - -
- - - - - From f8763f5fd908f738445e64336acb5bca2dfe65c9 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 14 Dec 2024 09:20:51 +0000 Subject: [PATCH 14/35] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 53 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 71 +- SECURITY.md | 5 - benchmark/benchmark.1d.js | 150 - benchmark/benchmark.2d.js | 161 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 51 - docs/types/test.ts | 195 - examples/index.js | 38 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 55 - lib/main.js | 199 - package.json | 84 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 892 ---- 44 files changed, 4881 insertions(+), 5320 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.1d.js delete mode 100644 benchmark/benchmark.2d.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 03a0613..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) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 48af73a..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) 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 443f7ec..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: '9 21 * * 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 + + ```
@@ -248,7 +239,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]. @@ -311,11 +302,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-filter/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 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 6958f29..0000000 --- a/benchmark/benchmark.1d.js +++ /dev/null @@ -1,150 +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 filter = require( './../lib' ); - - -// VARIABLES // - -var xtypes = [ 'generic' ]; -var ytypes = [ 'float64' ]; -var orders = [ 'row-major', 'column-major' ]; - - -// FUNCTIONS // - -/** -* Predicate function. -* -* @private -* @param {number} value - array element -* @param {NonNegativeIntegerArray} indices - element indices -* @param {ndarray} arr - input array -* @returns {boolean} result -*/ -function predicate( value ) { - return value > 0.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 = filter( x, opts, predicate ); - 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 c70a9f1..0000000 --- a/benchmark/benchmark.2d.js +++ /dev/null @@ -1,161 +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 filter = require( './../lib' ); - - -// VARIABLES // - -var xtypes = [ 'generic' ]; -var ytypes = [ 'float64' ]; -var orders = [ 'row-major', 'column-major' ]; - - -// FUNCTIONS // - -/** -* Predicate function. -* -* @private -* @param {number} value - array element -* @param {NonNegativeIntegerArray} indices - element indices -* @param {ndarray} arr - input array -* @returns {boolean} result -*/ -function predicate( value ) { - return value > 0.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 = filter( x, opts, predicate ); - 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 51e4f91..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" -%% click B href "https://github.com/stdlib-js/ndarray-filter/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-filter/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-filter/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-filter/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-filter/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/filter -[production-url]: https://github.com/stdlib-js/ndarray-filter/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-filter/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-filter/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-filter/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-filter/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-filter/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-filter/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 aafb9cb..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import filter from '../docs/types/index'; -export = filter; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 558b3a7..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var V=function(r,a){return function(){return a||r((a={exports:{}}).exports,a),a.exports}};var k=V(function(K,j){"use strict";var C=require("@stdlib/assert-is-plain-object"),O=require("@stdlib/assert-is-function"),F=require("@stdlib/assert-is-ndarray-like"),P=require("@stdlib/ndarray-base-assert-is-order"),T=require("@stdlib/assert-has-own-property"),D=require("@stdlib/ndarray-base-buffer-ctors"),I=require("@stdlib/array-base-zeros"),L=require("@stdlib/ndarray-shape"),E=require("@stdlib/ndarray-dtype"),N=require("@stdlib/ndarray-order"),S=require("@stdlib/ndarray-base-numel"),A=require("@stdlib/ndarray-base-next-cartesian-index").assign,B=require("@stdlib/blas-base-gcopy"),v=require("@stdlib/string-format");function G(r,a,g,z){var c,f,o,i,e,p,m,h,t,y,n,q,s,l,u,b,w,d;if(!F(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?O(a)?(i=a,h=g):(c=!0,e=a,i=g):(c=!0,e=a,i=g,h=z),!O(i))throw new TypeError(v("invalid argument. Callback argument must be a function. Value: `%s`.",i));if(c){if(!C(e))throw new TypeError(v("invalid argument. Options argument must be an object. Value: `%s`.",e));if(T(e,"dtype")?s=e.dtype:s=E(r),T(e,"order")){if(!P(e.order))throw new TypeError(v("invalid option. `%s` option must be a recognized order. Option: `%s`.","order",e.order));t=e.order}}else s=E(r);if(p=D(s),p===null)throw new TypeError(v("invalid option. `%s` option must be a recognized data type. Option: `%s`.","dtype",e.dtype));for(t===void 0&&(t=N(r)),l=L(r),u=S(l),f=l.length,t==="row-major"?y=f-1:y=0,n=I(f),o={length:0},m=-1,d=0;d0&&(n=A(l,t,n,y,n)),w=r.get.apply(r,n),i.call(h,w,n.slice(),r)&&(o.length+=1,m+=1,o[m]=w);return u=o.length,q=new p(u),B(u,o,1,q,1),b=new r.constructor(s,q,[u],[1],0,t),b}j.exports=G});var H=k();module.exports=H; -/** -* @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 d4c9544..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* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate 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 {boolean} [options.order] - index iteration order\n* @param {Callback} predicate - predicate function\n* @param {*} [thisArg] - predicate 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 isEven = require( '@stdlib/assert-is-even' ).isPrimitive;\n* var Float64Array = require( '@stdlib/array-float64' );\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\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 = filter( x, isEven );\n* // returns \n*\n* var arr = ndarray2array( y );\n* // returns [ 2.0, 4.0, 8.0, 10.0 ]\n*/\nfunction filter( x, options, predicate, thisArg ) {\n\tvar hasOpts;\n\tvar ndims;\n\tvar cache;\n\tvar clbk;\n\tvar opts;\n\tvar ctor;\n\tvar cidx;\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 = predicate;\n\t\t} else {\n\t\t\thasOpts = true;\n\t\t\topts = options;\n\t\t\tclbk = predicate;\n\t\t}\n\t} else {\n\t\thasOpts = true;\n\t\topts = options;\n\t\tclbk = predicate;\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 predicate 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 elements according to a predicate function...\n\tcidx = -1;\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 = x.get.apply( x, idx );\n\t\tif ( clbk.call( ctx, v, idx.slice(), x ) ) {\n\t\t\tcache.length += 1;\n\t\t\tcidx += 1;\n\t\t\tcache[ cidx ] = v;\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 = filter;\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* Return a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function.\n*\n* @module @stdlib/ndarray-filter\n*\n* @example\n* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive;\n* var Float64Array = require( '@stdlib/array-float64' );\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var filter = require( '@stdlib/ndarray-filter' );\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 = filter( x, isEven );\n* // returns \n*\n* var arr = ndarray2array( y );\n* // returns [ 2.0, 4.0, 8.0, 10.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,EAuC9C,SAASC,EAAQC,EAAGC,EAASC,EAAWC,EAAU,CACjD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,GAAK,CAAClC,EAAea,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,gFAAiFE,CAAE,CAAE,EAmBnH,GAjBK,UAAU,OAAS,EACvBO,EAAON,EACI,UAAU,SAAW,EAC3Bf,EAAYe,CAAQ,GACxBM,EAAON,EACPU,EAAMT,IAENE,EAAU,GACVI,EAAOP,EACPM,EAAOL,IAGRE,EAAU,GACVI,EAAOP,EACPM,EAAOL,EACPS,EAAMR,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,EAC9BQ,EAAKR,EAAK,MAEVQ,EAAKvB,EAAUO,CAAE,EAEbX,EAAYmB,EAAM,OAAQ,EAAI,CAClC,GAAK,CAACpB,EAASoB,EAAK,KAAM,EACzB,MAAM,IAAI,UAAWV,EAAQ,wEAAyE,QAASU,EAAK,KAAM,CAAE,EAE7HI,EAAMJ,EAAK,KACZ,CACD,MACCQ,EAAKvB,EAAUO,CAAE,EAIlB,GADAS,EAAOnB,EAAO0B,CAAG,EACZP,IAAS,KAEb,MAAM,IAAI,UAAWX,EAAQ,4EAA6E,QAASU,EAAK,KAAM,CAAE,EA+BjI,IA5BKI,IAAQ,SACZA,EAAMlB,EAAUM,CAAE,GAGnBiB,EAAKzB,EAAUQ,CAAE,EAGjBkB,EAAIvB,EAAOsB,CAAG,EAGdZ,EAAQY,EAAG,OAGNL,IAAQ,YACZC,EAAMR,EAAQ,EAEdQ,EAAM,EAGPC,EAAMvB,EAAOc,CAAM,EAGnBC,EAAQ,CACP,OAAU,CACX,EAGAI,EAAO,GACDW,EAAI,EAAGA,EAAIH,EAAGG,IACdA,EAAI,IACRP,EAAMlB,EAAoBqB,EAAIL,EAAKE,EAAKD,EAAKC,CAAI,GAElDM,EAAIpB,EAAE,IAAI,MAAOA,EAAGc,CAAI,EACnBP,EAAK,KAAMI,EAAKS,EAAGN,EAAI,MAAM,EAAGd,CAAE,IACtCM,EAAM,QAAU,EAChBI,GAAQ,EACRJ,EAAOI,CAAK,EAAIU,GAIlB,OAAAF,EAAIZ,EAAM,OAGVS,EAAM,IAAIN,EAAMS,CAAE,EAGlBrB,EAAOqB,EAAGZ,EAAO,EAAGS,EAAK,CAAE,EAG3BI,EAAI,IAAInB,EAAE,YAAagB,EAAID,EAAK,CAAEG,CAAE,EAAG,CAAE,CAAE,EAAG,EAAGN,CAAI,EAE9CO,CACR,CAKAnC,EAAO,QAAUe,ICrJjB,IAAIuB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isPlainObject", "isFunction", "isndarrayLike", "isOrder", "hasOwnProp", "ctors", "zeros", "getShape", "getDType", "getOrder", "numel", "nextCartesianIndex", "gcopy", "format", "filter", "x", "options", "predicate", "thisArg", "hasOpts", "ndims", "cache", "clbk", "opts", "ctor", "cidx", "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 8ed7071..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,51 +0,0 @@ - -{{alias}}( x[, options], predicate[, thisArg] ) - Returns a shallow copy of an ndarray containing only those elements which - pass a test implemented by a predicate function. - - The predicate function is provided the following arguments: - - - value: current array element. - - indices: current array element indices. - - arr: the input 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 manor, 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'. - - predicate: Function - Predicate function. - - thisArg: any (optional) - Predicate function execution context. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ); - > function f( v ) { return v > 2.0; }; - > var y = {{alias}}( x, f ); - > {{alias:@stdlib/ndarray/to-array}}( y ) - [ 3.0, 4.0 ] - - See Also - -------- diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 046dffb..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,195 +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 empty = require( '@stdlib/ndarray-base-empty' ); -import zeros = require( '@stdlib/ndarray-base-zeros' ); -import filter = require( './index' ); - -/** -* Predicate function. -* -* @param x - input value -* @returns result -*/ -function predicate( x: any ): boolean { - return Boolean( x ); -} - -// The function returns an ndarray... -{ - const sh = [ 2, 2 ]; - const ord = 'row-major'; - - filter( zeros( 'float64', sh, ord ), predicate ); // $ExpectType float64ndarray - filter( zeros( 'float64', sh, ord ), predicate, {} ); // $ExpectType float64ndarray - filter( zeros( 'float32', sh, ord ), predicate ); // $ExpectType float32ndarray - filter( zeros( 'float32', sh, ord ), predicate, {} ); // $ExpectType float32ndarray - filter( zeros( 'complex64', sh, ord ), predicate ); // $ExpectType complex64ndarray - filter( zeros( 'complex64', sh, ord ), predicate, {} ); // $ExpectType complex64ndarray - filter( zeros( 'complex128', sh, ord ), predicate ); // $ExpectType complex128ndarray - filter( zeros( 'complex128', sh, ord ), predicate, {} ); // $ExpectType complex128ndarray - filter( zeros( 'int32', sh, ord ), predicate ); // $ExpectType int32ndarray - filter( zeros( 'int32', sh, ord ), predicate, {} ); // $ExpectType int32ndarray - filter( zeros( 'int16', sh, ord ), predicate ); // $ExpectType int16ndarray - filter( zeros( 'int16', sh, ord ), predicate, {} ); // $ExpectType int16ndarray - filter( zeros( 'int8', sh, ord ), predicate ); // $ExpectType int8ndarray - filter( zeros( 'int8', sh, ord ), predicate, {} ); // $ExpectType int8ndarray - filter( zeros( 'uint32', sh, ord ), predicate ); // $ExpectType uint32ndarray - filter( zeros( 'uint32', sh, ord ), predicate, {} ); // $ExpectType uint32ndarray - filter( zeros( 'uint16', sh, ord ), predicate ); // $ExpectType uint16ndarray - filter( zeros( 'uint16', sh, ord ), predicate, {} ); // $ExpectType uint16ndarray - filter( zeros( 'uint8', sh, ord ), predicate ); // $ExpectType uint8ndarray - filter( zeros( 'uint8', sh, ord ), predicate, {} ); // $ExpectType uint8ndarray - filter( zeros( 'uint8c', sh, ord ), predicate ); // $ExpectType uint8cndarray - filter( zeros( 'uint8c', sh, ord ), predicate, {} ); // $ExpectType uint8cndarray - filter( empty( 'bool', sh, ord ), predicate ); // $ExpectType boolndarray - filter( empty( 'bool', sh, ord ), predicate, {} ); // $ExpectType boolndarray - filter( zeros( 'generic', sh, ord ), predicate ); // $ExpectType genericndarray - filter( zeros( 'generic', sh, ord ), predicate, {} ); // $ExpectType genericndarray - - - filter( zeros( 'generic', sh, ord ), { 'dtype': 'float64' }, predicate ); // $ExpectType float64ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'float64' }, predicate, {} ); // $ExpectType float64ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'float32' }, predicate ); // $ExpectType float32ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'float32' }, predicate, {} ); // $ExpectType float32ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'complex64' }, predicate ); // $ExpectType complex64ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'complex64' }, predicate, {} ); // $ExpectType complex64ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'complex128' }, predicate ); // $ExpectType complex128ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'complex128' }, predicate, {} ); // $ExpectType complex128ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'int32' }, predicate ); // $ExpectType int32ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'int32' }, predicate, {} ); // $ExpectType int32ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'int16' }, predicate ); // $ExpectType int16ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'int16' }, predicate, {} ); // $ExpectType int16ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'int8' }, predicate ); // $ExpectType int8ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'int8' }, predicate, {} ); // $ExpectType int8ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint32' }, predicate ); // $ExpectType uint32ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint32' }, predicate, {} ); // $ExpectType uint32ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint16' }, predicate ); // $ExpectType uint16ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint16' }, predicate, {} ); // $ExpectType uint16ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint8' }, predicate ); // $ExpectType uint8ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint8' }, predicate, {} ); // $ExpectType uint8ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint8c' }, predicate ); // $ExpectType uint8cndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint8c' }, predicate, {} ); // $ExpectType uint8cndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'bool' }, predicate ); // $ExpectType boolndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'bool' }, predicate, {} ); // $ExpectType boolndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'generic' }, predicate ); // $ExpectType genericndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'generic' }, predicate, {} ); // $ExpectType genericndarray - - - filter( zeros( 'float64', sh, ord ), { 'order': ord }, predicate ); // $ExpectType float64ndarray - filter( zeros( 'float64', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType float64ndarray - filter( zeros( 'float32', sh, ord ), { 'order': ord }, predicate ); // $ExpectType float32ndarray - filter( zeros( 'float32', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType float32ndarray - filter( zeros( 'complex64', sh, ord ), { 'order': ord }, predicate ); // $ExpectType complex64ndarray - filter( zeros( 'complex64', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType complex64ndarray - filter( zeros( 'complex128', sh, ord ), { 'order': ord }, predicate ); // $ExpectType complex128ndarray - filter( zeros( 'complex128', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType complex128ndarray - filter( zeros( 'int32', sh, ord ), { 'order': ord }, predicate ); // $ExpectType int32ndarray - filter( zeros( 'int32', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType int32ndarray - filter( zeros( 'int16', sh, ord ), { 'order': ord }, predicate ); // $ExpectType int16ndarray - filter( zeros( 'int16', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType int16ndarray - filter( zeros( 'int8', sh, ord ), { 'order': ord }, predicate ); // $ExpectType int8ndarray - filter( zeros( 'int8', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType int8ndarray - filter( zeros( 'uint32', sh, ord ), { 'order': ord }, predicate ); // $ExpectType uint32ndarray - filter( zeros( 'uint32', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType uint32ndarray - filter( zeros( 'uint16', sh, ord ), { 'order': ord }, predicate ); // $ExpectType uint16ndarray - filter( zeros( 'uint16', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType uint16ndarray - filter( zeros( 'uint8', sh, ord ), { 'order': ord }, predicate ); // $ExpectType uint8ndarray - filter( zeros( 'uint8', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType uint8ndarray - filter( zeros( 'uint8c', sh, ord ), { 'order': ord }, predicate ); // $ExpectType uint8cndarray - filter( zeros( 'uint8c', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType uint8cndarray - filter( empty( 'bool', sh, ord ), { 'order': ord }, predicate ); // $ExpectType boolndarray - filter( empty( 'bool', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType boolndarray - filter( zeros( 'generic', sh, ord ), { 'order': ord }, predicate ); // $ExpectType genericndarray - filter( zeros( 'generic', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType genericndarray - -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - filter( 5, predicate ); // $ExpectError - filter( true, predicate ); // $ExpectError - filter( false, predicate ); // $ExpectError - filter( null, predicate ); // $ExpectError - filter( undefined, predicate ); // $ExpectError - filter( {}, predicate ); // $ExpectError - filter( [ 1 ], predicate ); // $ExpectError - filter( ( x: number ): number => x, predicate ); // $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' ); - - filter( x, '5' ); // $ExpectError - filter( x, true ); // $ExpectError - filter( x, false ); // $ExpectError - filter( x, null ); // $ExpectError - filter( x, undefined ); // $ExpectError - filter( x, {} ); // $ExpectError - filter( 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' ); - - filter( x, '10', predicate, {} ); // $ExpectError - filter( x, 10, predicate, {} ); // $ExpectError - filter( x, false, predicate, {} ); // $ExpectError - filter( x, true, predicate, {} ); // $ExpectError - filter( x, [], predicate, {} ); // $ExpectError - filter( x, ( x: number ): number => x, predicate, {} ); // $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' ); - - filter( x, { 'dtype': '10' }, predicate ); // $ExpectError - filter( x, { 'dtype': 10 }, predicate ); // $ExpectError - filter( x, { 'dtype': null }, predicate ); // $ExpectError - filter( x, { 'dtype': false }, predicate ); // $ExpectError - filter( x, { 'dtype': true }, predicate ); // $ExpectError - filter( x, { 'dtype': [] }, predicate ); // $ExpectError - filter( x, { 'dtype': {} }, predicate ); // $ExpectError - filter( x, { 'dtype': ( x: number ): number => x }, predicate ); // $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' ); - - filter( x, { 'order': '10' }, predicate ); // $ExpectError - filter( x, { 'order': 10 }, predicate ); // $ExpectError - filter( x, { 'order': null }, predicate ); // $ExpectError - filter( x, { 'order': false }, predicate ); // $ExpectError - filter( x, { 'order': true }, predicate ); // $ExpectError - filter( x, { 'order': [] }, predicate ); // $ExpectError - filter( x, { 'order': {} }, predicate ); // $ExpectError - filter( x, { 'order': ( x: number ): number => x }, predicate ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - filter(); // $ExpectError - filter( zeros( 'float64', [ 2, 2 ], 'row-major' ) ); // $ExpectError - filter( 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 e2dd6cb..0000000 --- a/examples/index.js +++ /dev/null @@ -1,38 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var array = require( '@stdlib/ndarray-array' ); -var isPositive = require( '@stdlib/assert-is-positive-number' ).isPrimitive; -var filter = require( './../lib' ); - -var buffer = discreteUniform( 10, -100, 100, { - 'dtype': 'generic' -}); -var x = array( buffer, { - 'shape': [ 5, 2 ], - 'dtype': 'generic' -}); -console.log( ndarray2array( x ) ); - -var y = filter( x, naryFunction( isPositive, 1 ) ); -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 a39a064..e2a9d07 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..f1c84f4 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import e 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 a from"https://cdn.jsdelivr.net/gh/stdlib-js/blas-base-gcopy@v0.2.1-esm/index.mjs";import h 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,G;if(!e(v))throw new TypeError(h("null5t",v));if(arguments.length<3?w=f:3===arguments.length?s(f)?(w=f,k=b):(g=!0,u=f,w=b):(g=!0,u=f,w=b,k=c),!s(w))throw new TypeError(h("null2b",w));if(g){if(!r(u))throw new TypeError(h("null2V",u));if(q=n(u,"dtype")?u.dtype:m(v),n(u,"order")){if(!t(u.order))throw new TypeError(h("null5C","order",u.order));z=u.order}}else q=m(v);if(null===(E=d(q)))throw new TypeError(h("nullBf","dtype",u.dtype));for(void 0===z&&(z=l(v)),A=o(v),D=p(A),y=A.length,B="row-major"===z?y-1:0,C=i(y),x={length:0},T=-1,G=0;G0&&(C=j(A,z,C,B,C)),F=v.get.apply(v,C),w.call(k,F,C.slice(),v)&&(x.length+=1,x[T+=1]=F);return V=new E(D=x.length),a(D,x,1,V,1),new v.constructor(q,V,[D],[1],0,z)}export{v as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..b080961 --- /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* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate 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 {boolean} [options.order] - index iteration order\n* @param {Callback} predicate - predicate function\n* @param {*} [thisArg] - predicate 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 { isPrimitive as isEven } from '@stdlib/assert-is-even';\n* import Float64Array from '@stdlib/array-float64';\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndarray2array from '@stdlib/ndarray-to-array';\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 = filter( x, isEven );\n* // returns \n*\n* var arr = ndarray2array( y );\n* // returns [ 2.0, 4.0, 8.0, 10.0 ]\n*/\nfunction filter( x, options, predicate, thisArg ) {\n\tvar hasOpts;\n\tvar ndims;\n\tvar cache;\n\tvar clbk;\n\tvar opts;\n\tvar ctor;\n\tvar cidx;\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 = predicate;\n\t\t} else {\n\t\t\thasOpts = true;\n\t\t\topts = options;\n\t\t\tclbk = predicate;\n\t\t}\n\t} else {\n\t\thasOpts = true;\n\t\topts = options;\n\t\tclbk = predicate;\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 predicate 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 elements according to a predicate function...\n\tcidx = -1;\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 = x.get.apply( x, idx );\n\t\tif ( clbk.call( ctx, v, idx.slice(), x ) ) {\n\t\t\tcache.length += 1;\n\t\t\tcidx += 1;\n\t\t\tcache[ cidx ] = v;\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 filter;\n"],"names":["filter","x","options","predicate","thisArg","hasOpts","ndims","cache","clbk","opts","ctor","cidx","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","get","apply","call","slice","gcopy","constructor"],"mappings":";;6zCA0EA,SAASA,EAAQC,EAAGC,EAASC,EAAWC,GACvC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEAC,EACAC,EACJ,IAAMC,EAAerB,GACpB,MAAM,IAAIsB,UAAWC,EAAQ,SAAUvB,IAmBxC,GAjBKwB,UAAUC,OAAS,EACvBlB,EAAON,EACyB,IAArBuB,UAAUC,OAChBC,EAAYzB,IAChBM,EAAON,EACPU,EAAMT,IAENE,GAAU,EACVI,EAAOP,EACPM,EAAOL,IAGRE,GAAU,EACVI,EAAOP,EACPM,EAAOL,EACPS,EAAMR,IAEDuB,EAAYnB,GACjB,MAAM,IAAIe,UAAWC,EAAQ,SAAUhB,IAExC,GAAKH,EAAU,CACd,IAAMuB,EAAenB,GACpB,MAAM,IAAIc,UAAWC,EAAQ,SAAUf,IAOxC,GAJCQ,EADIY,EAAYpB,EAAM,SACjBA,EAAKqB,MAELC,EAAU9B,GAEX4B,EAAYpB,EAAM,SAAY,CAClC,IAAMuB,EAASvB,EAAKwB,OACnB,MAAM,IAAIV,UAAWC,EAAQ,SAAU,QAASf,EAAKwB,QAEtDpB,EAAMJ,EAAKwB,KACX,CACH,MACEhB,EAAKc,EAAU9B,GAIhB,GAAc,QADdS,EAAOwB,EAAOjB,IAGb,MAAM,IAAIM,UAAWC,EAAQ,SAAU,QAASf,EAAKqB,QA+BtD,SA5Ba,IAARjB,IACJA,EAAMsB,EAAUlC,IAGjBiB,EAAKkB,EAAUnC,GAGfkB,EAAIkB,EAAOnB,GAGXZ,EAAQY,EAAGQ,OAIVZ,EADY,cAARD,EACEP,EAAQ,EAER,EAGPS,EAAMuB,EAAOhC,GAGbC,EAAQ,CACPmB,OAAU,GAIXf,GAAQ,EACFU,EAAI,EAAGA,EAAIF,EAAGE,IACdA,EAAI,IACRN,EAAMwB,EAAoBrB,EAAIL,EAAKE,EAAKD,EAAKC,IAE9CK,EAAInB,EAAEuC,IAAIC,MAAOxC,EAAGc,GACfP,EAAKkC,KAAM9B,EAAKQ,EAAGL,EAAI4B,QAAS1C,KACpCM,EAAMmB,QAAU,EAEhBnB,EADAI,GAAQ,GACQS,GAelB,OARAJ,EAAM,IAAIN,EAHVS,EAAIZ,EAAMmB,QAMVkB,EAAOzB,EAAGZ,EAAO,EAAGS,EAAK,GAGrB,IAAIf,EAAE4C,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 46f5998..0000000 --- a/lib/index.js +++ /dev/null @@ -1,55 +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'; - -/** -* Return a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @module @stdlib/ndarray-filter -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var filter = require( '@stdlib/ndarray-filter' ); -* -* 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 = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.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 f101a98..0000000 --- a/lib/main.js +++ /dev/null @@ -1,199 +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/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param {ndarray} x - input ndarray -* @param {Options} [options] - function options -* @param {string} [options.dtype] - output array data type -* @param {boolean} [options.order] - index iteration order -* @param {Callback} predicate - predicate function -* @param {*} [thisArg] - predicate 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 isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -function filter( x, options, predicate, thisArg ) { - var hasOpts; - var ndims; - var cache; - var clbk; - var opts; - var ctor; - var cidx; - 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( 'null5t', x ) ); - } - if ( arguments.length < 3 ) { - clbk = options; - } else if ( arguments.length === 3 ) { - if ( isFunction( options ) ) { - clbk = options; - ctx = predicate; - } else { - hasOpts = true; - opts = options; - clbk = predicate; - } - } else { - hasOpts = true; - opts = options; - clbk = predicate; - ctx = thisArg; - } - if ( !isFunction( clbk ) ) { - throw new TypeError( format( 'null2b', clbk ) ); - } - if ( hasOpts ) { - if ( !isPlainObject( opts ) ) { - throw new TypeError( format( 'null2V', opts ) ); - } - if ( hasOwnProp( opts, 'dtype' ) ) { - dt = opts.dtype; - } else { - dt = getDType( x ); - } - if ( hasOwnProp( opts, 'order' ) ) { - if ( !isOrder( opts.order ) ) { - throw new TypeError( format( 'null5C', '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( 'nullBf', '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 predicate 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 elements according to a predicate function... - cidx = -1; - for ( i = 0; i < N; i++ ) { - if ( i > 0 ) { - idx = nextCartesianIndex( sh, ord, idx, dim, idx ); - } - v = x.get.apply( x, idx ); - if ( clbk.call( ctx, v, idx.slice(), x ) ) { - cache.length += 1; - cidx += 1; - cache[ cidx ] = v; - } - } - // 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 = filter; diff --git a/package.json b/package.json index a44b313..2473eda 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Return a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate 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,62 +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/error-tools-fmtprodmsg": "^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-positive-number": "^0.2.2", - "@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", - "@stdlib/utils-nary-function": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "strided", @@ -104,7 +25,6 @@ "select", "take" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..1f3c75d --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Codestin Search App + + + +
+ + + + + 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 3bea6b3..0000000 --- a/test/test.js +++ /dev/null @@ -1,892 +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 filter = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof filter, '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() { - filter( value, predicate ); - }; - } - - function predicate( z ) { - return ( z > 0.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() { - filter( 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() { - filter( 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() { - filter( x, value, predicate ); - }; - } - - function predicate( z ) { - return ( z > 0.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 - }; - filter( x, opts, predicate ); - }; - } - - function predicate( z ) { - return ( z > 0.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 - }; - filter( x, opts, predicate ); - }; - } - - function predicate( z ) { - return ( z > 0.0 ); - } -}); - -tape( 'the function filters an array according to a predicate 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 = filter( x, predicate ); - - expected = new Float64Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - - t.end(); - - function predicate( z ) { - return ( z > 0.0 ); - } -}); - -tape( 'the function filters an array according to a predicate 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 = filter( x, predicate ); - - expected = new Float64Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - - t.end(); - - function predicate( z ) { - return ( z > 0.0 ); - } -}); - -tape( 'the function filters an array according to a predicate 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 = filter( x, opts, predicate ); - - expected = new Float64Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - - opts = { - 'dtype': 'float32' - }; - y = filter( x, opts, predicate ); - - expected = new Float32Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat32Array( y.data, expected ), true, 'returns expected value' ); - - t.end(); - - function predicate( z ) { - return ( z > 0.0 ); - } -}); - -tape( 'the function filters an array according to a predicate 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 = filter( x, opts, predicate ); - - expected = new Float64Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - - opts = { - 'dtype': 'float32' - }; - y = filter( x, opts, predicate ); - - expected = new Float32Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat32Array( y.data, expected ), true, 'returns expected value' ); - - t.end(); - - function predicate( z ) { - return ( z > 0.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 = filter( x, predicate, ctx ); - - expected = new Float64Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function predicate( z ) { - this.count += 1; // eslint-disable-line no-invalid-this - return ( z > 0.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 = filter( x, {}, predicate, ctx ); - - expected = new Float64Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function predicate( z ) { - this.count += 1; // eslint-disable-line no-invalid-this - return ( z > 0.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 = filter( x, predicate ); - - expected = new Float64Array([ - 1.0, - 3.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 predicate( z, idx, arr ) { - values.push( z ); - indices.push( idx ); - arrays.push( arr ); - return ( z > 0.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 = filter( x, predicate ); - - expected = new Float64Array([ - 1.0, - 3.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 predicate( z, idx, arr ) { - values.push( z ); - indices.push( idx ); - arrays.push( arr ); - return ( z > 0.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 = filter( x, opts, predicate ); - - expected = new Float64Array([ - 1.0, - 3.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 predicate( z, idx, arr ) { - values.push( z ); - indices.push( idx ); - arrays.push( arr ); - return ( z > 0.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 = filter( x, opts, predicate ); - - expected = new Float64Array([ - 1.0, - 3.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 predicate( z, idx, arr ) { - values.push( z ); - indices.push( idx ); - arrays.push( arr ); - return ( z > 0.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 = filter( x, opts, predicate ); - - expected = new Float64Array([ - 1.0, - 3.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 predicate( z, idx, arr ) { - values.push( z ); - indices.push( idx ); - arrays.push( arr ); - return ( z > 0.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 = filter( x, opts, predicate ); - - expected = new Float64Array([ - 1.0, - 3.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 predicate( z, idx, arr ) { - values.push( z ); - indices.push( idx ); - arrays.push( arr ); - return ( z > 0.0 ); - } -}); From 838720591078455d43c05b448822dede21821b8a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 14 Dec 2024 23:26:19 +0000 Subject: [PATCH 15/35] Transform error messages --- lib/main.js | 12 ++++++------ package.json | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/main.js b/lib/main.js index 6ad824e..3cd50e0 100644 --- a/lib/main.js +++ b/lib/main.js @@ -33,7 +33,7 @@ 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' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -91,7 +91,7 @@ function filter( x, options, predicate, thisArg ) { var v; var i; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray-like object. Value: `%s`.', x ) ); + throw new TypeError( format( 'null5t', x ) ); } if ( arguments.length < 3 ) { clbk = options; @@ -111,11 +111,11 @@ function filter( x, options, predicate, thisArg ) { ctx = thisArg; } if ( !isFunction( clbk ) ) { - throw new TypeError( format( 'invalid argument. Callback argument must be a function. Value: `%s`.', clbk ) ); + throw new TypeError( format( 'null2b', clbk ) ); } if ( hasOpts ) { if ( !isPlainObject( opts ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) ); + throw new TypeError( format( 'null2V', opts ) ); } if ( hasOwnProp( opts, 'dtype' ) ) { dt = opts.dtype; @@ -124,7 +124,7 @@ function filter( x, options, predicate, thisArg ) { } 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 ) ); + throw new TypeError( format( 'null5C', 'order', opts.order ) ); } ord = opts.order; } @@ -135,7 +135,7 @@ function filter( x, options, predicate, thisArg ) { 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 ) ); + throw new TypeError( format( 'nullBf', 'dtype', opts.dtype ) ); } // Resolve the iteration order: if ( ord === void 0 ) { diff --git a/package.json b/package.json index 22065aa..a44b313 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@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/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From 6504d4911904a6094b55da85e9f2c48a46fedc4e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 14 Dec 2024 23:31:15 +0000 Subject: [PATCH 16/35] Remove files --- index.d.ts | 1612 ---------------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 6459 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index e2a9d07..0000000 --- a/index.d.ts +++ /dev/null @@ -1,1612 +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. -*/ - -// TypeScript Version: 4.1 - -/// - -/* eslint-disable max-lines */ - -import { typedndarray, DataType, Order, float64ndarray, float32ndarray, complex128ndarray, complex64ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, boolndarray, genericndarray } from '@stdlib/types/ndarray'; -import { Complex64, Complex128 } from '@stdlib/types/complex'; - -/** -* Returns a boolean indicating whether an element passes a test. -* -* @returns boolean indicating whether an element passes a test -*/ -type Nullary = ( this: V ) => boolean; - -/** -* Returns a boolean indicating whether an element passes a test. -* -* @param value - current array element -* @returns boolean indicating whether an element passes a test -*/ -type Unary = ( this: V, value: T ) => boolean; - -/** -* Returns a boolean indicating whether an element passes a test. -* -* @param value - current array element -* @param indices - current array element indices -* @returns boolean indicating whether an element passes a test -*/ -type Binary = ( this: V, value: T, indices: Array ) => boolean; - -/** -* Returns a boolean indicating whether an element passes a test. -* -* @param value - current array element -* @param indices - current array element indices -* @param arr - input array -* @returns boolean indicating whether an element passes a test -*/ -type Ternary = ( this: V, value: T, indices: Array, arr: typedndarray ) => boolean; - -/** -* Returns a boolean indicating whether an element passes a test. -* -* @param value - current array element -* @param indices - current array element indices -* @param arr - input array -* @returns boolean indicating whether an element passes a test -*/ -type Predicate = Nullary | Unary | Binary | Ternary; - -/** -* Interface describing "base" function options. -*/ -interface BaseOptions { - /** - * Index iteration order. - * - * ## Notes - * - * - By default, the function iterates over elements according to the layout order of the provided ndarray. Accordingly, for row-major input ndarrays, the last dimension indices increment fastest. For column-major input ndarrays, the first dimension indices increment fastest. To override the inferred order and ensure that indices increment in a specific manor, regardless of the input ndarray's layout order, explicitly set the iteration order. Note, however, that iterating according to an order which does not match that of the input ndarray may, in some circumstances, result in performance degradation due to cache misses. - */ - order?: Order; -} - -/** -* Interface describing function options. -*/ -interface OrderOptions { - /** - * Index iteration order. - * - * ## Notes - * - * - By default, the function iterates over elements according to the layout order of the provided ndarray. Accordingly, for row-major input ndarrays, the last dimension indices increment fastest. For column-major input ndarrays, the first dimension indices increment fastest. To override the inferred order and ensure that indices increment in a specific manor, regardless of the input ndarray's layout order, explicitly set the iteration order. Note, however, that iterating according to an order which does not match that of the input ndarray may, in some circumstances, result in performance degradation due to cache misses. - */ - order: Order; -} - -/** -* Interface describing function options. -*/ -interface Options extends BaseOptions { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: DataType; -} - -/** -* Interface describing function options. -*/ -interface Float64Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'float64'; -} - -/** -* Interface describing function options. -*/ -interface Float32Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'float32'; -} - -/** -* Interface describing function options. -*/ -interface Complex128Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'complex128'; -} - -/** -* Interface describing function options. -*/ -interface Complex64Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'complex64'; -} - -/** -* Interface describing function options. -*/ -interface Int32Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'int32'; -} - -/** -* Interface describing function options. -*/ -interface Int16Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'int16'; -} - -/** -* Interface describing function options. -*/ -interface Int8Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'int8'; -} - -/** -* Interface describing function options. -*/ -interface Uint32Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'uint32'; -} - -/** -* Interface describing function options. -*/ -interface Uint16Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'uint16'; -} - -/** -* Interface describing function options. -*/ -interface Uint8Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'uint8'; -} - -/** -* Interface describing function options. -*/ -interface Uint8COptions extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'uint8c'; -} - -/** -* Interface describing function options. -*/ -interface BoolOptions extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'bool'; -} - -/** -* Interface describing function options. -*/ -interface GenericOptions extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'generic'; -} - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: float64ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): float64ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float32Array = require( '@stdlib/array-float32' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Float32Array( [ 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( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: float32ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): float32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var Complex64Array = require( '@stdlib/array-complex64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* function predicate( z, idx ) { -* return idx[ 0 ] > 0; -* } -* -* var buffer = new Complex64Array( [ 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 = [ 3, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, predicate ); -* // returns -*/ -declare function filter( x: complex64ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): complex64ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* function predicate( z, idx ) { -* return idx[ 0 ] > 0; -* } -* -* var buffer = new Complex128Array( [ 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 = [ 3, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, predicate ); -* // returns -*/ -declare function filter( x: complex128ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): complex128ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Int32Array = require( '@stdlib/array-int32' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Int32Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: int32ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): int32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Int16Array = require( '@stdlib/array-int16' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Int16Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: int16ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): int16ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Int8Array = require( '@stdlib/array-int8' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Int8Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: int8ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): int8ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint32Array = require( '@stdlib/array-uint32' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint32Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint32ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): uint32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint16Array = require( '@stdlib/array-uint16' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint16Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint16ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): uint16ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint8Array = require( '@stdlib/array-uint8' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint8Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint8ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): uint8ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint8ClampedArray( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint8cndarray, predicate: Predicate, thisArg?: ThisParameterType> ): uint8cndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var BooleanArray = require( '@stdlib/array-bool' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* function predicate( z ) { -* return z; -* } -* -* var buffer = new BooleanArray( [ false, true, false, true, false, true, false, true, false, true, false, true ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'bool', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, predicate ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ true, true, true, true ] -*/ -declare function filter( x: boolndarray, predicate: Predicate, thisArg?: ThisParameterType> ): boolndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 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( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: genericndarray, predicate: Predicate, thisArg?: ThisParameterType> ): genericndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: float64ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): float64ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float32Array = require( '@stdlib/array-float32' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Float32Array( [ 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( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: float32ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): float32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var Complex64Array = require( '@stdlib/array-complex64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* function predicate( z, idx ) { -* return idx[ 0 ] > 0; -* } -* -* var buffer = new Complex64Array( [ 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 = [ 3, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, predicate ); -* // returns -*/ -declare function filter( x: complex64ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): complex64ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* function predicate( z, idx ) { -* return idx[ 0 ] > 0; -* } -* -* var buffer = new Complex128Array( [ 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 = [ 3, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, predicate ); -* // returns -*/ -declare function filter( x: complex128ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): complex128ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Int32Array = require( '@stdlib/array-int32' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Int32Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: int32ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): int32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Int16Array = require( '@stdlib/array-int16' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Int16Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: int16ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): int16ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Int8Array = require( '@stdlib/array-int8' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Int8Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: int8ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): int8ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint32Array = require( '@stdlib/array-uint32' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint32Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint32ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): uint32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint16Array = require( '@stdlib/array-uint16' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint16Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint16ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): uint16ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint8Array = require( '@stdlib/array-uint8' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint8Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint8ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): uint8ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint8ClampedArray( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint8cndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): uint8cndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var BooleanArray = require( '@stdlib/array-bool' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* function predicate( z ) { -* return z; -* } -* -* var buffer = new BooleanArray( [ false, true, false, true, false, true, false, true, false, true, false, true ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'bool', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, predicate ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ true, true, true, true ] -*/ -declare function filter( x: boolndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): boolndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 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( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: genericndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): genericndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'float64' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: typedndarray, options: Float64Options, predicate: Predicate, thisArg?: ThisParameterType> ): float64ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'float32' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: typedndarray, options: Float32Options, predicate: Predicate, thisArg?: ThisParameterType> ): float32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* function predicate( z, idx ) { -* return idx[ 0 ] > 0; -* } -* -* var buffer = new Complex128Array( [ 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 = [ 3, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'dtype': 'complex128' -* }; -* var y = filter( x, opts, predicate ); -* // returns -*/ -declare function filter( x: typedndarray, options: Complex128Options, predicate: Predicate, thisArg?: ThisParameterType> ): complex128ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* function predicate( z, idx ) { -* return idx[ 0 ] > 0; -* } -* -* var buffer = new Complex128Array( [ 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 = [ 3, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'dtype': 'complex64' -* }; -* var y = filter( x, opts, predicate ); -* // returns -*/ -declare function filter( x: typedndarray, options: Complex64Options, predicate: Predicate, thisArg?: ThisParameterType> ): complex64ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'int32' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: typedndarray, options: Int32Options, predicate: Predicate, thisArg?: ThisParameterType> ): int32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'int16' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: typedndarray, options: Int16Options, predicate: Predicate, thisArg?: ThisParameterType> ): int16ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'int8' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: typedndarray, options: Int8Options, predicate: Predicate, thisArg?: ThisParameterType> ): int8ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'uint32' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: typedndarray, options: Uint32Options, predicate: Predicate, thisArg?: ThisParameterType> ): uint32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'uint16' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: typedndarray, options: Uint16Options, predicate: Predicate, thisArg?: ThisParameterType> ): uint16ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'uint8' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: typedndarray, options: Uint8Options, predicate: Predicate, thisArg?: ThisParameterType> ): uint8ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'uint8c' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: typedndarray, options: Uint8COptions, predicate: Predicate, thisArg?: ThisParameterType> ): uint8cndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'bool' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ true, true, true, true ] -*/ -declare function filter( x: typedndarray, options: BoolOptions, predicate: Predicate, thisArg?: ThisParameterType> ): boolndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'generic' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: typedndarray, options: GenericOptions, predicate: Predicate, thisArg?: ThisParameterType> ): genericndarray; - - -// EXPORTS // - -export = filter; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index f1c84f4..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import e 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 a from"https://cdn.jsdelivr.net/gh/stdlib-js/blas-base-gcopy@v0.2.1-esm/index.mjs";import h 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,G;if(!e(v))throw new TypeError(h("null5t",v));if(arguments.length<3?w=f:3===arguments.length?s(f)?(w=f,k=b):(g=!0,u=f,w=b):(g=!0,u=f,w=b,k=c),!s(w))throw new TypeError(h("null2b",w));if(g){if(!r(u))throw new TypeError(h("null2V",u));if(q=n(u,"dtype")?u.dtype:m(v),n(u,"order")){if(!t(u.order))throw new TypeError(h("null5C","order",u.order));z=u.order}}else q=m(v);if(null===(E=d(q)))throw new TypeError(h("nullBf","dtype",u.dtype));for(void 0===z&&(z=l(v)),A=o(v),D=p(A),y=A.length,B="row-major"===z?y-1:0,C=i(y),x={length:0},T=-1,G=0;G0&&(C=j(A,z,C,B,C)),F=v.get.apply(v,C),w.call(k,F,C.slice(),v)&&(x.length+=1,x[T+=1]=F);return V=new E(D=x.length),a(D,x,1,V,1),new v.constructor(q,V,[D],[1],0,z)}export{v as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index b080961..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 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* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate 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 {boolean} [options.order] - index iteration order\n* @param {Callback} predicate - predicate function\n* @param {*} [thisArg] - predicate 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 { isPrimitive as isEven } from '@stdlib/assert-is-even';\n* import Float64Array from '@stdlib/array-float64';\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndarray2array from '@stdlib/ndarray-to-array';\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 = filter( x, isEven );\n* // returns \n*\n* var arr = ndarray2array( y );\n* // returns [ 2.0, 4.0, 8.0, 10.0 ]\n*/\nfunction filter( x, options, predicate, thisArg ) {\n\tvar hasOpts;\n\tvar ndims;\n\tvar cache;\n\tvar clbk;\n\tvar opts;\n\tvar ctor;\n\tvar cidx;\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 = predicate;\n\t\t} else {\n\t\t\thasOpts = true;\n\t\t\topts = options;\n\t\t\tclbk = predicate;\n\t\t}\n\t} else {\n\t\thasOpts = true;\n\t\topts = options;\n\t\tclbk = predicate;\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 predicate 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 elements according to a predicate function...\n\tcidx = -1;\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 = x.get.apply( x, idx );\n\t\tif ( clbk.call( ctx, v, idx.slice(), x ) ) {\n\t\t\tcache.length += 1;\n\t\t\tcidx += 1;\n\t\t\tcache[ cidx ] = v;\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 filter;\n"],"names":["filter","x","options","predicate","thisArg","hasOpts","ndims","cache","clbk","opts","ctor","cidx","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","get","apply","call","slice","gcopy","constructor"],"mappings":";;6zCA0EA,SAASA,EAAQC,EAAGC,EAASC,EAAWC,GACvC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEAC,EACAC,EACJ,IAAMC,EAAerB,GACpB,MAAM,IAAIsB,UAAWC,EAAQ,SAAUvB,IAmBxC,GAjBKwB,UAAUC,OAAS,EACvBlB,EAAON,EACyB,IAArBuB,UAAUC,OAChBC,EAAYzB,IAChBM,EAAON,EACPU,EAAMT,IAENE,GAAU,EACVI,EAAOP,EACPM,EAAOL,IAGRE,GAAU,EACVI,EAAOP,EACPM,EAAOL,EACPS,EAAMR,IAEDuB,EAAYnB,GACjB,MAAM,IAAIe,UAAWC,EAAQ,SAAUhB,IAExC,GAAKH,EAAU,CACd,IAAMuB,EAAenB,GACpB,MAAM,IAAIc,UAAWC,EAAQ,SAAUf,IAOxC,GAJCQ,EADIY,EAAYpB,EAAM,SACjBA,EAAKqB,MAELC,EAAU9B,GAEX4B,EAAYpB,EAAM,SAAY,CAClC,IAAMuB,EAASvB,EAAKwB,OACnB,MAAM,IAAIV,UAAWC,EAAQ,SAAU,QAASf,EAAKwB,QAEtDpB,EAAMJ,EAAKwB,KACX,CACH,MACEhB,EAAKc,EAAU9B,GAIhB,GAAc,QADdS,EAAOwB,EAAOjB,IAGb,MAAM,IAAIM,UAAWC,EAAQ,SAAU,QAASf,EAAKqB,QA+BtD,SA5Ba,IAARjB,IACJA,EAAMsB,EAAUlC,IAGjBiB,EAAKkB,EAAUnC,GAGfkB,EAAIkB,EAAOnB,GAGXZ,EAAQY,EAAGQ,OAIVZ,EADY,cAARD,EACEP,EAAQ,EAER,EAGPS,EAAMuB,EAAOhC,GAGbC,EAAQ,CACPmB,OAAU,GAIXf,GAAQ,EACFU,EAAI,EAAGA,EAAIF,EAAGE,IACdA,EAAI,IACRN,EAAMwB,EAAoBrB,EAAIL,EAAKE,EAAKD,EAAKC,IAE9CK,EAAInB,EAAEuC,IAAIC,MAAOxC,EAAGc,GACfP,EAAKkC,KAAM9B,EAAKQ,EAAGL,EAAI4B,QAAS1C,KACpCM,EAAMmB,QAAU,EAEhBnB,EADAI,GAAQ,GACQS,GAelB,OARAJ,EAAM,IAAIN,EAHVS,EAAIZ,EAAMmB,QAMVkB,EAAOzB,EAAGZ,EAAO,EAAGS,EAAK,GAGrB,IAAIf,EAAE4C,YAAa5B,EAAID,EAAK,CAAEG,GAAK,CAAE,GAAK,EAAGN,EAGlD"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 1f3c75d..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Codestin Search App - - - -
- - - - - From 7aa6234dbdfe82658ab89584868717308f036941 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 14 Dec 2024 23:31:59 +0000 Subject: [PATCH 17/35] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 54 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 71 +- SECURITY.md | 5 - benchmark/benchmark.1d.js | 150 - benchmark/benchmark.2d.js | 161 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 51 - docs/types/test.ts | 195 - examples/index.js | 38 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 55 - lib/main.js | 196 - package.json | 84 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 892 ---- 44 files changed, 4881 insertions(+), 5318 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.1d.js delete mode 100644 benchmark/benchmark.2d.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 03a0613..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) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 48af73a..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) 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 443f7ec..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: '9 21 * * 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 + + ```
@@ -248,7 +239,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]. @@ -311,11 +302,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-filter/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 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 6958f29..0000000 --- a/benchmark/benchmark.1d.js +++ /dev/null @@ -1,150 +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 filter = require( './../lib' ); - - -// VARIABLES // - -var xtypes = [ 'generic' ]; -var ytypes = [ 'float64' ]; -var orders = [ 'row-major', 'column-major' ]; - - -// FUNCTIONS // - -/** -* Predicate function. -* -* @private -* @param {number} value - array element -* @param {NonNegativeIntegerArray} indices - element indices -* @param {ndarray} arr - input array -* @returns {boolean} result -*/ -function predicate( value ) { - return value > 0.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 = filter( x, opts, predicate ); - 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 c70a9f1..0000000 --- a/benchmark/benchmark.2d.js +++ /dev/null @@ -1,161 +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 filter = require( './../lib' ); - - -// VARIABLES // - -var xtypes = [ 'generic' ]; -var ytypes = [ 'float64' ]; -var orders = [ 'row-major', 'column-major' ]; - - -// FUNCTIONS // - -/** -* Predicate function. -* -* @private -* @param {number} value - array element -* @param {NonNegativeIntegerArray} indices - element indices -* @param {ndarray} arr - input array -* @returns {boolean} result -*/ -function predicate( value ) { - return value > 0.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 = filter( x, opts, predicate ); - 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 51e4f91..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" -%% click B href "https://github.com/stdlib-js/ndarray-filter/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-filter/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-filter/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-filter/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-filter/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/filter -[production-url]: https://github.com/stdlib-js/ndarray-filter/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-filter/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-filter/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-filter/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-filter/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-filter/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-filter/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 aafb9cb..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import filter from '../docs/types/index'; -export = filter; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index b5b2378..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(J,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"),N=require("@stdlib/ndarray-base-numel"),S=require("@stdlib/ndarray-base-next-cartesian-index").assign,A=require("@stdlib/blas-base-gcopy"),v=require("@stdlib/string-format");function B(r,a,g,k){var f,p,t,i,e,c,m,n,h,u,y,s,l,o,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=g):(f=!0,e=a,i=g):(f=!0,e=a,i=g,m=k),!b(i))throw new TypeError(v("invalid argument. Callback argument must be a function. Value: `%s`.",i));if(f){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(c=P(s),c===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),o=N(l),p=l.length,n==="row-major"?h=p-1:h=0,u=D(p),t={length:0},d=0;d0&&(u=S(l,n,u,h,u)),q=r.get.apply(r,u),i.call(m,q,u.slice(),r)&&(t[t.length]=q,t.length+=1);return o=t.length,y=new c(o),A(o,t,1,y,1),w=new r.constructor(s,y,[o],[1],0,n),w}E.exports=B});var G=j();module.exports=G; -/** -* @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 cfadd98..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* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate 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 {boolean} [options.order] - index iteration order\n* @param {Callback} predicate - predicate function\n* @param {*} [thisArg] - predicate 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 isEven = require( '@stdlib/assert-is-even' ).isPrimitive;\n* var Float64Array = require( '@stdlib/array-float64' );\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\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 = filter( x, isEven );\n* // returns \n*\n* var arr = ndarray2array( y );\n* // returns [ 2.0, 4.0, 8.0, 10.0 ]\n*/\nfunction filter( x, options, predicate, 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 = predicate;\n\t\t} else {\n\t\t\thasOpts = true;\n\t\t\topts = options;\n\t\t\tclbk = predicate;\n\t\t}\n\t} else {\n\t\thasOpts = true;\n\t\topts = options;\n\t\tclbk = predicate;\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 predicate 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 elements according to a predicate 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 = x.get.apply( x, idx );\n\t\tif ( clbk.call( ctx, v, idx.slice(), x ) ) {\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 = filter;\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* Return a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function.\n*\n* @module @stdlib/ndarray-filter\n*\n* @example\n* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive;\n* var Float64Array = require( '@stdlib/array-float64' );\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var filter = require( '@stdlib/ndarray-filter' );\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 = filter( x, isEven );\n* // returns \n*\n* var arr = ndarray2array( y );\n* // returns [ 2.0, 4.0, 8.0, 10.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,EAuC9C,SAASC,EAAQC,EAAGC,EAASC,EAAWC,EAAU,CACjD,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,EAAInB,EAAE,IAAI,MAAOA,EAAGa,CAAI,EACnBN,EAAK,KAAMG,EAAKS,EAAGN,EAAI,MAAM,EAAGb,CAAE,IACtCM,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", "filter", "x", "options", "predicate", "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 8ed7071..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,51 +0,0 @@ - -{{alias}}( x[, options], predicate[, thisArg] ) - Returns a shallow copy of an ndarray containing only those elements which - pass a test implemented by a predicate function. - - The predicate function is provided the following arguments: - - - value: current array element. - - indices: current array element indices. - - arr: the input 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 manor, 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'. - - predicate: Function - Predicate function. - - thisArg: any (optional) - Predicate function execution context. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ); - > function f( v ) { return v > 2.0; }; - > var y = {{alias}}( x, f ); - > {{alias:@stdlib/ndarray/to-array}}( y ) - [ 3.0, 4.0 ] - - See Also - -------- diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 046dffb..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,195 +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 empty = require( '@stdlib/ndarray-base-empty' ); -import zeros = require( '@stdlib/ndarray-base-zeros' ); -import filter = require( './index' ); - -/** -* Predicate function. -* -* @param x - input value -* @returns result -*/ -function predicate( x: any ): boolean { - return Boolean( x ); -} - -// The function returns an ndarray... -{ - const sh = [ 2, 2 ]; - const ord = 'row-major'; - - filter( zeros( 'float64', sh, ord ), predicate ); // $ExpectType float64ndarray - filter( zeros( 'float64', sh, ord ), predicate, {} ); // $ExpectType float64ndarray - filter( zeros( 'float32', sh, ord ), predicate ); // $ExpectType float32ndarray - filter( zeros( 'float32', sh, ord ), predicate, {} ); // $ExpectType float32ndarray - filter( zeros( 'complex64', sh, ord ), predicate ); // $ExpectType complex64ndarray - filter( zeros( 'complex64', sh, ord ), predicate, {} ); // $ExpectType complex64ndarray - filter( zeros( 'complex128', sh, ord ), predicate ); // $ExpectType complex128ndarray - filter( zeros( 'complex128', sh, ord ), predicate, {} ); // $ExpectType complex128ndarray - filter( zeros( 'int32', sh, ord ), predicate ); // $ExpectType int32ndarray - filter( zeros( 'int32', sh, ord ), predicate, {} ); // $ExpectType int32ndarray - filter( zeros( 'int16', sh, ord ), predicate ); // $ExpectType int16ndarray - filter( zeros( 'int16', sh, ord ), predicate, {} ); // $ExpectType int16ndarray - filter( zeros( 'int8', sh, ord ), predicate ); // $ExpectType int8ndarray - filter( zeros( 'int8', sh, ord ), predicate, {} ); // $ExpectType int8ndarray - filter( zeros( 'uint32', sh, ord ), predicate ); // $ExpectType uint32ndarray - filter( zeros( 'uint32', sh, ord ), predicate, {} ); // $ExpectType uint32ndarray - filter( zeros( 'uint16', sh, ord ), predicate ); // $ExpectType uint16ndarray - filter( zeros( 'uint16', sh, ord ), predicate, {} ); // $ExpectType uint16ndarray - filter( zeros( 'uint8', sh, ord ), predicate ); // $ExpectType uint8ndarray - filter( zeros( 'uint8', sh, ord ), predicate, {} ); // $ExpectType uint8ndarray - filter( zeros( 'uint8c', sh, ord ), predicate ); // $ExpectType uint8cndarray - filter( zeros( 'uint8c', sh, ord ), predicate, {} ); // $ExpectType uint8cndarray - filter( empty( 'bool', sh, ord ), predicate ); // $ExpectType boolndarray - filter( empty( 'bool', sh, ord ), predicate, {} ); // $ExpectType boolndarray - filter( zeros( 'generic', sh, ord ), predicate ); // $ExpectType genericndarray - filter( zeros( 'generic', sh, ord ), predicate, {} ); // $ExpectType genericndarray - - - filter( zeros( 'generic', sh, ord ), { 'dtype': 'float64' }, predicate ); // $ExpectType float64ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'float64' }, predicate, {} ); // $ExpectType float64ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'float32' }, predicate ); // $ExpectType float32ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'float32' }, predicate, {} ); // $ExpectType float32ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'complex64' }, predicate ); // $ExpectType complex64ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'complex64' }, predicate, {} ); // $ExpectType complex64ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'complex128' }, predicate ); // $ExpectType complex128ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'complex128' }, predicate, {} ); // $ExpectType complex128ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'int32' }, predicate ); // $ExpectType int32ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'int32' }, predicate, {} ); // $ExpectType int32ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'int16' }, predicate ); // $ExpectType int16ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'int16' }, predicate, {} ); // $ExpectType int16ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'int8' }, predicate ); // $ExpectType int8ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'int8' }, predicate, {} ); // $ExpectType int8ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint32' }, predicate ); // $ExpectType uint32ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint32' }, predicate, {} ); // $ExpectType uint32ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint16' }, predicate ); // $ExpectType uint16ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint16' }, predicate, {} ); // $ExpectType uint16ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint8' }, predicate ); // $ExpectType uint8ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint8' }, predicate, {} ); // $ExpectType uint8ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint8c' }, predicate ); // $ExpectType uint8cndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint8c' }, predicate, {} ); // $ExpectType uint8cndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'bool' }, predicate ); // $ExpectType boolndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'bool' }, predicate, {} ); // $ExpectType boolndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'generic' }, predicate ); // $ExpectType genericndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'generic' }, predicate, {} ); // $ExpectType genericndarray - - - filter( zeros( 'float64', sh, ord ), { 'order': ord }, predicate ); // $ExpectType float64ndarray - filter( zeros( 'float64', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType float64ndarray - filter( zeros( 'float32', sh, ord ), { 'order': ord }, predicate ); // $ExpectType float32ndarray - filter( zeros( 'float32', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType float32ndarray - filter( zeros( 'complex64', sh, ord ), { 'order': ord }, predicate ); // $ExpectType complex64ndarray - filter( zeros( 'complex64', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType complex64ndarray - filter( zeros( 'complex128', sh, ord ), { 'order': ord }, predicate ); // $ExpectType complex128ndarray - filter( zeros( 'complex128', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType complex128ndarray - filter( zeros( 'int32', sh, ord ), { 'order': ord }, predicate ); // $ExpectType int32ndarray - filter( zeros( 'int32', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType int32ndarray - filter( zeros( 'int16', sh, ord ), { 'order': ord }, predicate ); // $ExpectType int16ndarray - filter( zeros( 'int16', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType int16ndarray - filter( zeros( 'int8', sh, ord ), { 'order': ord }, predicate ); // $ExpectType int8ndarray - filter( zeros( 'int8', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType int8ndarray - filter( zeros( 'uint32', sh, ord ), { 'order': ord }, predicate ); // $ExpectType uint32ndarray - filter( zeros( 'uint32', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType uint32ndarray - filter( zeros( 'uint16', sh, ord ), { 'order': ord }, predicate ); // $ExpectType uint16ndarray - filter( zeros( 'uint16', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType uint16ndarray - filter( zeros( 'uint8', sh, ord ), { 'order': ord }, predicate ); // $ExpectType uint8ndarray - filter( zeros( 'uint8', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType uint8ndarray - filter( zeros( 'uint8c', sh, ord ), { 'order': ord }, predicate ); // $ExpectType uint8cndarray - filter( zeros( 'uint8c', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType uint8cndarray - filter( empty( 'bool', sh, ord ), { 'order': ord }, predicate ); // $ExpectType boolndarray - filter( empty( 'bool', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType boolndarray - filter( zeros( 'generic', sh, ord ), { 'order': ord }, predicate ); // $ExpectType genericndarray - filter( zeros( 'generic', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType genericndarray - -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - filter( 5, predicate ); // $ExpectError - filter( true, predicate ); // $ExpectError - filter( false, predicate ); // $ExpectError - filter( null, predicate ); // $ExpectError - filter( undefined, predicate ); // $ExpectError - filter( {}, predicate ); // $ExpectError - filter( [ 1 ], predicate ); // $ExpectError - filter( ( x: number ): number => x, predicate ); // $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' ); - - filter( x, '5' ); // $ExpectError - filter( x, true ); // $ExpectError - filter( x, false ); // $ExpectError - filter( x, null ); // $ExpectError - filter( x, undefined ); // $ExpectError - filter( x, {} ); // $ExpectError - filter( 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' ); - - filter( x, '10', predicate, {} ); // $ExpectError - filter( x, 10, predicate, {} ); // $ExpectError - filter( x, false, predicate, {} ); // $ExpectError - filter( x, true, predicate, {} ); // $ExpectError - filter( x, [], predicate, {} ); // $ExpectError - filter( x, ( x: number ): number => x, predicate, {} ); // $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' ); - - filter( x, { 'dtype': '10' }, predicate ); // $ExpectError - filter( x, { 'dtype': 10 }, predicate ); // $ExpectError - filter( x, { 'dtype': null }, predicate ); // $ExpectError - filter( x, { 'dtype': false }, predicate ); // $ExpectError - filter( x, { 'dtype': true }, predicate ); // $ExpectError - filter( x, { 'dtype': [] }, predicate ); // $ExpectError - filter( x, { 'dtype': {} }, predicate ); // $ExpectError - filter( x, { 'dtype': ( x: number ): number => x }, predicate ); // $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' ); - - filter( x, { 'order': '10' }, predicate ); // $ExpectError - filter( x, { 'order': 10 }, predicate ); // $ExpectError - filter( x, { 'order': null }, predicate ); // $ExpectError - filter( x, { 'order': false }, predicate ); // $ExpectError - filter( x, { 'order': true }, predicate ); // $ExpectError - filter( x, { 'order': [] }, predicate ); // $ExpectError - filter( x, { 'order': {} }, predicate ); // $ExpectError - filter( x, { 'order': ( x: number ): number => x }, predicate ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - filter(); // $ExpectError - filter( zeros( 'float64', [ 2, 2 ], 'row-major' ) ); // $ExpectError - filter( 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 e2dd6cb..0000000 --- a/examples/index.js +++ /dev/null @@ -1,38 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var array = require( '@stdlib/ndarray-array' ); -var isPositive = require( '@stdlib/assert-is-positive-number' ).isPrimitive; -var filter = require( './../lib' ); - -var buffer = discreteUniform( 10, -100, 100, { - 'dtype': 'generic' -}); -var x = array( buffer, { - 'shape': [ 5, 2 ], - 'dtype': 'generic' -}); -console.log( ndarray2array( x ) ); - -var y = filter( x, naryFunction( isPositive, 1 ) ); -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 a39a064..e2a9d07 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..1f7d867 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import 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)),D=v.get.apply(v,B),w.call(T,D,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..2c1ae93 --- /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* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate 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 {boolean} [options.order] - index iteration order\n* @param {Callback} predicate - predicate function\n* @param {*} [thisArg] - predicate 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 { isPrimitive as isEven } from '@stdlib/assert-is-even';\n* import Float64Array from '@stdlib/array-float64';\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndarray2array from '@stdlib/ndarray-to-array';\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 = filter( x, isEven );\n* // returns \n*\n* var arr = ndarray2array( y );\n* // returns [ 2.0, 4.0, 8.0, 10.0 ]\n*/\nfunction filter( x, options, predicate, 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 = predicate;\n\t\t} else {\n\t\t\thasOpts = true;\n\t\t\topts = options;\n\t\t\tclbk = predicate;\n\t\t}\n\t} else {\n\t\thasOpts = true;\n\t\topts = options;\n\t\tclbk = predicate;\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 predicate 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 elements according to a predicate 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 = x.get.apply( x, idx );\n\t\tif ( clbk.call( ctx, v, idx.slice(), x ) ) {\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 filter;\n"],"names":["filter","x","options","predicate","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","get","apply","call","slice","gcopy","constructor"],"mappings":";;6zCA0EA,SAASA,EAAQC,EAAGC,EAASC,EAAWC,GACvC,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,IAE9CK,EAAIlB,EAAEsC,IAAIC,MAAOvC,EAAGa,GACfN,EAAKiC,KAAM9B,EAAKQ,EAAGL,EAAI4B,QAASzC,KACpCM,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 46f5998..0000000 --- a/lib/index.js +++ /dev/null @@ -1,55 +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'; - -/** -* Return a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @module @stdlib/ndarray-filter -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var filter = require( '@stdlib/ndarray-filter' ); -* -* 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 = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.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 3cd50e0..0000000 --- a/lib/main.js +++ /dev/null @@ -1,196 +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/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param {ndarray} x - input ndarray -* @param {Options} [options] - function options -* @param {string} [options.dtype] - output array data type -* @param {boolean} [options.order] - index iteration order -* @param {Callback} predicate - predicate function -* @param {*} [thisArg] - predicate 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 isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -function filter( x, options, predicate, 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( 'null5t', x ) ); - } - if ( arguments.length < 3 ) { - clbk = options; - } else if ( arguments.length === 3 ) { - if ( isFunction( options ) ) { - clbk = options; - ctx = predicate; - } else { - hasOpts = true; - opts = options; - clbk = predicate; - } - } else { - hasOpts = true; - opts = options; - clbk = predicate; - ctx = thisArg; - } - if ( !isFunction( clbk ) ) { - throw new TypeError( format( 'null2b', clbk ) ); - } - if ( hasOpts ) { - if ( !isPlainObject( opts ) ) { - throw new TypeError( format( 'null2V', opts ) ); - } - if ( hasOwnProp( opts, 'dtype' ) ) { - dt = opts.dtype; - } else { - dt = getDType( x ); - } - if ( hasOwnProp( opts, 'order' ) ) { - if ( !isOrder( opts.order ) ) { - throw new TypeError( format( 'null5C', '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( 'nullBf', '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 predicate 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 elements according to a predicate function... - for ( i = 0; i < N; i++ ) { - if ( i > 0 ) { - idx = nextCartesianIndex( sh, ord, idx, dim, idx ); - } - v = x.get.apply( x, idx ); - if ( clbk.call( ctx, v, idx.slice(), x ) ) { - 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 = filter; diff --git a/package.json b/package.json index a44b313..2473eda 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Return a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate 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,62 +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/error-tools-fmtprodmsg": "^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-positive-number": "^0.2.2", - "@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", - "@stdlib/utils-nary-function": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "strided", @@ -104,7 +25,6 @@ "select", "take" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..135eeac --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Codestin Search App + + + +
+ + + + + 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 3bea6b3..0000000 --- a/test/test.js +++ /dev/null @@ -1,892 +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 filter = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof filter, '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() { - filter( value, predicate ); - }; - } - - function predicate( z ) { - return ( z > 0.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() { - filter( 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() { - filter( 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() { - filter( x, value, predicate ); - }; - } - - function predicate( z ) { - return ( z > 0.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 - }; - filter( x, opts, predicate ); - }; - } - - function predicate( z ) { - return ( z > 0.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 - }; - filter( x, opts, predicate ); - }; - } - - function predicate( z ) { - return ( z > 0.0 ); - } -}); - -tape( 'the function filters an array according to a predicate 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 = filter( x, predicate ); - - expected = new Float64Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - - t.end(); - - function predicate( z ) { - return ( z > 0.0 ); - } -}); - -tape( 'the function filters an array according to a predicate 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 = filter( x, predicate ); - - expected = new Float64Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - - t.end(); - - function predicate( z ) { - return ( z > 0.0 ); - } -}); - -tape( 'the function filters an array according to a predicate 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 = filter( x, opts, predicate ); - - expected = new Float64Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - - opts = { - 'dtype': 'float32' - }; - y = filter( x, opts, predicate ); - - expected = new Float32Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat32Array( y.data, expected ), true, 'returns expected value' ); - - t.end(); - - function predicate( z ) { - return ( z > 0.0 ); - } -}); - -tape( 'the function filters an array according to a predicate 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 = filter( x, opts, predicate ); - - expected = new Float64Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - - opts = { - 'dtype': 'float32' - }; - y = filter( x, opts, predicate ); - - expected = new Float32Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat32Array( y.data, expected ), true, 'returns expected value' ); - - t.end(); - - function predicate( z ) { - return ( z > 0.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 = filter( x, predicate, ctx ); - - expected = new Float64Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function predicate( z ) { - this.count += 1; // eslint-disable-line no-invalid-this - return ( z > 0.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 = filter( x, {}, predicate, ctx ); - - expected = new Float64Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function predicate( z ) { - this.count += 1; // eslint-disable-line no-invalid-this - return ( z > 0.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 = filter( x, predicate ); - - expected = new Float64Array([ - 1.0, - 3.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 predicate( z, idx, arr ) { - values.push( z ); - indices.push( idx ); - arrays.push( arr ); - return ( z > 0.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 = filter( x, predicate ); - - expected = new Float64Array([ - 1.0, - 3.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 predicate( z, idx, arr ) { - values.push( z ); - indices.push( idx ); - arrays.push( arr ); - return ( z > 0.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 = filter( x, opts, predicate ); - - expected = new Float64Array([ - 1.0, - 3.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 predicate( z, idx, arr ) { - values.push( z ); - indices.push( idx ); - arrays.push( arr ); - return ( z > 0.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 = filter( x, opts, predicate ); - - expected = new Float64Array([ - 1.0, - 3.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 predicate( z, idx, arr ) { - values.push( z ); - indices.push( idx ); - arrays.push( arr ); - return ( z > 0.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 = filter( x, opts, predicate ); - - expected = new Float64Array([ - 1.0, - 3.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 predicate( z, idx, arr ) { - values.push( z ); - indices.push( idx ); - arrays.push( arr ); - return ( z > 0.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 = filter( x, opts, predicate ); - - expected = new Float64Array([ - 1.0, - 3.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 predicate( z, idx, arr ) { - values.push( z ); - indices.push( idx ); - arrays.push( arr ); - return ( z > 0.0 ); - } -}); From 5840a0d8922fb0a89bc378491b87a0d2f43e88c7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 2 Jan 2025 01:46:04 +0000 Subject: [PATCH 18/35] Transform error messages --- lib/main.js | 12 ++++++------ package.json | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/main.js b/lib/main.js index 6ad824e..3cd50e0 100644 --- a/lib/main.js +++ b/lib/main.js @@ -33,7 +33,7 @@ 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' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -91,7 +91,7 @@ function filter( x, options, predicate, thisArg ) { var v; var i; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray-like object. Value: `%s`.', x ) ); + throw new TypeError( format( 'null5t', x ) ); } if ( arguments.length < 3 ) { clbk = options; @@ -111,11 +111,11 @@ function filter( x, options, predicate, thisArg ) { ctx = thisArg; } if ( !isFunction( clbk ) ) { - throw new TypeError( format( 'invalid argument. Callback argument must be a function. Value: `%s`.', clbk ) ); + throw new TypeError( format( 'null2b', clbk ) ); } if ( hasOpts ) { if ( !isPlainObject( opts ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) ); + throw new TypeError( format( 'null2V', opts ) ); } if ( hasOwnProp( opts, 'dtype' ) ) { dt = opts.dtype; @@ -124,7 +124,7 @@ function filter( x, options, predicate, thisArg ) { } 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 ) ); + throw new TypeError( format( 'null5C', 'order', opts.order ) ); } ord = opts.order; } @@ -135,7 +135,7 @@ function filter( x, options, predicate, thisArg ) { 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 ) ); + throw new TypeError( format( 'nullBf', 'dtype', opts.dtype ) ); } // Resolve the iteration order: if ( ord === void 0 ) { diff --git a/package.json b/package.json index 22065aa..a44b313 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@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/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From cd479c855b0321617262b2f192d5f6264daf2771 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 2 Jan 2025 01:47:06 +0000 Subject: [PATCH 19/35] Remove files --- index.d.ts | 1612 ---------------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 6459 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index e2a9d07..0000000 --- a/index.d.ts +++ /dev/null @@ -1,1612 +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. -*/ - -// TypeScript Version: 4.1 - -/// - -/* eslint-disable max-lines */ - -import { typedndarray, DataType, Order, float64ndarray, float32ndarray, complex128ndarray, complex64ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, boolndarray, genericndarray } from '@stdlib/types/ndarray'; -import { Complex64, Complex128 } from '@stdlib/types/complex'; - -/** -* Returns a boolean indicating whether an element passes a test. -* -* @returns boolean indicating whether an element passes a test -*/ -type Nullary = ( this: V ) => boolean; - -/** -* Returns a boolean indicating whether an element passes a test. -* -* @param value - current array element -* @returns boolean indicating whether an element passes a test -*/ -type Unary = ( this: V, value: T ) => boolean; - -/** -* Returns a boolean indicating whether an element passes a test. -* -* @param value - current array element -* @param indices - current array element indices -* @returns boolean indicating whether an element passes a test -*/ -type Binary = ( this: V, value: T, indices: Array ) => boolean; - -/** -* Returns a boolean indicating whether an element passes a test. -* -* @param value - current array element -* @param indices - current array element indices -* @param arr - input array -* @returns boolean indicating whether an element passes a test -*/ -type Ternary = ( this: V, value: T, indices: Array, arr: typedndarray ) => boolean; - -/** -* Returns a boolean indicating whether an element passes a test. -* -* @param value - current array element -* @param indices - current array element indices -* @param arr - input array -* @returns boolean indicating whether an element passes a test -*/ -type Predicate = Nullary | Unary | Binary | Ternary; - -/** -* Interface describing "base" function options. -*/ -interface BaseOptions { - /** - * Index iteration order. - * - * ## Notes - * - * - By default, the function iterates over elements according to the layout order of the provided ndarray. Accordingly, for row-major input ndarrays, the last dimension indices increment fastest. For column-major input ndarrays, the first dimension indices increment fastest. To override the inferred order and ensure that indices increment in a specific manor, regardless of the input ndarray's layout order, explicitly set the iteration order. Note, however, that iterating according to an order which does not match that of the input ndarray may, in some circumstances, result in performance degradation due to cache misses. - */ - order?: Order; -} - -/** -* Interface describing function options. -*/ -interface OrderOptions { - /** - * Index iteration order. - * - * ## Notes - * - * - By default, the function iterates over elements according to the layout order of the provided ndarray. Accordingly, for row-major input ndarrays, the last dimension indices increment fastest. For column-major input ndarrays, the first dimension indices increment fastest. To override the inferred order and ensure that indices increment in a specific manor, regardless of the input ndarray's layout order, explicitly set the iteration order. Note, however, that iterating according to an order which does not match that of the input ndarray may, in some circumstances, result in performance degradation due to cache misses. - */ - order: Order; -} - -/** -* Interface describing function options. -*/ -interface Options extends BaseOptions { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: DataType; -} - -/** -* Interface describing function options. -*/ -interface Float64Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'float64'; -} - -/** -* Interface describing function options. -*/ -interface Float32Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'float32'; -} - -/** -* Interface describing function options. -*/ -interface Complex128Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'complex128'; -} - -/** -* Interface describing function options. -*/ -interface Complex64Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'complex64'; -} - -/** -* Interface describing function options. -*/ -interface Int32Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'int32'; -} - -/** -* Interface describing function options. -*/ -interface Int16Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'int16'; -} - -/** -* Interface describing function options. -*/ -interface Int8Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'int8'; -} - -/** -* Interface describing function options. -*/ -interface Uint32Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'uint32'; -} - -/** -* Interface describing function options. -*/ -interface Uint16Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'uint16'; -} - -/** -* Interface describing function options. -*/ -interface Uint8Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'uint8'; -} - -/** -* Interface describing function options. -*/ -interface Uint8COptions extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'uint8c'; -} - -/** -* Interface describing function options. -*/ -interface BoolOptions extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'bool'; -} - -/** -* Interface describing function options. -*/ -interface GenericOptions extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'generic'; -} - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: float64ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): float64ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float32Array = require( '@stdlib/array-float32' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Float32Array( [ 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( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: float32ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): float32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var Complex64Array = require( '@stdlib/array-complex64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* function predicate( z, idx ) { -* return idx[ 0 ] > 0; -* } -* -* var buffer = new Complex64Array( [ 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 = [ 3, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, predicate ); -* // returns -*/ -declare function filter( x: complex64ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): complex64ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* function predicate( z, idx ) { -* return idx[ 0 ] > 0; -* } -* -* var buffer = new Complex128Array( [ 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 = [ 3, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, predicate ); -* // returns -*/ -declare function filter( x: complex128ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): complex128ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Int32Array = require( '@stdlib/array-int32' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Int32Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: int32ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): int32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Int16Array = require( '@stdlib/array-int16' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Int16Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: int16ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): int16ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Int8Array = require( '@stdlib/array-int8' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Int8Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: int8ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): int8ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint32Array = require( '@stdlib/array-uint32' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint32Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint32ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): uint32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint16Array = require( '@stdlib/array-uint16' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint16Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint16ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): uint16ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint8Array = require( '@stdlib/array-uint8' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint8Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint8ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): uint8ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint8ClampedArray( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint8cndarray, predicate: Predicate, thisArg?: ThisParameterType> ): uint8cndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var BooleanArray = require( '@stdlib/array-bool' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* function predicate( z ) { -* return z; -* } -* -* var buffer = new BooleanArray( [ false, true, false, true, false, true, false, true, false, true, false, true ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'bool', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, predicate ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ true, true, true, true ] -*/ -declare function filter( x: boolndarray, predicate: Predicate, thisArg?: ThisParameterType> ): boolndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 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( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: genericndarray, predicate: Predicate, thisArg?: ThisParameterType> ): genericndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: float64ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): float64ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float32Array = require( '@stdlib/array-float32' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Float32Array( [ 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( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: float32ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): float32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var Complex64Array = require( '@stdlib/array-complex64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* function predicate( z, idx ) { -* return idx[ 0 ] > 0; -* } -* -* var buffer = new Complex64Array( [ 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 = [ 3, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, predicate ); -* // returns -*/ -declare function filter( x: complex64ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): complex64ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* function predicate( z, idx ) { -* return idx[ 0 ] > 0; -* } -* -* var buffer = new Complex128Array( [ 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 = [ 3, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, predicate ); -* // returns -*/ -declare function filter( x: complex128ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): complex128ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Int32Array = require( '@stdlib/array-int32' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Int32Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: int32ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): int32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Int16Array = require( '@stdlib/array-int16' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Int16Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: int16ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): int16ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Int8Array = require( '@stdlib/array-int8' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Int8Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: int8ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): int8ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint32Array = require( '@stdlib/array-uint32' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint32Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint32ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): uint32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint16Array = require( '@stdlib/array-uint16' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint16Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint16ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): uint16ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint8Array = require( '@stdlib/array-uint8' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint8Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint8ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): uint8ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint8ClampedArray( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint8cndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): uint8cndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var BooleanArray = require( '@stdlib/array-bool' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* function predicate( z ) { -* return z; -* } -* -* var buffer = new BooleanArray( [ false, true, false, true, false, true, false, true, false, true, false, true ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'bool', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, predicate ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ true, true, true, true ] -*/ -declare function filter( x: boolndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): boolndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 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( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: genericndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): genericndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'float64' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: typedndarray, options: Float64Options, predicate: Predicate, thisArg?: ThisParameterType> ): float64ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'float32' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: typedndarray, options: Float32Options, predicate: Predicate, thisArg?: ThisParameterType> ): float32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* function predicate( z, idx ) { -* return idx[ 0 ] > 0; -* } -* -* var buffer = new Complex128Array( [ 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 = [ 3, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'dtype': 'complex128' -* }; -* var y = filter( x, opts, predicate ); -* // returns -*/ -declare function filter( x: typedndarray, options: Complex128Options, predicate: Predicate, thisArg?: ThisParameterType> ): complex128ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* function predicate( z, idx ) { -* return idx[ 0 ] > 0; -* } -* -* var buffer = new Complex128Array( [ 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 = [ 3, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'dtype': 'complex64' -* }; -* var y = filter( x, opts, predicate ); -* // returns -*/ -declare function filter( x: typedndarray, options: Complex64Options, predicate: Predicate, thisArg?: ThisParameterType> ): complex64ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'int32' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: typedndarray, options: Int32Options, predicate: Predicate, thisArg?: ThisParameterType> ): int32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'int16' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: typedndarray, options: Int16Options, predicate: Predicate, thisArg?: ThisParameterType> ): int16ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'int8' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: typedndarray, options: Int8Options, predicate: Predicate, thisArg?: ThisParameterType> ): int8ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'uint32' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: typedndarray, options: Uint32Options, predicate: Predicate, thisArg?: ThisParameterType> ): uint32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'uint16' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: typedndarray, options: Uint16Options, predicate: Predicate, thisArg?: ThisParameterType> ): uint16ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'uint8' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: typedndarray, options: Uint8Options, predicate: Predicate, thisArg?: ThisParameterType> ): uint8ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'uint8c' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: typedndarray, options: Uint8COptions, predicate: Predicate, thisArg?: ThisParameterType> ): uint8cndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'bool' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ true, true, true, true ] -*/ -declare function filter( x: typedndarray, options: BoolOptions, predicate: Predicate, thisArg?: ThisParameterType> ): boolndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'generic' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: typedndarray, options: GenericOptions, predicate: Predicate, thisArg?: ThisParameterType> ): genericndarray; - - -// EXPORTS // - -export = filter; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 1f7d867..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import 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)),D=v.get.apply(v,B),w.call(T,D,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 deleted file mode 100644 index 2c1ae93..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 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* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate 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 {boolean} [options.order] - index iteration order\n* @param {Callback} predicate - predicate function\n* @param {*} [thisArg] - predicate 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 { isPrimitive as isEven } from '@stdlib/assert-is-even';\n* import Float64Array from '@stdlib/array-float64';\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndarray2array from '@stdlib/ndarray-to-array';\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 = filter( x, isEven );\n* // returns \n*\n* var arr = ndarray2array( y );\n* // returns [ 2.0, 4.0, 8.0, 10.0 ]\n*/\nfunction filter( x, options, predicate, 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 = predicate;\n\t\t} else {\n\t\t\thasOpts = true;\n\t\t\topts = options;\n\t\t\tclbk = predicate;\n\t\t}\n\t} else {\n\t\thasOpts = true;\n\t\topts = options;\n\t\tclbk = predicate;\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 predicate 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 elements according to a predicate 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 = x.get.apply( x, idx );\n\t\tif ( clbk.call( ctx, v, idx.slice(), x ) ) {\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 filter;\n"],"names":["filter","x","options","predicate","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","get","apply","call","slice","gcopy","constructor"],"mappings":";;6zCA0EA,SAASA,EAAQC,EAAGC,EAASC,EAAWC,GACvC,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,IAE9CK,EAAIlB,EAAEsC,IAAIC,MAAOvC,EAAGa,GACfN,EAAKiC,KAAM9B,EAAKQ,EAAGL,EAAI4B,QAASzC,KACpCM,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/stats.html b/stats.html deleted file mode 100644 index 135eeac..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Codestin Search App - - - -
- - - - - From 4afe6477d5a0c308a83ab6a7a97134d2b37f43c5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 2 Jan 2025 01:47:23 +0000 Subject: [PATCH 20/35] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 56 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 71 +- SECURITY.md | 5 - benchmark/benchmark.1d.js | 150 - benchmark/benchmark.2d.js | 161 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 51 - docs/types/test.ts | 195 - examples/index.js | 38 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 55 - lib/main.js | 196 - package.json | 84 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 892 ---- 44 files changed, 4881 insertions(+), 5320 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.1d.js delete mode 100644 benchmark/benchmark.2d.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0779e8a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 03a0613..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) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 48af73a..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) 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 443f7ec..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: '9 21 * * 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 + + ```
@@ -248,7 +239,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]. @@ -311,11 +302,11 @@ Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-filter/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 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 6958f29..0000000 --- a/benchmark/benchmark.1d.js +++ /dev/null @@ -1,150 +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 filter = require( './../lib' ); - - -// VARIABLES // - -var xtypes = [ 'generic' ]; -var ytypes = [ 'float64' ]; -var orders = [ 'row-major', 'column-major' ]; - - -// FUNCTIONS // - -/** -* Predicate function. -* -* @private -* @param {number} value - array element -* @param {NonNegativeIntegerArray} indices - element indices -* @param {ndarray} arr - input array -* @returns {boolean} result -*/ -function predicate( value ) { - return value > 0.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 = filter( x, opts, predicate ); - 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 c70a9f1..0000000 --- a/benchmark/benchmark.2d.js +++ /dev/null @@ -1,161 +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 filter = require( './../lib' ); - - -// VARIABLES // - -var xtypes = [ 'generic' ]; -var ytypes = [ 'float64' ]; -var orders = [ 'row-major', 'column-major' ]; - - -// FUNCTIONS // - -/** -* Predicate function. -* -* @private -* @param {number} value - array element -* @param {NonNegativeIntegerArray} indices - element indices -* @param {ndarray} arr - input array -* @returns {boolean} result -*/ -function predicate( value ) { - return value > 0.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 = filter( x, opts, predicate ); - 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 51e4f91..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" -%% click B href "https://github.com/stdlib-js/ndarray-filter/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-filter/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-filter/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-filter/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-filter/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/filter -[production-url]: https://github.com/stdlib-js/ndarray-filter/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-filter/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-filter/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-filter/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-filter/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-filter/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-filter/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 aafb9cb..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import filter from '../docs/types/index'; -export = filter; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index b5b2378..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(J,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"),N=require("@stdlib/ndarray-base-numel"),S=require("@stdlib/ndarray-base-next-cartesian-index").assign,A=require("@stdlib/blas-base-gcopy"),v=require("@stdlib/string-format");function B(r,a,g,k){var f,p,t,i,e,c,m,n,h,u,y,s,l,o,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=g):(f=!0,e=a,i=g):(f=!0,e=a,i=g,m=k),!b(i))throw new TypeError(v("invalid argument. Callback argument must be a function. Value: `%s`.",i));if(f){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(c=P(s),c===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),o=N(l),p=l.length,n==="row-major"?h=p-1:h=0,u=D(p),t={length:0},d=0;d0&&(u=S(l,n,u,h,u)),q=r.get.apply(r,u),i.call(m,q,u.slice(),r)&&(t[t.length]=q,t.length+=1);return o=t.length,y=new c(o),A(o,t,1,y,1),w=new r.constructor(s,y,[o],[1],0,n),w}E.exports=B});var G=j();module.exports=G; -/** -* @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 cfadd98..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* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate 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 {boolean} [options.order] - index iteration order\n* @param {Callback} predicate - predicate function\n* @param {*} [thisArg] - predicate 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 isEven = require( '@stdlib/assert-is-even' ).isPrimitive;\n* var Float64Array = require( '@stdlib/array-float64' );\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\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 = filter( x, isEven );\n* // returns \n*\n* var arr = ndarray2array( y );\n* // returns [ 2.0, 4.0, 8.0, 10.0 ]\n*/\nfunction filter( x, options, predicate, 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 = predicate;\n\t\t} else {\n\t\t\thasOpts = true;\n\t\t\topts = options;\n\t\t\tclbk = predicate;\n\t\t}\n\t} else {\n\t\thasOpts = true;\n\t\topts = options;\n\t\tclbk = predicate;\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 predicate 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 elements according to a predicate 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 = x.get.apply( x, idx );\n\t\tif ( clbk.call( ctx, v, idx.slice(), x ) ) {\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 = filter;\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* Return a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function.\n*\n* @module @stdlib/ndarray-filter\n*\n* @example\n* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive;\n* var Float64Array = require( '@stdlib/array-float64' );\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var filter = require( '@stdlib/ndarray-filter' );\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 = filter( x, isEven );\n* // returns \n*\n* var arr = ndarray2array( y );\n* // returns [ 2.0, 4.0, 8.0, 10.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,EAuC9C,SAASC,EAAQC,EAAGC,EAASC,EAAWC,EAAU,CACjD,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,EAAInB,EAAE,IAAI,MAAOA,EAAGa,CAAI,EACnBN,EAAK,KAAMG,EAAKS,EAAGN,EAAI,MAAM,EAAGb,CAAE,IACtCM,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", "filter", "x", "options", "predicate", "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 75de7ed..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,51 +0,0 @@ - -{{alias}}( x[, options], predicate[, thisArg] ) - Returns a shallow copy of an ndarray containing only those elements which - pass a test implemented by a predicate function. - - The predicate function is provided the following arguments: - - - value: current array element. - - indices: current array element indices. - - arr: the input 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'. - - predicate: Function - Predicate function. - - thisArg: any (optional) - Predicate function execution context. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ); - > function f( v ) { return v > 2.0; }; - > var y = {{alias}}( x, f ); - > {{alias:@stdlib/ndarray/to-array}}( y ) - [ 3.0, 4.0 ] - - See Also - -------- diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 046dffb..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,195 +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 empty = require( '@stdlib/ndarray-base-empty' ); -import zeros = require( '@stdlib/ndarray-base-zeros' ); -import filter = require( './index' ); - -/** -* Predicate function. -* -* @param x - input value -* @returns result -*/ -function predicate( x: any ): boolean { - return Boolean( x ); -} - -// The function returns an ndarray... -{ - const sh = [ 2, 2 ]; - const ord = 'row-major'; - - filter( zeros( 'float64', sh, ord ), predicate ); // $ExpectType float64ndarray - filter( zeros( 'float64', sh, ord ), predicate, {} ); // $ExpectType float64ndarray - filter( zeros( 'float32', sh, ord ), predicate ); // $ExpectType float32ndarray - filter( zeros( 'float32', sh, ord ), predicate, {} ); // $ExpectType float32ndarray - filter( zeros( 'complex64', sh, ord ), predicate ); // $ExpectType complex64ndarray - filter( zeros( 'complex64', sh, ord ), predicate, {} ); // $ExpectType complex64ndarray - filter( zeros( 'complex128', sh, ord ), predicate ); // $ExpectType complex128ndarray - filter( zeros( 'complex128', sh, ord ), predicate, {} ); // $ExpectType complex128ndarray - filter( zeros( 'int32', sh, ord ), predicate ); // $ExpectType int32ndarray - filter( zeros( 'int32', sh, ord ), predicate, {} ); // $ExpectType int32ndarray - filter( zeros( 'int16', sh, ord ), predicate ); // $ExpectType int16ndarray - filter( zeros( 'int16', sh, ord ), predicate, {} ); // $ExpectType int16ndarray - filter( zeros( 'int8', sh, ord ), predicate ); // $ExpectType int8ndarray - filter( zeros( 'int8', sh, ord ), predicate, {} ); // $ExpectType int8ndarray - filter( zeros( 'uint32', sh, ord ), predicate ); // $ExpectType uint32ndarray - filter( zeros( 'uint32', sh, ord ), predicate, {} ); // $ExpectType uint32ndarray - filter( zeros( 'uint16', sh, ord ), predicate ); // $ExpectType uint16ndarray - filter( zeros( 'uint16', sh, ord ), predicate, {} ); // $ExpectType uint16ndarray - filter( zeros( 'uint8', sh, ord ), predicate ); // $ExpectType uint8ndarray - filter( zeros( 'uint8', sh, ord ), predicate, {} ); // $ExpectType uint8ndarray - filter( zeros( 'uint8c', sh, ord ), predicate ); // $ExpectType uint8cndarray - filter( zeros( 'uint8c', sh, ord ), predicate, {} ); // $ExpectType uint8cndarray - filter( empty( 'bool', sh, ord ), predicate ); // $ExpectType boolndarray - filter( empty( 'bool', sh, ord ), predicate, {} ); // $ExpectType boolndarray - filter( zeros( 'generic', sh, ord ), predicate ); // $ExpectType genericndarray - filter( zeros( 'generic', sh, ord ), predicate, {} ); // $ExpectType genericndarray - - - filter( zeros( 'generic', sh, ord ), { 'dtype': 'float64' }, predicate ); // $ExpectType float64ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'float64' }, predicate, {} ); // $ExpectType float64ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'float32' }, predicate ); // $ExpectType float32ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'float32' }, predicate, {} ); // $ExpectType float32ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'complex64' }, predicate ); // $ExpectType complex64ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'complex64' }, predicate, {} ); // $ExpectType complex64ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'complex128' }, predicate ); // $ExpectType complex128ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'complex128' }, predicate, {} ); // $ExpectType complex128ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'int32' }, predicate ); // $ExpectType int32ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'int32' }, predicate, {} ); // $ExpectType int32ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'int16' }, predicate ); // $ExpectType int16ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'int16' }, predicate, {} ); // $ExpectType int16ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'int8' }, predicate ); // $ExpectType int8ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'int8' }, predicate, {} ); // $ExpectType int8ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint32' }, predicate ); // $ExpectType uint32ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint32' }, predicate, {} ); // $ExpectType uint32ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint16' }, predicate ); // $ExpectType uint16ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint16' }, predicate, {} ); // $ExpectType uint16ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint8' }, predicate ); // $ExpectType uint8ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint8' }, predicate, {} ); // $ExpectType uint8ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint8c' }, predicate ); // $ExpectType uint8cndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint8c' }, predicate, {} ); // $ExpectType uint8cndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'bool' }, predicate ); // $ExpectType boolndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'bool' }, predicate, {} ); // $ExpectType boolndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'generic' }, predicate ); // $ExpectType genericndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'generic' }, predicate, {} ); // $ExpectType genericndarray - - - filter( zeros( 'float64', sh, ord ), { 'order': ord }, predicate ); // $ExpectType float64ndarray - filter( zeros( 'float64', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType float64ndarray - filter( zeros( 'float32', sh, ord ), { 'order': ord }, predicate ); // $ExpectType float32ndarray - filter( zeros( 'float32', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType float32ndarray - filter( zeros( 'complex64', sh, ord ), { 'order': ord }, predicate ); // $ExpectType complex64ndarray - filter( zeros( 'complex64', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType complex64ndarray - filter( zeros( 'complex128', sh, ord ), { 'order': ord }, predicate ); // $ExpectType complex128ndarray - filter( zeros( 'complex128', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType complex128ndarray - filter( zeros( 'int32', sh, ord ), { 'order': ord }, predicate ); // $ExpectType int32ndarray - filter( zeros( 'int32', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType int32ndarray - filter( zeros( 'int16', sh, ord ), { 'order': ord }, predicate ); // $ExpectType int16ndarray - filter( zeros( 'int16', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType int16ndarray - filter( zeros( 'int8', sh, ord ), { 'order': ord }, predicate ); // $ExpectType int8ndarray - filter( zeros( 'int8', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType int8ndarray - filter( zeros( 'uint32', sh, ord ), { 'order': ord }, predicate ); // $ExpectType uint32ndarray - filter( zeros( 'uint32', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType uint32ndarray - filter( zeros( 'uint16', sh, ord ), { 'order': ord }, predicate ); // $ExpectType uint16ndarray - filter( zeros( 'uint16', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType uint16ndarray - filter( zeros( 'uint8', sh, ord ), { 'order': ord }, predicate ); // $ExpectType uint8ndarray - filter( zeros( 'uint8', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType uint8ndarray - filter( zeros( 'uint8c', sh, ord ), { 'order': ord }, predicate ); // $ExpectType uint8cndarray - filter( zeros( 'uint8c', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType uint8cndarray - filter( empty( 'bool', sh, ord ), { 'order': ord }, predicate ); // $ExpectType boolndarray - filter( empty( 'bool', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType boolndarray - filter( zeros( 'generic', sh, ord ), { 'order': ord }, predicate ); // $ExpectType genericndarray - filter( zeros( 'generic', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType genericndarray - -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - filter( 5, predicate ); // $ExpectError - filter( true, predicate ); // $ExpectError - filter( false, predicate ); // $ExpectError - filter( null, predicate ); // $ExpectError - filter( undefined, predicate ); // $ExpectError - filter( {}, predicate ); // $ExpectError - filter( [ 1 ], predicate ); // $ExpectError - filter( ( x: number ): number => x, predicate ); // $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' ); - - filter( x, '5' ); // $ExpectError - filter( x, true ); // $ExpectError - filter( x, false ); // $ExpectError - filter( x, null ); // $ExpectError - filter( x, undefined ); // $ExpectError - filter( x, {} ); // $ExpectError - filter( 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' ); - - filter( x, '10', predicate, {} ); // $ExpectError - filter( x, 10, predicate, {} ); // $ExpectError - filter( x, false, predicate, {} ); // $ExpectError - filter( x, true, predicate, {} ); // $ExpectError - filter( x, [], predicate, {} ); // $ExpectError - filter( x, ( x: number ): number => x, predicate, {} ); // $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' ); - - filter( x, { 'dtype': '10' }, predicate ); // $ExpectError - filter( x, { 'dtype': 10 }, predicate ); // $ExpectError - filter( x, { 'dtype': null }, predicate ); // $ExpectError - filter( x, { 'dtype': false }, predicate ); // $ExpectError - filter( x, { 'dtype': true }, predicate ); // $ExpectError - filter( x, { 'dtype': [] }, predicate ); // $ExpectError - filter( x, { 'dtype': {} }, predicate ); // $ExpectError - filter( x, { 'dtype': ( x: number ): number => x }, predicate ); // $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' ); - - filter( x, { 'order': '10' }, predicate ); // $ExpectError - filter( x, { 'order': 10 }, predicate ); // $ExpectError - filter( x, { 'order': null }, predicate ); // $ExpectError - filter( x, { 'order': false }, predicate ); // $ExpectError - filter( x, { 'order': true }, predicate ); // $ExpectError - filter( x, { 'order': [] }, predicate ); // $ExpectError - filter( x, { 'order': {} }, predicate ); // $ExpectError - filter( x, { 'order': ( x: number ): number => x }, predicate ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - filter(); // $ExpectError - filter( zeros( 'float64', [ 2, 2 ], 'row-major' ) ); // $ExpectError - filter( 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 e2dd6cb..0000000 --- a/examples/index.js +++ /dev/null @@ -1,38 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var array = require( '@stdlib/ndarray-array' ); -var isPositive = require( '@stdlib/assert-is-positive-number' ).isPrimitive; -var filter = require( './../lib' ); - -var buffer = discreteUniform( 10, -100, 100, { - 'dtype': 'generic' -}); -var x = array( buffer, { - 'shape': [ 5, 2 ], - 'dtype': 'generic' -}); -console.log( ndarray2array( x ) ); - -var y = filter( x, naryFunction( isPositive, 1 ) ); -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 c4dadbe..7f6ff4a 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..483f25f --- /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)),D=v.get.apply(v,B),w.call(T,D,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..2c1ae93 --- /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* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate 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 {boolean} [options.order] - index iteration order\n* @param {Callback} predicate - predicate function\n* @param {*} [thisArg] - predicate 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 { isPrimitive as isEven } from '@stdlib/assert-is-even';\n* import Float64Array from '@stdlib/array-float64';\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndarray2array from '@stdlib/ndarray-to-array';\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 = filter( x, isEven );\n* // returns \n*\n* var arr = ndarray2array( y );\n* // returns [ 2.0, 4.0, 8.0, 10.0 ]\n*/\nfunction filter( x, options, predicate, 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 = predicate;\n\t\t} else {\n\t\t\thasOpts = true;\n\t\t\topts = options;\n\t\t\tclbk = predicate;\n\t\t}\n\t} else {\n\t\thasOpts = true;\n\t\topts = options;\n\t\tclbk = predicate;\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 predicate 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 elements according to a predicate 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 = x.get.apply( x, idx );\n\t\tif ( clbk.call( ctx, v, idx.slice(), x ) ) {\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 filter;\n"],"names":["filter","x","options","predicate","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","get","apply","call","slice","gcopy","constructor"],"mappings":";;6zCA0EA,SAASA,EAAQC,EAAGC,EAASC,EAAWC,GACvC,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,IAE9CK,EAAIlB,EAAEsC,IAAIC,MAAOvC,EAAGa,GACfN,EAAKiC,KAAM9B,EAAKQ,EAAGL,EAAI4B,QAASzC,KACpCM,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 46f5998..0000000 --- a/lib/index.js +++ /dev/null @@ -1,55 +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'; - -/** -* Return a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @module @stdlib/ndarray-filter -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var filter = require( '@stdlib/ndarray-filter' ); -* -* 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 = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.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 3cd50e0..0000000 --- a/lib/main.js +++ /dev/null @@ -1,196 +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/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param {ndarray} x - input ndarray -* @param {Options} [options] - function options -* @param {string} [options.dtype] - output array data type -* @param {boolean} [options.order] - index iteration order -* @param {Callback} predicate - predicate function -* @param {*} [thisArg] - predicate 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 isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -function filter( x, options, predicate, 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( 'null5t', x ) ); - } - if ( arguments.length < 3 ) { - clbk = options; - } else if ( arguments.length === 3 ) { - if ( isFunction( options ) ) { - clbk = options; - ctx = predicate; - } else { - hasOpts = true; - opts = options; - clbk = predicate; - } - } else { - hasOpts = true; - opts = options; - clbk = predicate; - ctx = thisArg; - } - if ( !isFunction( clbk ) ) { - throw new TypeError( format( 'null2b', clbk ) ); - } - if ( hasOpts ) { - if ( !isPlainObject( opts ) ) { - throw new TypeError( format( 'null2V', opts ) ); - } - if ( hasOwnProp( opts, 'dtype' ) ) { - dt = opts.dtype; - } else { - dt = getDType( x ); - } - if ( hasOwnProp( opts, 'order' ) ) { - if ( !isOrder( opts.order ) ) { - throw new TypeError( format( 'null5C', '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( 'nullBf', '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 predicate 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 elements according to a predicate function... - for ( i = 0; i < N; i++ ) { - if ( i > 0 ) { - idx = nextCartesianIndex( sh, ord, idx, dim, idx ); - } - v = x.get.apply( x, idx ); - if ( clbk.call( ctx, v, idx.slice(), x ) ) { - 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 = filter; diff --git a/package.json b/package.json index a44b313..2473eda 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Return a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate 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,62 +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/error-tools-fmtprodmsg": "^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-positive-number": "^0.2.2", - "@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", - "@stdlib/utils-nary-function": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "strided", @@ -104,7 +25,6 @@ "select", "take" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..135eeac --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Codestin Search App + + + +
+ + + + + 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 3bea6b3..0000000 --- a/test/test.js +++ /dev/null @@ -1,892 +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 filter = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof filter, '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() { - filter( value, predicate ); - }; - } - - function predicate( z ) { - return ( z > 0.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() { - filter( 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() { - filter( 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() { - filter( x, value, predicate ); - }; - } - - function predicate( z ) { - return ( z > 0.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 - }; - filter( x, opts, predicate ); - }; - } - - function predicate( z ) { - return ( z > 0.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 - }; - filter( x, opts, predicate ); - }; - } - - function predicate( z ) { - return ( z > 0.0 ); - } -}); - -tape( 'the function filters an array according to a predicate 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 = filter( x, predicate ); - - expected = new Float64Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - - t.end(); - - function predicate( z ) { - return ( z > 0.0 ); - } -}); - -tape( 'the function filters an array according to a predicate 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 = filter( x, predicate ); - - expected = new Float64Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - - t.end(); - - function predicate( z ) { - return ( z > 0.0 ); - } -}); - -tape( 'the function filters an array according to a predicate 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 = filter( x, opts, predicate ); - - expected = new Float64Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - - opts = { - 'dtype': 'float32' - }; - y = filter( x, opts, predicate ); - - expected = new Float32Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat32Array( y.data, expected ), true, 'returns expected value' ); - - t.end(); - - function predicate( z ) { - return ( z > 0.0 ); - } -}); - -tape( 'the function filters an array according to a predicate 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 = filter( x, opts, predicate ); - - expected = new Float64Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - - opts = { - 'dtype': 'float32' - }; - y = filter( x, opts, predicate ); - - expected = new Float32Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat32Array( y.data, expected ), true, 'returns expected value' ); - - t.end(); - - function predicate( z ) { - return ( z > 0.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 = filter( x, predicate, ctx ); - - expected = new Float64Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function predicate( z ) { - this.count += 1; // eslint-disable-line no-invalid-this - return ( z > 0.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 = filter( x, {}, predicate, ctx ); - - expected = new Float64Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function predicate( z ) { - this.count += 1; // eslint-disable-line no-invalid-this - return ( z > 0.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 = filter( x, predicate ); - - expected = new Float64Array([ - 1.0, - 3.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 predicate( z, idx, arr ) { - values.push( z ); - indices.push( idx ); - arrays.push( arr ); - return ( z > 0.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 = filter( x, predicate ); - - expected = new Float64Array([ - 1.0, - 3.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 predicate( z, idx, arr ) { - values.push( z ); - indices.push( idx ); - arrays.push( arr ); - return ( z > 0.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 = filter( x, opts, predicate ); - - expected = new Float64Array([ - 1.0, - 3.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 predicate( z, idx, arr ) { - values.push( z ); - indices.push( idx ); - arrays.push( arr ); - return ( z > 0.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 = filter( x, opts, predicate ); - - expected = new Float64Array([ - 1.0, - 3.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 predicate( z, idx, arr ) { - values.push( z ); - indices.push( idx ); - arrays.push( arr ); - return ( z > 0.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 = filter( x, opts, predicate ); - - expected = new Float64Array([ - 1.0, - 3.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 predicate( z, idx, arr ) { - values.push( z ); - indices.push( idx ); - arrays.push( arr ); - return ( z > 0.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 = filter( x, opts, predicate ); - - expected = new Float64Array([ - 1.0, - 3.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 predicate( z, idx, arr ) { - values.push( z ); - indices.push( idx ); - arrays.push( arr ); - return ( z > 0.0 ); - } -}); From 38069db3de1c806007966804a24cc44c2322dc19 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 7 Jan 2025 03:15:18 +0000 Subject: [PATCH 21/35] Transform error messages --- lib/main.js | 12 ++++++------ package.json | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/main.js b/lib/main.js index 6ad824e..3cd50e0 100644 --- a/lib/main.js +++ b/lib/main.js @@ -33,7 +33,7 @@ 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' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -91,7 +91,7 @@ function filter( x, options, predicate, thisArg ) { var v; var i; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray-like object. Value: `%s`.', x ) ); + throw new TypeError( format( 'null5t', x ) ); } if ( arguments.length < 3 ) { clbk = options; @@ -111,11 +111,11 @@ function filter( x, options, predicate, thisArg ) { ctx = thisArg; } if ( !isFunction( clbk ) ) { - throw new TypeError( format( 'invalid argument. Callback argument must be a function. Value: `%s`.', clbk ) ); + throw new TypeError( format( 'null2b', clbk ) ); } if ( hasOpts ) { if ( !isPlainObject( opts ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) ); + throw new TypeError( format( 'null2V', opts ) ); } if ( hasOwnProp( opts, 'dtype' ) ) { dt = opts.dtype; @@ -124,7 +124,7 @@ function filter( x, options, predicate, thisArg ) { } 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 ) ); + throw new TypeError( format( 'null5C', 'order', opts.order ) ); } ord = opts.order; } @@ -135,7 +135,7 @@ function filter( x, options, predicate, thisArg ) { 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 ) ); + throw new TypeError( format( 'nullBf', 'dtype', opts.dtype ) ); } // Resolve the iteration order: if ( ord === void 0 ) { diff --git a/package.json b/package.json index 22065aa..a44b313 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@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/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From 57319ea3cbc3d0602dedb47dbbad85cc7e06292c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 7 Jan 2025 03:17:27 +0000 Subject: [PATCH 22/35] Remove files --- index.d.ts | 1612 ---------------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 6459 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 7f6ff4a..0000000 --- a/index.d.ts +++ /dev/null @@ -1,1612 +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. -*/ - -// TypeScript Version: 4.1 - -/// - -/* eslint-disable max-lines */ - -import { typedndarray, DataType, Order, float64ndarray, float32ndarray, complex128ndarray, complex64ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, boolndarray, genericndarray } from '@stdlib/types/ndarray'; -import { Complex64, Complex128 } from '@stdlib/types/complex'; - -/** -* Returns a boolean indicating whether an element passes a test. -* -* @returns boolean indicating whether an element passes a test -*/ -type Nullary = ( this: V ) => boolean; - -/** -* Returns a boolean indicating whether an element passes a test. -* -* @param value - current array element -* @returns boolean indicating whether an element passes a test -*/ -type Unary = ( this: V, value: T ) => boolean; - -/** -* Returns a boolean indicating whether an element passes a test. -* -* @param value - current array element -* @param indices - current array element indices -* @returns boolean indicating whether an element passes a test -*/ -type Binary = ( this: V, value: T, indices: Array ) => boolean; - -/** -* Returns a boolean indicating whether an element passes a test. -* -* @param value - current array element -* @param indices - current array element indices -* @param arr - input array -* @returns boolean indicating whether an element passes a test -*/ -type Ternary = ( this: V, value: T, indices: Array, arr: typedndarray ) => boolean; - -/** -* Returns a boolean indicating whether an element passes a test. -* -* @param value - current array element -* @param indices - current array element indices -* @param arr - input array -* @returns boolean indicating whether an element passes a test -*/ -type Predicate = Nullary | Unary | Binary | Ternary; - -/** -* Interface describing "base" function options. -*/ -interface BaseOptions { - /** - * Index iteration order. - * - * ## Notes - * - * - By default, the function iterates over elements according to the layout order of the provided ndarray. Accordingly, for row-major input ndarrays, the last dimension indices increment fastest. For column-major input ndarrays, the first dimension indices increment fastest. To override the inferred order and ensure that indices increment in a specific manner, regardless of the input ndarray's layout order, explicitly set the iteration order. Note, however, that iterating according to an order which does not match that of the input ndarray may, in some circumstances, result in performance degradation due to cache misses. - */ - order?: Order; -} - -/** -* Interface describing function options. -*/ -interface OrderOptions { - /** - * Index iteration order. - * - * ## Notes - * - * - By default, the function iterates over elements according to the layout order of the provided ndarray. Accordingly, for row-major input ndarrays, the last dimension indices increment fastest. For column-major input ndarrays, the first dimension indices increment fastest. To override the inferred order and ensure that indices increment in a specific manner, regardless of the input ndarray's layout order, explicitly set the iteration order. Note, however, that iterating according to an order which does not match that of the input ndarray may, in some circumstances, result in performance degradation due to cache misses. - */ - order: Order; -} - -/** -* Interface describing function options. -*/ -interface Options extends BaseOptions { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: DataType; -} - -/** -* Interface describing function options. -*/ -interface Float64Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'float64'; -} - -/** -* Interface describing function options. -*/ -interface Float32Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'float32'; -} - -/** -* Interface describing function options. -*/ -interface Complex128Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'complex128'; -} - -/** -* Interface describing function options. -*/ -interface Complex64Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'complex64'; -} - -/** -* Interface describing function options. -*/ -interface Int32Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'int32'; -} - -/** -* Interface describing function options. -*/ -interface Int16Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'int16'; -} - -/** -* Interface describing function options. -*/ -interface Int8Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'int8'; -} - -/** -* Interface describing function options. -*/ -interface Uint32Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'uint32'; -} - -/** -* Interface describing function options. -*/ -interface Uint16Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'uint16'; -} - -/** -* Interface describing function options. -*/ -interface Uint8Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'uint8'; -} - -/** -* Interface describing function options. -*/ -interface Uint8COptions extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'uint8c'; -} - -/** -* Interface describing function options. -*/ -interface BoolOptions extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'bool'; -} - -/** -* Interface describing function options. -*/ -interface GenericOptions extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'generic'; -} - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: float64ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): float64ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float32Array = require( '@stdlib/array-float32' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Float32Array( [ 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( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: float32ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): float32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var Complex64Array = require( '@stdlib/array-complex64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* function predicate( z, idx ) { -* return idx[ 0 ] > 0; -* } -* -* var buffer = new Complex64Array( [ 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 = [ 3, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, predicate ); -* // returns -*/ -declare function filter( x: complex64ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): complex64ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* function predicate( z, idx ) { -* return idx[ 0 ] > 0; -* } -* -* var buffer = new Complex128Array( [ 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 = [ 3, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, predicate ); -* // returns -*/ -declare function filter( x: complex128ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): complex128ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Int32Array = require( '@stdlib/array-int32' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Int32Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: int32ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): int32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Int16Array = require( '@stdlib/array-int16' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Int16Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: int16ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): int16ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Int8Array = require( '@stdlib/array-int8' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Int8Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: int8ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): int8ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint32Array = require( '@stdlib/array-uint32' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint32Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint32ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): uint32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint16Array = require( '@stdlib/array-uint16' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint16Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint16ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): uint16ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint8Array = require( '@stdlib/array-uint8' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint8Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint8ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): uint8ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint8ClampedArray( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint8cndarray, predicate: Predicate, thisArg?: ThisParameterType> ): uint8cndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var BooleanArray = require( '@stdlib/array-bool' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* function predicate( z ) { -* return z; -* } -* -* var buffer = new BooleanArray( [ false, true, false, true, false, true, false, true, false, true, false, true ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'bool', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, predicate ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ true, true, true, true ] -*/ -declare function filter( x: boolndarray, predicate: Predicate, thisArg?: ThisParameterType> ): boolndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 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( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: genericndarray, predicate: Predicate, thisArg?: ThisParameterType> ): genericndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: float64ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): float64ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float32Array = require( '@stdlib/array-float32' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Float32Array( [ 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( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: float32ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): float32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var Complex64Array = require( '@stdlib/array-complex64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* function predicate( z, idx ) { -* return idx[ 0 ] > 0; -* } -* -* var buffer = new Complex64Array( [ 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 = [ 3, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, predicate ); -* // returns -*/ -declare function filter( x: complex64ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): complex64ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* function predicate( z, idx ) { -* return idx[ 0 ] > 0; -* } -* -* var buffer = new Complex128Array( [ 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 = [ 3, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, predicate ); -* // returns -*/ -declare function filter( x: complex128ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): complex128ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Int32Array = require( '@stdlib/array-int32' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Int32Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: int32ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): int32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Int16Array = require( '@stdlib/array-int16' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Int16Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: int16ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): int16ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Int8Array = require( '@stdlib/array-int8' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Int8Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: int8ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): int8ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint32Array = require( '@stdlib/array-uint32' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint32Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint32ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): uint32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint16Array = require( '@stdlib/array-uint16' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint16Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint16ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): uint16ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint8Array = require( '@stdlib/array-uint8' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint8Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint8ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): uint8ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint8ClampedArray( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint8cndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): uint8cndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var BooleanArray = require( '@stdlib/array-bool' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* function predicate( z ) { -* return z; -* } -* -* var buffer = new BooleanArray( [ false, true, false, true, false, true, false, true, false, true, false, true ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'bool', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, predicate ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ true, true, true, true ] -*/ -declare function filter( x: boolndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): boolndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 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( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: genericndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): genericndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'float64' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: typedndarray, options: Float64Options, predicate: Predicate, thisArg?: ThisParameterType> ): float64ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'float32' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: typedndarray, options: Float32Options, predicate: Predicate, thisArg?: ThisParameterType> ): float32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* function predicate( z, idx ) { -* return idx[ 0 ] > 0; -* } -* -* var buffer = new Complex128Array( [ 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 = [ 3, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'dtype': 'complex128' -* }; -* var y = filter( x, opts, predicate ); -* // returns -*/ -declare function filter( x: typedndarray, options: Complex128Options, predicate: Predicate, thisArg?: ThisParameterType> ): complex128ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* function predicate( z, idx ) { -* return idx[ 0 ] > 0; -* } -* -* var buffer = new Complex128Array( [ 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 = [ 3, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'dtype': 'complex64' -* }; -* var y = filter( x, opts, predicate ); -* // returns -*/ -declare function filter( x: typedndarray, options: Complex64Options, predicate: Predicate, thisArg?: ThisParameterType> ): complex64ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'int32' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: typedndarray, options: Int32Options, predicate: Predicate, thisArg?: ThisParameterType> ): int32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'int16' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: typedndarray, options: Int16Options, predicate: Predicate, thisArg?: ThisParameterType> ): int16ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'int8' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: typedndarray, options: Int8Options, predicate: Predicate, thisArg?: ThisParameterType> ): int8ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'uint32' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: typedndarray, options: Uint32Options, predicate: Predicate, thisArg?: ThisParameterType> ): uint32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'uint16' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: typedndarray, options: Uint16Options, predicate: Predicate, thisArg?: ThisParameterType> ): uint16ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'uint8' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: typedndarray, options: Uint8Options, predicate: Predicate, thisArg?: ThisParameterType> ): uint8ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'uint8c' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: typedndarray, options: Uint8COptions, predicate: Predicate, thisArg?: ThisParameterType> ): uint8cndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'bool' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ true, true, true, true ] -*/ -declare function filter( x: typedndarray, options: BoolOptions, predicate: Predicate, thisArg?: ThisParameterType> ): boolndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'generic' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: typedndarray, options: GenericOptions, predicate: Predicate, thisArg?: ThisParameterType> ): genericndarray; - - -// EXPORTS // - -export = filter; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 483f25f..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import 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)),D=v.get.apply(v,B),w.call(T,D,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 deleted file mode 100644 index 2c1ae93..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 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* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate 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 {boolean} [options.order] - index iteration order\n* @param {Callback} predicate - predicate function\n* @param {*} [thisArg] - predicate 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 { isPrimitive as isEven } from '@stdlib/assert-is-even';\n* import Float64Array from '@stdlib/array-float64';\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndarray2array from '@stdlib/ndarray-to-array';\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 = filter( x, isEven );\n* // returns \n*\n* var arr = ndarray2array( y );\n* // returns [ 2.0, 4.0, 8.0, 10.0 ]\n*/\nfunction filter( x, options, predicate, 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 = predicate;\n\t\t} else {\n\t\t\thasOpts = true;\n\t\t\topts = options;\n\t\t\tclbk = predicate;\n\t\t}\n\t} else {\n\t\thasOpts = true;\n\t\topts = options;\n\t\tclbk = predicate;\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 predicate 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 elements according to a predicate 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 = x.get.apply( x, idx );\n\t\tif ( clbk.call( ctx, v, idx.slice(), x ) ) {\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 filter;\n"],"names":["filter","x","options","predicate","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","get","apply","call","slice","gcopy","constructor"],"mappings":";;6zCA0EA,SAASA,EAAQC,EAAGC,EAASC,EAAWC,GACvC,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,IAE9CK,EAAIlB,EAAEsC,IAAIC,MAAOvC,EAAGa,GACfN,EAAKiC,KAAM9B,EAAKQ,EAAGL,EAAI4B,QAASzC,KACpCM,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/stats.html b/stats.html deleted file mode 100644 index 135eeac..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Codestin Search App - - - -
- - - - - From fdce7f639b94833cfe0a8d69030175f72b0e21d3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 7 Jan 2025 03:18:10 +0000 Subject: [PATCH 23/35] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 57 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 79 +- SECURITY.md | 5 - benchmark/benchmark.1d.js | 150 - benchmark/benchmark.2d.js | 161 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 51 - docs/types/test.ts | 195 - examples/index.js | 38 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 55 - lib/main.js | 196 - package.json | 84 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 892 ---- 44 files changed, 4885 insertions(+), 5325 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.1d.js delete mode 100644 benchmark/benchmark.2d.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0779e8a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 03a0613..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) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 48af73a..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) 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 443f7ec..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: '9 21 * * 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 + + ```
@@ -257,7 +248,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]. @@ -320,21 +311,21 @@ Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-filter/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-map]: https://github.com/stdlib-js/ndarray-filter-map +[@stdlib/ndarray/filter-map]: https://github.com/stdlib-js/ndarray-filter-map/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 6958f29..0000000 --- a/benchmark/benchmark.1d.js +++ /dev/null @@ -1,150 +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 filter = require( './../lib' ); - - -// VARIABLES // - -var xtypes = [ 'generic' ]; -var ytypes = [ 'float64' ]; -var orders = [ 'row-major', 'column-major' ]; - - -// FUNCTIONS // - -/** -* Predicate function. -* -* @private -* @param {number} value - array element -* @param {NonNegativeIntegerArray} indices - element indices -* @param {ndarray} arr - input array -* @returns {boolean} result -*/ -function predicate( value ) { - return value > 0.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 = filter( x, opts, predicate ); - 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 c70a9f1..0000000 --- a/benchmark/benchmark.2d.js +++ /dev/null @@ -1,161 +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 filter = require( './../lib' ); - - -// VARIABLES // - -var xtypes = [ 'generic' ]; -var ytypes = [ 'float64' ]; -var orders = [ 'row-major', 'column-major' ]; - - -// FUNCTIONS // - -/** -* Predicate function. -* -* @private -* @param {number} value - array element -* @param {NonNegativeIntegerArray} indices - element indices -* @param {ndarray} arr - input array -* @returns {boolean} result -*/ -function predicate( value ) { - return value > 0.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 = filter( x, opts, predicate ); - 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 51e4f91..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" -%% click B href "https://github.com/stdlib-js/ndarray-filter/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-filter/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-filter/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-filter/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-filter/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/filter -[production-url]: https://github.com/stdlib-js/ndarray-filter/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-filter/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-filter/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-filter/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-filter/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-filter/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-filter/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 aafb9cb..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import filter from '../docs/types/index'; -export = filter; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index b5b2378..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(J,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"),N=require("@stdlib/ndarray-base-numel"),S=require("@stdlib/ndarray-base-next-cartesian-index").assign,A=require("@stdlib/blas-base-gcopy"),v=require("@stdlib/string-format");function B(r,a,g,k){var f,p,t,i,e,c,m,n,h,u,y,s,l,o,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=g):(f=!0,e=a,i=g):(f=!0,e=a,i=g,m=k),!b(i))throw new TypeError(v("invalid argument. Callback argument must be a function. Value: `%s`.",i));if(f){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(c=P(s),c===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),o=N(l),p=l.length,n==="row-major"?h=p-1:h=0,u=D(p),t={length:0},d=0;d0&&(u=S(l,n,u,h,u)),q=r.get.apply(r,u),i.call(m,q,u.slice(),r)&&(t[t.length]=q,t.length+=1);return o=t.length,y=new c(o),A(o,t,1,y,1),w=new r.constructor(s,y,[o],[1],0,n),w}E.exports=B});var G=j();module.exports=G; -/** -* @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 cfadd98..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* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate 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 {boolean} [options.order] - index iteration order\n* @param {Callback} predicate - predicate function\n* @param {*} [thisArg] - predicate 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 isEven = require( '@stdlib/assert-is-even' ).isPrimitive;\n* var Float64Array = require( '@stdlib/array-float64' );\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\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 = filter( x, isEven );\n* // returns \n*\n* var arr = ndarray2array( y );\n* // returns [ 2.0, 4.0, 8.0, 10.0 ]\n*/\nfunction filter( x, options, predicate, 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 = predicate;\n\t\t} else {\n\t\t\thasOpts = true;\n\t\t\topts = options;\n\t\t\tclbk = predicate;\n\t\t}\n\t} else {\n\t\thasOpts = true;\n\t\topts = options;\n\t\tclbk = predicate;\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 predicate 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 elements according to a predicate 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 = x.get.apply( x, idx );\n\t\tif ( clbk.call( ctx, v, idx.slice(), x ) ) {\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 = filter;\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* Return a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function.\n*\n* @module @stdlib/ndarray-filter\n*\n* @example\n* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive;\n* var Float64Array = require( '@stdlib/array-float64' );\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var filter = require( '@stdlib/ndarray-filter' );\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 = filter( x, isEven );\n* // returns \n*\n* var arr = ndarray2array( y );\n* // returns [ 2.0, 4.0, 8.0, 10.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,EAuC9C,SAASC,EAAQC,EAAGC,EAASC,EAAWC,EAAU,CACjD,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,EAAInB,EAAE,IAAI,MAAOA,EAAGa,CAAI,EACnBN,EAAK,KAAMG,EAAKS,EAAGN,EAAI,MAAM,EAAGb,CAAE,IACtCM,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", "filter", "x", "options", "predicate", "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 75de7ed..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,51 +0,0 @@ - -{{alias}}( x[, options], predicate[, thisArg] ) - Returns a shallow copy of an ndarray containing only those elements which - pass a test implemented by a predicate function. - - The predicate function is provided the following arguments: - - - value: current array element. - - indices: current array element indices. - - arr: the input 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'. - - predicate: Function - Predicate function. - - thisArg: any (optional) - Predicate function execution context. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ); - > function f( v ) { return v > 2.0; }; - > var y = {{alias}}( x, f ); - > {{alias:@stdlib/ndarray/to-array}}( y ) - [ 3.0, 4.0 ] - - See Also - -------- diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 046dffb..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,195 +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 empty = require( '@stdlib/ndarray-base-empty' ); -import zeros = require( '@stdlib/ndarray-base-zeros' ); -import filter = require( './index' ); - -/** -* Predicate function. -* -* @param x - input value -* @returns result -*/ -function predicate( x: any ): boolean { - return Boolean( x ); -} - -// The function returns an ndarray... -{ - const sh = [ 2, 2 ]; - const ord = 'row-major'; - - filter( zeros( 'float64', sh, ord ), predicate ); // $ExpectType float64ndarray - filter( zeros( 'float64', sh, ord ), predicate, {} ); // $ExpectType float64ndarray - filter( zeros( 'float32', sh, ord ), predicate ); // $ExpectType float32ndarray - filter( zeros( 'float32', sh, ord ), predicate, {} ); // $ExpectType float32ndarray - filter( zeros( 'complex64', sh, ord ), predicate ); // $ExpectType complex64ndarray - filter( zeros( 'complex64', sh, ord ), predicate, {} ); // $ExpectType complex64ndarray - filter( zeros( 'complex128', sh, ord ), predicate ); // $ExpectType complex128ndarray - filter( zeros( 'complex128', sh, ord ), predicate, {} ); // $ExpectType complex128ndarray - filter( zeros( 'int32', sh, ord ), predicate ); // $ExpectType int32ndarray - filter( zeros( 'int32', sh, ord ), predicate, {} ); // $ExpectType int32ndarray - filter( zeros( 'int16', sh, ord ), predicate ); // $ExpectType int16ndarray - filter( zeros( 'int16', sh, ord ), predicate, {} ); // $ExpectType int16ndarray - filter( zeros( 'int8', sh, ord ), predicate ); // $ExpectType int8ndarray - filter( zeros( 'int8', sh, ord ), predicate, {} ); // $ExpectType int8ndarray - filter( zeros( 'uint32', sh, ord ), predicate ); // $ExpectType uint32ndarray - filter( zeros( 'uint32', sh, ord ), predicate, {} ); // $ExpectType uint32ndarray - filter( zeros( 'uint16', sh, ord ), predicate ); // $ExpectType uint16ndarray - filter( zeros( 'uint16', sh, ord ), predicate, {} ); // $ExpectType uint16ndarray - filter( zeros( 'uint8', sh, ord ), predicate ); // $ExpectType uint8ndarray - filter( zeros( 'uint8', sh, ord ), predicate, {} ); // $ExpectType uint8ndarray - filter( zeros( 'uint8c', sh, ord ), predicate ); // $ExpectType uint8cndarray - filter( zeros( 'uint8c', sh, ord ), predicate, {} ); // $ExpectType uint8cndarray - filter( empty( 'bool', sh, ord ), predicate ); // $ExpectType boolndarray - filter( empty( 'bool', sh, ord ), predicate, {} ); // $ExpectType boolndarray - filter( zeros( 'generic', sh, ord ), predicate ); // $ExpectType genericndarray - filter( zeros( 'generic', sh, ord ), predicate, {} ); // $ExpectType genericndarray - - - filter( zeros( 'generic', sh, ord ), { 'dtype': 'float64' }, predicate ); // $ExpectType float64ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'float64' }, predicate, {} ); // $ExpectType float64ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'float32' }, predicate ); // $ExpectType float32ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'float32' }, predicate, {} ); // $ExpectType float32ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'complex64' }, predicate ); // $ExpectType complex64ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'complex64' }, predicate, {} ); // $ExpectType complex64ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'complex128' }, predicate ); // $ExpectType complex128ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'complex128' }, predicate, {} ); // $ExpectType complex128ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'int32' }, predicate ); // $ExpectType int32ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'int32' }, predicate, {} ); // $ExpectType int32ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'int16' }, predicate ); // $ExpectType int16ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'int16' }, predicate, {} ); // $ExpectType int16ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'int8' }, predicate ); // $ExpectType int8ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'int8' }, predicate, {} ); // $ExpectType int8ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint32' }, predicate ); // $ExpectType uint32ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint32' }, predicate, {} ); // $ExpectType uint32ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint16' }, predicate ); // $ExpectType uint16ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint16' }, predicate, {} ); // $ExpectType uint16ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint8' }, predicate ); // $ExpectType uint8ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint8' }, predicate, {} ); // $ExpectType uint8ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint8c' }, predicate ); // $ExpectType uint8cndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint8c' }, predicate, {} ); // $ExpectType uint8cndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'bool' }, predicate ); // $ExpectType boolndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'bool' }, predicate, {} ); // $ExpectType boolndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'generic' }, predicate ); // $ExpectType genericndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'generic' }, predicate, {} ); // $ExpectType genericndarray - - - filter( zeros( 'float64', sh, ord ), { 'order': ord }, predicate ); // $ExpectType float64ndarray - filter( zeros( 'float64', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType float64ndarray - filter( zeros( 'float32', sh, ord ), { 'order': ord }, predicate ); // $ExpectType float32ndarray - filter( zeros( 'float32', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType float32ndarray - filter( zeros( 'complex64', sh, ord ), { 'order': ord }, predicate ); // $ExpectType complex64ndarray - filter( zeros( 'complex64', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType complex64ndarray - filter( zeros( 'complex128', sh, ord ), { 'order': ord }, predicate ); // $ExpectType complex128ndarray - filter( zeros( 'complex128', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType complex128ndarray - filter( zeros( 'int32', sh, ord ), { 'order': ord }, predicate ); // $ExpectType int32ndarray - filter( zeros( 'int32', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType int32ndarray - filter( zeros( 'int16', sh, ord ), { 'order': ord }, predicate ); // $ExpectType int16ndarray - filter( zeros( 'int16', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType int16ndarray - filter( zeros( 'int8', sh, ord ), { 'order': ord }, predicate ); // $ExpectType int8ndarray - filter( zeros( 'int8', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType int8ndarray - filter( zeros( 'uint32', sh, ord ), { 'order': ord }, predicate ); // $ExpectType uint32ndarray - filter( zeros( 'uint32', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType uint32ndarray - filter( zeros( 'uint16', sh, ord ), { 'order': ord }, predicate ); // $ExpectType uint16ndarray - filter( zeros( 'uint16', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType uint16ndarray - filter( zeros( 'uint8', sh, ord ), { 'order': ord }, predicate ); // $ExpectType uint8ndarray - filter( zeros( 'uint8', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType uint8ndarray - filter( zeros( 'uint8c', sh, ord ), { 'order': ord }, predicate ); // $ExpectType uint8cndarray - filter( zeros( 'uint8c', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType uint8cndarray - filter( empty( 'bool', sh, ord ), { 'order': ord }, predicate ); // $ExpectType boolndarray - filter( empty( 'bool', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType boolndarray - filter( zeros( 'generic', sh, ord ), { 'order': ord }, predicate ); // $ExpectType genericndarray - filter( zeros( 'generic', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType genericndarray - -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - filter( 5, predicate ); // $ExpectError - filter( true, predicate ); // $ExpectError - filter( false, predicate ); // $ExpectError - filter( null, predicate ); // $ExpectError - filter( undefined, predicate ); // $ExpectError - filter( {}, predicate ); // $ExpectError - filter( [ 1 ], predicate ); // $ExpectError - filter( ( x: number ): number => x, predicate ); // $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' ); - - filter( x, '5' ); // $ExpectError - filter( x, true ); // $ExpectError - filter( x, false ); // $ExpectError - filter( x, null ); // $ExpectError - filter( x, undefined ); // $ExpectError - filter( x, {} ); // $ExpectError - filter( 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' ); - - filter( x, '10', predicate, {} ); // $ExpectError - filter( x, 10, predicate, {} ); // $ExpectError - filter( x, false, predicate, {} ); // $ExpectError - filter( x, true, predicate, {} ); // $ExpectError - filter( x, [], predicate, {} ); // $ExpectError - filter( x, ( x: number ): number => x, predicate, {} ); // $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' ); - - filter( x, { 'dtype': '10' }, predicate ); // $ExpectError - filter( x, { 'dtype': 10 }, predicate ); // $ExpectError - filter( x, { 'dtype': null }, predicate ); // $ExpectError - filter( x, { 'dtype': false }, predicate ); // $ExpectError - filter( x, { 'dtype': true }, predicate ); // $ExpectError - filter( x, { 'dtype': [] }, predicate ); // $ExpectError - filter( x, { 'dtype': {} }, predicate ); // $ExpectError - filter( x, { 'dtype': ( x: number ): number => x }, predicate ); // $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' ); - - filter( x, { 'order': '10' }, predicate ); // $ExpectError - filter( x, { 'order': 10 }, predicate ); // $ExpectError - filter( x, { 'order': null }, predicate ); // $ExpectError - filter( x, { 'order': false }, predicate ); // $ExpectError - filter( x, { 'order': true }, predicate ); // $ExpectError - filter( x, { 'order': [] }, predicate ); // $ExpectError - filter( x, { 'order': {} }, predicate ); // $ExpectError - filter( x, { 'order': ( x: number ): number => x }, predicate ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - filter(); // $ExpectError - filter( zeros( 'float64', [ 2, 2 ], 'row-major' ) ); // $ExpectError - filter( 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 e2dd6cb..0000000 --- a/examples/index.js +++ /dev/null @@ -1,38 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var array = require( '@stdlib/ndarray-array' ); -var isPositive = require( '@stdlib/assert-is-positive-number' ).isPrimitive; -var filter = require( './../lib' ); - -var buffer = discreteUniform( 10, -100, 100, { - 'dtype': 'generic' -}); -var x = array( buffer, { - 'shape': [ 5, 2 ], - 'dtype': 'generic' -}); -console.log( ndarray2array( x ) ); - -var y = filter( x, naryFunction( isPositive, 1 ) ); -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 c4dadbe..7f6ff4a 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..483f25f --- /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)),D=v.get.apply(v,B),w.call(T,D,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..2c1ae93 --- /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* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate 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 {boolean} [options.order] - index iteration order\n* @param {Callback} predicate - predicate function\n* @param {*} [thisArg] - predicate 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 { isPrimitive as isEven } from '@stdlib/assert-is-even';\n* import Float64Array from '@stdlib/array-float64';\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndarray2array from '@stdlib/ndarray-to-array';\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 = filter( x, isEven );\n* // returns \n*\n* var arr = ndarray2array( y );\n* // returns [ 2.0, 4.0, 8.0, 10.0 ]\n*/\nfunction filter( x, options, predicate, 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 = predicate;\n\t\t} else {\n\t\t\thasOpts = true;\n\t\t\topts = options;\n\t\t\tclbk = predicate;\n\t\t}\n\t} else {\n\t\thasOpts = true;\n\t\topts = options;\n\t\tclbk = predicate;\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 predicate 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 elements according to a predicate 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 = x.get.apply( x, idx );\n\t\tif ( clbk.call( ctx, v, idx.slice(), x ) ) {\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 filter;\n"],"names":["filter","x","options","predicate","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","get","apply","call","slice","gcopy","constructor"],"mappings":";;6zCA0EA,SAASA,EAAQC,EAAGC,EAASC,EAAWC,GACvC,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,IAE9CK,EAAIlB,EAAEsC,IAAIC,MAAOvC,EAAGa,GACfN,EAAKiC,KAAM9B,EAAKQ,EAAGL,EAAI4B,QAASzC,KACpCM,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 46f5998..0000000 --- a/lib/index.js +++ /dev/null @@ -1,55 +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'; - -/** -* Return a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @module @stdlib/ndarray-filter -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var filter = require( '@stdlib/ndarray-filter' ); -* -* 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 = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.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 3cd50e0..0000000 --- a/lib/main.js +++ /dev/null @@ -1,196 +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/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param {ndarray} x - input ndarray -* @param {Options} [options] - function options -* @param {string} [options.dtype] - output array data type -* @param {boolean} [options.order] - index iteration order -* @param {Callback} predicate - predicate function -* @param {*} [thisArg] - predicate 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 isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -function filter( x, options, predicate, 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( 'null5t', x ) ); - } - if ( arguments.length < 3 ) { - clbk = options; - } else if ( arguments.length === 3 ) { - if ( isFunction( options ) ) { - clbk = options; - ctx = predicate; - } else { - hasOpts = true; - opts = options; - clbk = predicate; - } - } else { - hasOpts = true; - opts = options; - clbk = predicate; - ctx = thisArg; - } - if ( !isFunction( clbk ) ) { - throw new TypeError( format( 'null2b', clbk ) ); - } - if ( hasOpts ) { - if ( !isPlainObject( opts ) ) { - throw new TypeError( format( 'null2V', opts ) ); - } - if ( hasOwnProp( opts, 'dtype' ) ) { - dt = opts.dtype; - } else { - dt = getDType( x ); - } - if ( hasOwnProp( opts, 'order' ) ) { - if ( !isOrder( opts.order ) ) { - throw new TypeError( format( 'null5C', '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( 'nullBf', '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 predicate 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 elements according to a predicate function... - for ( i = 0; i < N; i++ ) { - if ( i > 0 ) { - idx = nextCartesianIndex( sh, ord, idx, dim, idx ); - } - v = x.get.apply( x, idx ); - if ( clbk.call( ctx, v, idx.slice(), x ) ) { - 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 = filter; diff --git a/package.json b/package.json index a44b313..2473eda 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Return a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate 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,62 +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/error-tools-fmtprodmsg": "^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-positive-number": "^0.2.2", - "@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", - "@stdlib/utils-nary-function": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "strided", @@ -104,7 +25,6 @@ "select", "take" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..135eeac --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Codestin Search App + + + +
+ + + + + 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 3bea6b3..0000000 --- a/test/test.js +++ /dev/null @@ -1,892 +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 filter = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof filter, '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() { - filter( value, predicate ); - }; - } - - function predicate( z ) { - return ( z > 0.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() { - filter( 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() { - filter( 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() { - filter( x, value, predicate ); - }; - } - - function predicate( z ) { - return ( z > 0.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 - }; - filter( x, opts, predicate ); - }; - } - - function predicate( z ) { - return ( z > 0.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 - }; - filter( x, opts, predicate ); - }; - } - - function predicate( z ) { - return ( z > 0.0 ); - } -}); - -tape( 'the function filters an array according to a predicate 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 = filter( x, predicate ); - - expected = new Float64Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - - t.end(); - - function predicate( z ) { - return ( z > 0.0 ); - } -}); - -tape( 'the function filters an array according to a predicate 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 = filter( x, predicate ); - - expected = new Float64Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - - t.end(); - - function predicate( z ) { - return ( z > 0.0 ); - } -}); - -tape( 'the function filters an array according to a predicate 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 = filter( x, opts, predicate ); - - expected = new Float64Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - - opts = { - 'dtype': 'float32' - }; - y = filter( x, opts, predicate ); - - expected = new Float32Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat32Array( y.data, expected ), true, 'returns expected value' ); - - t.end(); - - function predicate( z ) { - return ( z > 0.0 ); - } -}); - -tape( 'the function filters an array according to a predicate 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 = filter( x, opts, predicate ); - - expected = new Float64Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - - opts = { - 'dtype': 'float32' - }; - y = filter( x, opts, predicate ); - - expected = new Float32Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat32Array( y.data, expected ), true, 'returns expected value' ); - - t.end(); - - function predicate( z ) { - return ( z > 0.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 = filter( x, predicate, ctx ); - - expected = new Float64Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function predicate( z ) { - this.count += 1; // eslint-disable-line no-invalid-this - return ( z > 0.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 = filter( x, {}, predicate, ctx ); - - expected = new Float64Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function predicate( z ) { - this.count += 1; // eslint-disable-line no-invalid-this - return ( z > 0.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 = filter( x, predicate ); - - expected = new Float64Array([ - 1.0, - 3.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 predicate( z, idx, arr ) { - values.push( z ); - indices.push( idx ); - arrays.push( arr ); - return ( z > 0.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 = filter( x, predicate ); - - expected = new Float64Array([ - 1.0, - 3.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 predicate( z, idx, arr ) { - values.push( z ); - indices.push( idx ); - arrays.push( arr ); - return ( z > 0.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 = filter( x, opts, predicate ); - - expected = new Float64Array([ - 1.0, - 3.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 predicate( z, idx, arr ) { - values.push( z ); - indices.push( idx ); - arrays.push( arr ); - return ( z > 0.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 = filter( x, opts, predicate ); - - expected = new Float64Array([ - 1.0, - 3.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 predicate( z, idx, arr ) { - values.push( z ); - indices.push( idx ); - arrays.push( arr ); - return ( z > 0.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 = filter( x, opts, predicate ); - - expected = new Float64Array([ - 1.0, - 3.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 predicate( z, idx, arr ) { - values.push( z ); - indices.push( idx ); - arrays.push( arr ); - return ( z > 0.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 = filter( x, opts, predicate ); - - expected = new Float64Array([ - 1.0, - 3.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 predicate( z, idx, arr ) { - values.push( z ); - indices.push( idx ); - arrays.push( arr ); - return ( z > 0.0 ); - } -}); From 2f91165464172ea029ab3e67e54ab4fb0f4ba048 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 13 Jan 2025 02:29:49 +0000 Subject: [PATCH 24/35] Transform error messages --- lib/main.js | 12 ++++++------ package.json | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/main.js b/lib/main.js index 6ad824e..3cd50e0 100644 --- a/lib/main.js +++ b/lib/main.js @@ -33,7 +33,7 @@ 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' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -91,7 +91,7 @@ function filter( x, options, predicate, thisArg ) { var v; var i; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray-like object. Value: `%s`.', x ) ); + throw new TypeError( format( 'null5t', x ) ); } if ( arguments.length < 3 ) { clbk = options; @@ -111,11 +111,11 @@ function filter( x, options, predicate, thisArg ) { ctx = thisArg; } if ( !isFunction( clbk ) ) { - throw new TypeError( format( 'invalid argument. Callback argument must be a function. Value: `%s`.', clbk ) ); + throw new TypeError( format( 'null2b', clbk ) ); } if ( hasOpts ) { if ( !isPlainObject( opts ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) ); + throw new TypeError( format( 'null2V', opts ) ); } if ( hasOwnProp( opts, 'dtype' ) ) { dt = opts.dtype; @@ -124,7 +124,7 @@ function filter( x, options, predicate, thisArg ) { } 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 ) ); + throw new TypeError( format( 'null5C', 'order', opts.order ) ); } ord = opts.order; } @@ -135,7 +135,7 @@ function filter( x, options, predicate, thisArg ) { 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 ) ); + throw new TypeError( format( 'nullBf', 'dtype', opts.dtype ) ); } // Resolve the iteration order: if ( ord === void 0 ) { diff --git a/package.json b/package.json index 22065aa..a44b313 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@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/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From 0b3f22133b7768a0f331d0ede52ff3b03de70c89 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 13 Jan 2025 03:02:49 +0000 Subject: [PATCH 25/35] Remove files --- index.d.ts | 1612 ---------------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 6459 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 7f6ff4a..0000000 --- a/index.d.ts +++ /dev/null @@ -1,1612 +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. -*/ - -// TypeScript Version: 4.1 - -/// - -/* eslint-disable max-lines */ - -import { typedndarray, DataType, Order, float64ndarray, float32ndarray, complex128ndarray, complex64ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, boolndarray, genericndarray } from '@stdlib/types/ndarray'; -import { Complex64, Complex128 } from '@stdlib/types/complex'; - -/** -* Returns a boolean indicating whether an element passes a test. -* -* @returns boolean indicating whether an element passes a test -*/ -type Nullary = ( this: V ) => boolean; - -/** -* Returns a boolean indicating whether an element passes a test. -* -* @param value - current array element -* @returns boolean indicating whether an element passes a test -*/ -type Unary = ( this: V, value: T ) => boolean; - -/** -* Returns a boolean indicating whether an element passes a test. -* -* @param value - current array element -* @param indices - current array element indices -* @returns boolean indicating whether an element passes a test -*/ -type Binary = ( this: V, value: T, indices: Array ) => boolean; - -/** -* Returns a boolean indicating whether an element passes a test. -* -* @param value - current array element -* @param indices - current array element indices -* @param arr - input array -* @returns boolean indicating whether an element passes a test -*/ -type Ternary = ( this: V, value: T, indices: Array, arr: typedndarray ) => boolean; - -/** -* Returns a boolean indicating whether an element passes a test. -* -* @param value - current array element -* @param indices - current array element indices -* @param arr - input array -* @returns boolean indicating whether an element passes a test -*/ -type Predicate = Nullary | Unary | Binary | Ternary; - -/** -* Interface describing "base" function options. -*/ -interface BaseOptions { - /** - * Index iteration order. - * - * ## Notes - * - * - By default, the function iterates over elements according to the layout order of the provided ndarray. Accordingly, for row-major input ndarrays, the last dimension indices increment fastest. For column-major input ndarrays, the first dimension indices increment fastest. To override the inferred order and ensure that indices increment in a specific manner, regardless of the input ndarray's layout order, explicitly set the iteration order. Note, however, that iterating according to an order which does not match that of the input ndarray may, in some circumstances, result in performance degradation due to cache misses. - */ - order?: Order; -} - -/** -* Interface describing function options. -*/ -interface OrderOptions { - /** - * Index iteration order. - * - * ## Notes - * - * - By default, the function iterates over elements according to the layout order of the provided ndarray. Accordingly, for row-major input ndarrays, the last dimension indices increment fastest. For column-major input ndarrays, the first dimension indices increment fastest. To override the inferred order and ensure that indices increment in a specific manner, regardless of the input ndarray's layout order, explicitly set the iteration order. Note, however, that iterating according to an order which does not match that of the input ndarray may, in some circumstances, result in performance degradation due to cache misses. - */ - order: Order; -} - -/** -* Interface describing function options. -*/ -interface Options extends BaseOptions { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: DataType; -} - -/** -* Interface describing function options. -*/ -interface Float64Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'float64'; -} - -/** -* Interface describing function options. -*/ -interface Float32Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'float32'; -} - -/** -* Interface describing function options. -*/ -interface Complex128Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'complex128'; -} - -/** -* Interface describing function options. -*/ -interface Complex64Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'complex64'; -} - -/** -* Interface describing function options. -*/ -interface Int32Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'int32'; -} - -/** -* Interface describing function options. -*/ -interface Int16Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'int16'; -} - -/** -* Interface describing function options. -*/ -interface Int8Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'int8'; -} - -/** -* Interface describing function options. -*/ -interface Uint32Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'uint32'; -} - -/** -* Interface describing function options. -*/ -interface Uint16Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'uint16'; -} - -/** -* Interface describing function options. -*/ -interface Uint8Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'uint8'; -} - -/** -* Interface describing function options. -*/ -interface Uint8COptions extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'uint8c'; -} - -/** -* Interface describing function options. -*/ -interface BoolOptions extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'bool'; -} - -/** -* Interface describing function options. -*/ -interface GenericOptions extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'generic'; -} - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: float64ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): float64ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float32Array = require( '@stdlib/array-float32' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Float32Array( [ 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( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: float32ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): float32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var Complex64Array = require( '@stdlib/array-complex64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* function predicate( z, idx ) { -* return idx[ 0 ] > 0; -* } -* -* var buffer = new Complex64Array( [ 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 = [ 3, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, predicate ); -* // returns -*/ -declare function filter( x: complex64ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): complex64ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* function predicate( z, idx ) { -* return idx[ 0 ] > 0; -* } -* -* var buffer = new Complex128Array( [ 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 = [ 3, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, predicate ); -* // returns -*/ -declare function filter( x: complex128ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): complex128ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Int32Array = require( '@stdlib/array-int32' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Int32Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: int32ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): int32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Int16Array = require( '@stdlib/array-int16' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Int16Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: int16ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): int16ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Int8Array = require( '@stdlib/array-int8' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Int8Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: int8ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): int8ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint32Array = require( '@stdlib/array-uint32' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint32Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint32ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): uint32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint16Array = require( '@stdlib/array-uint16' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint16Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint16ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): uint16ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint8Array = require( '@stdlib/array-uint8' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint8Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint8ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): uint8ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint8ClampedArray( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint8cndarray, predicate: Predicate, thisArg?: ThisParameterType> ): uint8cndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var BooleanArray = require( '@stdlib/array-bool' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* function predicate( z ) { -* return z; -* } -* -* var buffer = new BooleanArray( [ false, true, false, true, false, true, false, true, false, true, false, true ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'bool', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, predicate ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ true, true, true, true ] -*/ -declare function filter( x: boolndarray, predicate: Predicate, thisArg?: ThisParameterType> ): boolndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 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( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: genericndarray, predicate: Predicate, thisArg?: ThisParameterType> ): genericndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: float64ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): float64ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float32Array = require( '@stdlib/array-float32' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Float32Array( [ 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( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: float32ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): float32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var Complex64Array = require( '@stdlib/array-complex64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* function predicate( z, idx ) { -* return idx[ 0 ] > 0; -* } -* -* var buffer = new Complex64Array( [ 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 = [ 3, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, predicate ); -* // returns -*/ -declare function filter( x: complex64ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): complex64ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* function predicate( z, idx ) { -* return idx[ 0 ] > 0; -* } -* -* var buffer = new Complex128Array( [ 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 = [ 3, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, predicate ); -* // returns -*/ -declare function filter( x: complex128ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): complex128ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Int32Array = require( '@stdlib/array-int32' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Int32Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: int32ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): int32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Int16Array = require( '@stdlib/array-int16' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Int16Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: int16ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): int16ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Int8Array = require( '@stdlib/array-int8' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Int8Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: int8ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): int8ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint32Array = require( '@stdlib/array-uint32' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint32Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint32ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): uint32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint16Array = require( '@stdlib/array-uint16' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint16Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint16ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): uint16ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint8Array = require( '@stdlib/array-uint8' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint8Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint8ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): uint8ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint8ClampedArray( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint8cndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): uint8cndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var BooleanArray = require( '@stdlib/array-bool' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* function predicate( z ) { -* return z; -* } -* -* var buffer = new BooleanArray( [ false, true, false, true, false, true, false, true, false, true, false, true ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'bool', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, predicate ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ true, true, true, true ] -*/ -declare function filter( x: boolndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): boolndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 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( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: genericndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): genericndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'float64' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: typedndarray, options: Float64Options, predicate: Predicate, thisArg?: ThisParameterType> ): float64ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'float32' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: typedndarray, options: Float32Options, predicate: Predicate, thisArg?: ThisParameterType> ): float32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* function predicate( z, idx ) { -* return idx[ 0 ] > 0; -* } -* -* var buffer = new Complex128Array( [ 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 = [ 3, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'dtype': 'complex128' -* }; -* var y = filter( x, opts, predicate ); -* // returns -*/ -declare function filter( x: typedndarray, options: Complex128Options, predicate: Predicate, thisArg?: ThisParameterType> ): complex128ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* function predicate( z, idx ) { -* return idx[ 0 ] > 0; -* } -* -* var buffer = new Complex128Array( [ 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 = [ 3, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'dtype': 'complex64' -* }; -* var y = filter( x, opts, predicate ); -* // returns -*/ -declare function filter( x: typedndarray, options: Complex64Options, predicate: Predicate, thisArg?: ThisParameterType> ): complex64ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'int32' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: typedndarray, options: Int32Options, predicate: Predicate, thisArg?: ThisParameterType> ): int32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'int16' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: typedndarray, options: Int16Options, predicate: Predicate, thisArg?: ThisParameterType> ): int16ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'int8' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: typedndarray, options: Int8Options, predicate: Predicate, thisArg?: ThisParameterType> ): int8ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'uint32' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: typedndarray, options: Uint32Options, predicate: Predicate, thisArg?: ThisParameterType> ): uint32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'uint16' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: typedndarray, options: Uint16Options, predicate: Predicate, thisArg?: ThisParameterType> ): uint16ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'uint8' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: typedndarray, options: Uint8Options, predicate: Predicate, thisArg?: ThisParameterType> ): uint8ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'uint8c' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: typedndarray, options: Uint8COptions, predicate: Predicate, thisArg?: ThisParameterType> ): uint8cndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'bool' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ true, true, true, true ] -*/ -declare function filter( x: typedndarray, options: BoolOptions, predicate: Predicate, thisArg?: ThisParameterType> ): boolndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'generic' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: typedndarray, options: GenericOptions, predicate: Predicate, thisArg?: ThisParameterType> ): genericndarray; - - -// EXPORTS // - -export = filter; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 483f25f..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import 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)),D=v.get.apply(v,B),w.call(T,D,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 deleted file mode 100644 index 2c1ae93..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 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* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate 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 {boolean} [options.order] - index iteration order\n* @param {Callback} predicate - predicate function\n* @param {*} [thisArg] - predicate 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 { isPrimitive as isEven } from '@stdlib/assert-is-even';\n* import Float64Array from '@stdlib/array-float64';\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndarray2array from '@stdlib/ndarray-to-array';\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 = filter( x, isEven );\n* // returns \n*\n* var arr = ndarray2array( y );\n* // returns [ 2.0, 4.0, 8.0, 10.0 ]\n*/\nfunction filter( x, options, predicate, 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 = predicate;\n\t\t} else {\n\t\t\thasOpts = true;\n\t\t\topts = options;\n\t\t\tclbk = predicate;\n\t\t}\n\t} else {\n\t\thasOpts = true;\n\t\topts = options;\n\t\tclbk = predicate;\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 predicate 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 elements according to a predicate 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 = x.get.apply( x, idx );\n\t\tif ( clbk.call( ctx, v, idx.slice(), x ) ) {\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 filter;\n"],"names":["filter","x","options","predicate","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","get","apply","call","slice","gcopy","constructor"],"mappings":";;6zCA0EA,SAASA,EAAQC,EAAGC,EAASC,EAAWC,GACvC,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,IAE9CK,EAAIlB,EAAEsC,IAAIC,MAAOvC,EAAGa,GACfN,EAAKiC,KAAM9B,EAAKQ,EAAGL,EAAI4B,QAASzC,KACpCM,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/stats.html b/stats.html deleted file mode 100644 index 135eeac..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Codestin Search App - - - -
- - - - - From 752052a290fbe2cbd4c14621caa37cef989320fd Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 13 Jan 2025 03:03:25 +0000 Subject: [PATCH 26/35] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 57 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 79 +- SECURITY.md | 5 - benchmark/benchmark.1d.js | 150 - benchmark/benchmark.2d.js | 161 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 51 - docs/types/test.ts | 195 - examples/index.js | 38 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 55 - lib/main.js | 196 - package.json | 84 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 892 ---- 45 files changed, 4885 insertions(+), 5326 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.1d.js delete mode 100644 benchmark/benchmark.2d.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0779e8a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 4ec4778..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-01-13T02:15:36.136Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 03a0613..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) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 48af73a..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) 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 443f7ec..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: '9 21 * * 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 + + ```
@@ -257,7 +248,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]. @@ -320,21 +311,21 @@ Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-filter/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-map]: https://github.com/stdlib-js/ndarray-filter-map +[@stdlib/ndarray/filter-map]: https://github.com/stdlib-js/ndarray-filter-map/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 6958f29..0000000 --- a/benchmark/benchmark.1d.js +++ /dev/null @@ -1,150 +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 filter = require( './../lib' ); - - -// VARIABLES // - -var xtypes = [ 'generic' ]; -var ytypes = [ 'float64' ]; -var orders = [ 'row-major', 'column-major' ]; - - -// FUNCTIONS // - -/** -* Predicate function. -* -* @private -* @param {number} value - array element -* @param {NonNegativeIntegerArray} indices - element indices -* @param {ndarray} arr - input array -* @returns {boolean} result -*/ -function predicate( value ) { - return value > 0.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 = filter( x, opts, predicate ); - 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 c70a9f1..0000000 --- a/benchmark/benchmark.2d.js +++ /dev/null @@ -1,161 +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 filter = require( './../lib' ); - - -// VARIABLES // - -var xtypes = [ 'generic' ]; -var ytypes = [ 'float64' ]; -var orders = [ 'row-major', 'column-major' ]; - - -// FUNCTIONS // - -/** -* Predicate function. -* -* @private -* @param {number} value - array element -* @param {NonNegativeIntegerArray} indices - element indices -* @param {ndarray} arr - input array -* @returns {boolean} result -*/ -function predicate( value ) { - return value > 0.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 = filter( x, opts, predicate ); - 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 51e4f91..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" -%% click B href "https://github.com/stdlib-js/ndarray-filter/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-filter/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-filter/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-filter/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-filter/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/filter -[production-url]: https://github.com/stdlib-js/ndarray-filter/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-filter/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-filter/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-filter/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-filter/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-filter/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-filter/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 aafb9cb..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import filter from '../docs/types/index'; -export = filter; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index b5b2378..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(J,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"),N=require("@stdlib/ndarray-base-numel"),S=require("@stdlib/ndarray-base-next-cartesian-index").assign,A=require("@stdlib/blas-base-gcopy"),v=require("@stdlib/string-format");function B(r,a,g,k){var f,p,t,i,e,c,m,n,h,u,y,s,l,o,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=g):(f=!0,e=a,i=g):(f=!0,e=a,i=g,m=k),!b(i))throw new TypeError(v("invalid argument. Callback argument must be a function. Value: `%s`.",i));if(f){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(c=P(s),c===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),o=N(l),p=l.length,n==="row-major"?h=p-1:h=0,u=D(p),t={length:0},d=0;d0&&(u=S(l,n,u,h,u)),q=r.get.apply(r,u),i.call(m,q,u.slice(),r)&&(t[t.length]=q,t.length+=1);return o=t.length,y=new c(o),A(o,t,1,y,1),w=new r.constructor(s,y,[o],[1],0,n),w}E.exports=B});var G=j();module.exports=G; -/** -* @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 cfadd98..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* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate 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 {boolean} [options.order] - index iteration order\n* @param {Callback} predicate - predicate function\n* @param {*} [thisArg] - predicate 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 isEven = require( '@stdlib/assert-is-even' ).isPrimitive;\n* var Float64Array = require( '@stdlib/array-float64' );\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\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 = filter( x, isEven );\n* // returns \n*\n* var arr = ndarray2array( y );\n* // returns [ 2.0, 4.0, 8.0, 10.0 ]\n*/\nfunction filter( x, options, predicate, 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 = predicate;\n\t\t} else {\n\t\t\thasOpts = true;\n\t\t\topts = options;\n\t\t\tclbk = predicate;\n\t\t}\n\t} else {\n\t\thasOpts = true;\n\t\topts = options;\n\t\tclbk = predicate;\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 predicate 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 elements according to a predicate 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 = x.get.apply( x, idx );\n\t\tif ( clbk.call( ctx, v, idx.slice(), x ) ) {\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 = filter;\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* Return a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function.\n*\n* @module @stdlib/ndarray-filter\n*\n* @example\n* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive;\n* var Float64Array = require( '@stdlib/array-float64' );\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var filter = require( '@stdlib/ndarray-filter' );\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 = filter( x, isEven );\n* // returns \n*\n* var arr = ndarray2array( y );\n* // returns [ 2.0, 4.0, 8.0, 10.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,EAuC9C,SAASC,EAAQC,EAAGC,EAASC,EAAWC,EAAU,CACjD,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,EAAInB,EAAE,IAAI,MAAOA,EAAGa,CAAI,EACnBN,EAAK,KAAMG,EAAKS,EAAGN,EAAI,MAAM,EAAGb,CAAE,IACtCM,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", "filter", "x", "options", "predicate", "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 75de7ed..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,51 +0,0 @@ - -{{alias}}( x[, options], predicate[, thisArg] ) - Returns a shallow copy of an ndarray containing only those elements which - pass a test implemented by a predicate function. - - The predicate function is provided the following arguments: - - - value: current array element. - - indices: current array element indices. - - arr: the input 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'. - - predicate: Function - Predicate function. - - thisArg: any (optional) - Predicate function execution context. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ); - > function f( v ) { return v > 2.0; }; - > var y = {{alias}}( x, f ); - > {{alias:@stdlib/ndarray/to-array}}( y ) - [ 3.0, 4.0 ] - - See Also - -------- diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 046dffb..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,195 +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 empty = require( '@stdlib/ndarray-base-empty' ); -import zeros = require( '@stdlib/ndarray-base-zeros' ); -import filter = require( './index' ); - -/** -* Predicate function. -* -* @param x - input value -* @returns result -*/ -function predicate( x: any ): boolean { - return Boolean( x ); -} - -// The function returns an ndarray... -{ - const sh = [ 2, 2 ]; - const ord = 'row-major'; - - filter( zeros( 'float64', sh, ord ), predicate ); // $ExpectType float64ndarray - filter( zeros( 'float64', sh, ord ), predicate, {} ); // $ExpectType float64ndarray - filter( zeros( 'float32', sh, ord ), predicate ); // $ExpectType float32ndarray - filter( zeros( 'float32', sh, ord ), predicate, {} ); // $ExpectType float32ndarray - filter( zeros( 'complex64', sh, ord ), predicate ); // $ExpectType complex64ndarray - filter( zeros( 'complex64', sh, ord ), predicate, {} ); // $ExpectType complex64ndarray - filter( zeros( 'complex128', sh, ord ), predicate ); // $ExpectType complex128ndarray - filter( zeros( 'complex128', sh, ord ), predicate, {} ); // $ExpectType complex128ndarray - filter( zeros( 'int32', sh, ord ), predicate ); // $ExpectType int32ndarray - filter( zeros( 'int32', sh, ord ), predicate, {} ); // $ExpectType int32ndarray - filter( zeros( 'int16', sh, ord ), predicate ); // $ExpectType int16ndarray - filter( zeros( 'int16', sh, ord ), predicate, {} ); // $ExpectType int16ndarray - filter( zeros( 'int8', sh, ord ), predicate ); // $ExpectType int8ndarray - filter( zeros( 'int8', sh, ord ), predicate, {} ); // $ExpectType int8ndarray - filter( zeros( 'uint32', sh, ord ), predicate ); // $ExpectType uint32ndarray - filter( zeros( 'uint32', sh, ord ), predicate, {} ); // $ExpectType uint32ndarray - filter( zeros( 'uint16', sh, ord ), predicate ); // $ExpectType uint16ndarray - filter( zeros( 'uint16', sh, ord ), predicate, {} ); // $ExpectType uint16ndarray - filter( zeros( 'uint8', sh, ord ), predicate ); // $ExpectType uint8ndarray - filter( zeros( 'uint8', sh, ord ), predicate, {} ); // $ExpectType uint8ndarray - filter( zeros( 'uint8c', sh, ord ), predicate ); // $ExpectType uint8cndarray - filter( zeros( 'uint8c', sh, ord ), predicate, {} ); // $ExpectType uint8cndarray - filter( empty( 'bool', sh, ord ), predicate ); // $ExpectType boolndarray - filter( empty( 'bool', sh, ord ), predicate, {} ); // $ExpectType boolndarray - filter( zeros( 'generic', sh, ord ), predicate ); // $ExpectType genericndarray - filter( zeros( 'generic', sh, ord ), predicate, {} ); // $ExpectType genericndarray - - - filter( zeros( 'generic', sh, ord ), { 'dtype': 'float64' }, predicate ); // $ExpectType float64ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'float64' }, predicate, {} ); // $ExpectType float64ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'float32' }, predicate ); // $ExpectType float32ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'float32' }, predicate, {} ); // $ExpectType float32ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'complex64' }, predicate ); // $ExpectType complex64ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'complex64' }, predicate, {} ); // $ExpectType complex64ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'complex128' }, predicate ); // $ExpectType complex128ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'complex128' }, predicate, {} ); // $ExpectType complex128ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'int32' }, predicate ); // $ExpectType int32ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'int32' }, predicate, {} ); // $ExpectType int32ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'int16' }, predicate ); // $ExpectType int16ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'int16' }, predicate, {} ); // $ExpectType int16ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'int8' }, predicate ); // $ExpectType int8ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'int8' }, predicate, {} ); // $ExpectType int8ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint32' }, predicate ); // $ExpectType uint32ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint32' }, predicate, {} ); // $ExpectType uint32ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint16' }, predicate ); // $ExpectType uint16ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint16' }, predicate, {} ); // $ExpectType uint16ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint8' }, predicate ); // $ExpectType uint8ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint8' }, predicate, {} ); // $ExpectType uint8ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint8c' }, predicate ); // $ExpectType uint8cndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint8c' }, predicate, {} ); // $ExpectType uint8cndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'bool' }, predicate ); // $ExpectType boolndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'bool' }, predicate, {} ); // $ExpectType boolndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'generic' }, predicate ); // $ExpectType genericndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'generic' }, predicate, {} ); // $ExpectType genericndarray - - - filter( zeros( 'float64', sh, ord ), { 'order': ord }, predicate ); // $ExpectType float64ndarray - filter( zeros( 'float64', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType float64ndarray - filter( zeros( 'float32', sh, ord ), { 'order': ord }, predicate ); // $ExpectType float32ndarray - filter( zeros( 'float32', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType float32ndarray - filter( zeros( 'complex64', sh, ord ), { 'order': ord }, predicate ); // $ExpectType complex64ndarray - filter( zeros( 'complex64', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType complex64ndarray - filter( zeros( 'complex128', sh, ord ), { 'order': ord }, predicate ); // $ExpectType complex128ndarray - filter( zeros( 'complex128', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType complex128ndarray - filter( zeros( 'int32', sh, ord ), { 'order': ord }, predicate ); // $ExpectType int32ndarray - filter( zeros( 'int32', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType int32ndarray - filter( zeros( 'int16', sh, ord ), { 'order': ord }, predicate ); // $ExpectType int16ndarray - filter( zeros( 'int16', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType int16ndarray - filter( zeros( 'int8', sh, ord ), { 'order': ord }, predicate ); // $ExpectType int8ndarray - filter( zeros( 'int8', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType int8ndarray - filter( zeros( 'uint32', sh, ord ), { 'order': ord }, predicate ); // $ExpectType uint32ndarray - filter( zeros( 'uint32', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType uint32ndarray - filter( zeros( 'uint16', sh, ord ), { 'order': ord }, predicate ); // $ExpectType uint16ndarray - filter( zeros( 'uint16', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType uint16ndarray - filter( zeros( 'uint8', sh, ord ), { 'order': ord }, predicate ); // $ExpectType uint8ndarray - filter( zeros( 'uint8', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType uint8ndarray - filter( zeros( 'uint8c', sh, ord ), { 'order': ord }, predicate ); // $ExpectType uint8cndarray - filter( zeros( 'uint8c', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType uint8cndarray - filter( empty( 'bool', sh, ord ), { 'order': ord }, predicate ); // $ExpectType boolndarray - filter( empty( 'bool', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType boolndarray - filter( zeros( 'generic', sh, ord ), { 'order': ord }, predicate ); // $ExpectType genericndarray - filter( zeros( 'generic', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType genericndarray - -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - filter( 5, predicate ); // $ExpectError - filter( true, predicate ); // $ExpectError - filter( false, predicate ); // $ExpectError - filter( null, predicate ); // $ExpectError - filter( undefined, predicate ); // $ExpectError - filter( {}, predicate ); // $ExpectError - filter( [ 1 ], predicate ); // $ExpectError - filter( ( x: number ): number => x, predicate ); // $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' ); - - filter( x, '5' ); // $ExpectError - filter( x, true ); // $ExpectError - filter( x, false ); // $ExpectError - filter( x, null ); // $ExpectError - filter( x, undefined ); // $ExpectError - filter( x, {} ); // $ExpectError - filter( 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' ); - - filter( x, '10', predicate, {} ); // $ExpectError - filter( x, 10, predicate, {} ); // $ExpectError - filter( x, false, predicate, {} ); // $ExpectError - filter( x, true, predicate, {} ); // $ExpectError - filter( x, [], predicate, {} ); // $ExpectError - filter( x, ( x: number ): number => x, predicate, {} ); // $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' ); - - filter( x, { 'dtype': '10' }, predicate ); // $ExpectError - filter( x, { 'dtype': 10 }, predicate ); // $ExpectError - filter( x, { 'dtype': null }, predicate ); // $ExpectError - filter( x, { 'dtype': false }, predicate ); // $ExpectError - filter( x, { 'dtype': true }, predicate ); // $ExpectError - filter( x, { 'dtype': [] }, predicate ); // $ExpectError - filter( x, { 'dtype': {} }, predicate ); // $ExpectError - filter( x, { 'dtype': ( x: number ): number => x }, predicate ); // $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' ); - - filter( x, { 'order': '10' }, predicate ); // $ExpectError - filter( x, { 'order': 10 }, predicate ); // $ExpectError - filter( x, { 'order': null }, predicate ); // $ExpectError - filter( x, { 'order': false }, predicate ); // $ExpectError - filter( x, { 'order': true }, predicate ); // $ExpectError - filter( x, { 'order': [] }, predicate ); // $ExpectError - filter( x, { 'order': {} }, predicate ); // $ExpectError - filter( x, { 'order': ( x: number ): number => x }, predicate ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - filter(); // $ExpectError - filter( zeros( 'float64', [ 2, 2 ], 'row-major' ) ); // $ExpectError - filter( 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 e2dd6cb..0000000 --- a/examples/index.js +++ /dev/null @@ -1,38 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var array = require( '@stdlib/ndarray-array' ); -var isPositive = require( '@stdlib/assert-is-positive-number' ).isPrimitive; -var filter = require( './../lib' ); - -var buffer = discreteUniform( 10, -100, 100, { - 'dtype': 'generic' -}); -var x = array( buffer, { - 'shape': [ 5, 2 ], - 'dtype': 'generic' -}); -console.log( ndarray2array( x ) ); - -var y = filter( x, naryFunction( isPositive, 1 ) ); -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 c4dadbe..7f6ff4a 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..483f25f --- /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)),D=v.get.apply(v,B),w.call(T,D,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..2c1ae93 --- /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* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate 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 {boolean} [options.order] - index iteration order\n* @param {Callback} predicate - predicate function\n* @param {*} [thisArg] - predicate 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 { isPrimitive as isEven } from '@stdlib/assert-is-even';\n* import Float64Array from '@stdlib/array-float64';\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndarray2array from '@stdlib/ndarray-to-array';\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 = filter( x, isEven );\n* // returns \n*\n* var arr = ndarray2array( y );\n* // returns [ 2.0, 4.0, 8.0, 10.0 ]\n*/\nfunction filter( x, options, predicate, 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 = predicate;\n\t\t} else {\n\t\t\thasOpts = true;\n\t\t\topts = options;\n\t\t\tclbk = predicate;\n\t\t}\n\t} else {\n\t\thasOpts = true;\n\t\topts = options;\n\t\tclbk = predicate;\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 predicate 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 elements according to a predicate 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 = x.get.apply( x, idx );\n\t\tif ( clbk.call( ctx, v, idx.slice(), x ) ) {\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 filter;\n"],"names":["filter","x","options","predicate","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","get","apply","call","slice","gcopy","constructor"],"mappings":";;6zCA0EA,SAASA,EAAQC,EAAGC,EAASC,EAAWC,GACvC,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,IAE9CK,EAAIlB,EAAEsC,IAAIC,MAAOvC,EAAGa,GACfN,EAAKiC,KAAM9B,EAAKQ,EAAGL,EAAI4B,QAASzC,KACpCM,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 46f5998..0000000 --- a/lib/index.js +++ /dev/null @@ -1,55 +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'; - -/** -* Return a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @module @stdlib/ndarray-filter -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var filter = require( '@stdlib/ndarray-filter' ); -* -* 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 = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.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 3cd50e0..0000000 --- a/lib/main.js +++ /dev/null @@ -1,196 +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/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param {ndarray} x - input ndarray -* @param {Options} [options] - function options -* @param {string} [options.dtype] - output array data type -* @param {boolean} [options.order] - index iteration order -* @param {Callback} predicate - predicate function -* @param {*} [thisArg] - predicate 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 isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -function filter( x, options, predicate, 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( 'null5t', x ) ); - } - if ( arguments.length < 3 ) { - clbk = options; - } else if ( arguments.length === 3 ) { - if ( isFunction( options ) ) { - clbk = options; - ctx = predicate; - } else { - hasOpts = true; - opts = options; - clbk = predicate; - } - } else { - hasOpts = true; - opts = options; - clbk = predicate; - ctx = thisArg; - } - if ( !isFunction( clbk ) ) { - throw new TypeError( format( 'null2b', clbk ) ); - } - if ( hasOpts ) { - if ( !isPlainObject( opts ) ) { - throw new TypeError( format( 'null2V', opts ) ); - } - if ( hasOwnProp( opts, 'dtype' ) ) { - dt = opts.dtype; - } else { - dt = getDType( x ); - } - if ( hasOwnProp( opts, 'order' ) ) { - if ( !isOrder( opts.order ) ) { - throw new TypeError( format( 'null5C', '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( 'nullBf', '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 predicate 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 elements according to a predicate function... - for ( i = 0; i < N; i++ ) { - if ( i > 0 ) { - idx = nextCartesianIndex( sh, ord, idx, dim, idx ); - } - v = x.get.apply( x, idx ); - if ( clbk.call( ctx, v, idx.slice(), x ) ) { - 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 = filter; diff --git a/package.json b/package.json index a44b313..2473eda 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Return a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate 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,62 +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/error-tools-fmtprodmsg": "^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-positive-number": "^0.2.2", - "@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", - "@stdlib/utils-nary-function": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "strided", @@ -104,7 +25,6 @@ "select", "take" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..135eeac --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Codestin Search App + + + +
+ + + + + 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 3bea6b3..0000000 --- a/test/test.js +++ /dev/null @@ -1,892 +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 filter = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof filter, '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() { - filter( value, predicate ); - }; - } - - function predicate( z ) { - return ( z > 0.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() { - filter( 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() { - filter( 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() { - filter( x, value, predicate ); - }; - } - - function predicate( z ) { - return ( z > 0.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 - }; - filter( x, opts, predicate ); - }; - } - - function predicate( z ) { - return ( z > 0.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 - }; - filter( x, opts, predicate ); - }; - } - - function predicate( z ) { - return ( z > 0.0 ); - } -}); - -tape( 'the function filters an array according to a predicate 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 = filter( x, predicate ); - - expected = new Float64Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - - t.end(); - - function predicate( z ) { - return ( z > 0.0 ); - } -}); - -tape( 'the function filters an array according to a predicate 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 = filter( x, predicate ); - - expected = new Float64Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - - t.end(); - - function predicate( z ) { - return ( z > 0.0 ); - } -}); - -tape( 'the function filters an array according to a predicate 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 = filter( x, opts, predicate ); - - expected = new Float64Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - - opts = { - 'dtype': 'float32' - }; - y = filter( x, opts, predicate ); - - expected = new Float32Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat32Array( y.data, expected ), true, 'returns expected value' ); - - t.end(); - - function predicate( z ) { - return ( z > 0.0 ); - } -}); - -tape( 'the function filters an array according to a predicate 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 = filter( x, opts, predicate ); - - expected = new Float64Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - - opts = { - 'dtype': 'float32' - }; - y = filter( x, opts, predicate ); - - expected = new Float32Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat32Array( y.data, expected ), true, 'returns expected value' ); - - t.end(); - - function predicate( z ) { - return ( z > 0.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 = filter( x, predicate, ctx ); - - expected = new Float64Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function predicate( z ) { - this.count += 1; // eslint-disable-line no-invalid-this - return ( z > 0.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 = filter( x, {}, predicate, ctx ); - - expected = new Float64Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function predicate( z ) { - this.count += 1; // eslint-disable-line no-invalid-this - return ( z > 0.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 = filter( x, predicate ); - - expected = new Float64Array([ - 1.0, - 3.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 predicate( z, idx, arr ) { - values.push( z ); - indices.push( idx ); - arrays.push( arr ); - return ( z > 0.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 = filter( x, predicate ); - - expected = new Float64Array([ - 1.0, - 3.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 predicate( z, idx, arr ) { - values.push( z ); - indices.push( idx ); - arrays.push( arr ); - return ( z > 0.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 = filter( x, opts, predicate ); - - expected = new Float64Array([ - 1.0, - 3.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 predicate( z, idx, arr ) { - values.push( z ); - indices.push( idx ); - arrays.push( arr ); - return ( z > 0.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 = filter( x, opts, predicate ); - - expected = new Float64Array([ - 1.0, - 3.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 predicate( z, idx, arr ) { - values.push( z ); - indices.push( idx ); - arrays.push( arr ); - return ( z > 0.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 = filter( x, opts, predicate ); - - expected = new Float64Array([ - 1.0, - 3.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 predicate( z, idx, arr ) { - values.push( z ); - indices.push( idx ); - arrays.push( arr ); - return ( z > 0.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 = filter( x, opts, predicate ); - - expected = new Float64Array([ - 1.0, - 3.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 predicate( z, idx, arr ) { - values.push( z ); - indices.push( idx ); - arrays.push( arr ); - return ( z > 0.0 ); - } -}); From 1e7ac7cd1abfd83dc87c04ec54f1b2c676a5b432 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 20 Jan 2025 01:28:41 +0000 Subject: [PATCH 27/35] Transform error messages --- lib/main.js | 12 ++++++------ package.json | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/main.js b/lib/main.js index 6ad824e..3cd50e0 100644 --- a/lib/main.js +++ b/lib/main.js @@ -33,7 +33,7 @@ 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' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -91,7 +91,7 @@ function filter( x, options, predicate, thisArg ) { var v; var i; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray-like object. Value: `%s`.', x ) ); + throw new TypeError( format( 'null5t', x ) ); } if ( arguments.length < 3 ) { clbk = options; @@ -111,11 +111,11 @@ function filter( x, options, predicate, thisArg ) { ctx = thisArg; } if ( !isFunction( clbk ) ) { - throw new TypeError( format( 'invalid argument. Callback argument must be a function. Value: `%s`.', clbk ) ); + throw new TypeError( format( 'null2b', clbk ) ); } if ( hasOpts ) { if ( !isPlainObject( opts ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) ); + throw new TypeError( format( 'null2V', opts ) ); } if ( hasOwnProp( opts, 'dtype' ) ) { dt = opts.dtype; @@ -124,7 +124,7 @@ function filter( x, options, predicate, thisArg ) { } 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 ) ); + throw new TypeError( format( 'null5C', 'order', opts.order ) ); } ord = opts.order; } @@ -135,7 +135,7 @@ function filter( x, options, predicate, thisArg ) { 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 ) ); + throw new TypeError( format( 'nullBf', 'dtype', opts.dtype ) ); } // Resolve the iteration order: if ( ord === void 0 ) { diff --git a/package.json b/package.json index 22065aa..a44b313 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@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/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From acb1eeef813e0db15f810b243160cae07dc43601 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 20 Jan 2025 01:35:22 +0000 Subject: [PATCH 28/35] Remove files --- index.d.ts | 1612 ---------------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 6459 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 7f6ff4a..0000000 --- a/index.d.ts +++ /dev/null @@ -1,1612 +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. -*/ - -// TypeScript Version: 4.1 - -/// - -/* eslint-disable max-lines */ - -import { typedndarray, DataType, Order, float64ndarray, float32ndarray, complex128ndarray, complex64ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, boolndarray, genericndarray } from '@stdlib/types/ndarray'; -import { Complex64, Complex128 } from '@stdlib/types/complex'; - -/** -* Returns a boolean indicating whether an element passes a test. -* -* @returns boolean indicating whether an element passes a test -*/ -type Nullary = ( this: V ) => boolean; - -/** -* Returns a boolean indicating whether an element passes a test. -* -* @param value - current array element -* @returns boolean indicating whether an element passes a test -*/ -type Unary = ( this: V, value: T ) => boolean; - -/** -* Returns a boolean indicating whether an element passes a test. -* -* @param value - current array element -* @param indices - current array element indices -* @returns boolean indicating whether an element passes a test -*/ -type Binary = ( this: V, value: T, indices: Array ) => boolean; - -/** -* Returns a boolean indicating whether an element passes a test. -* -* @param value - current array element -* @param indices - current array element indices -* @param arr - input array -* @returns boolean indicating whether an element passes a test -*/ -type Ternary = ( this: V, value: T, indices: Array, arr: typedndarray ) => boolean; - -/** -* Returns a boolean indicating whether an element passes a test. -* -* @param value - current array element -* @param indices - current array element indices -* @param arr - input array -* @returns boolean indicating whether an element passes a test -*/ -type Predicate = Nullary | Unary | Binary | Ternary; - -/** -* Interface describing "base" function options. -*/ -interface BaseOptions { - /** - * Index iteration order. - * - * ## Notes - * - * - By default, the function iterates over elements according to the layout order of the provided ndarray. Accordingly, for row-major input ndarrays, the last dimension indices increment fastest. For column-major input ndarrays, the first dimension indices increment fastest. To override the inferred order and ensure that indices increment in a specific manner, regardless of the input ndarray's layout order, explicitly set the iteration order. Note, however, that iterating according to an order which does not match that of the input ndarray may, in some circumstances, result in performance degradation due to cache misses. - */ - order?: Order; -} - -/** -* Interface describing function options. -*/ -interface OrderOptions { - /** - * Index iteration order. - * - * ## Notes - * - * - By default, the function iterates over elements according to the layout order of the provided ndarray. Accordingly, for row-major input ndarrays, the last dimension indices increment fastest. For column-major input ndarrays, the first dimension indices increment fastest. To override the inferred order and ensure that indices increment in a specific manner, regardless of the input ndarray's layout order, explicitly set the iteration order. Note, however, that iterating according to an order which does not match that of the input ndarray may, in some circumstances, result in performance degradation due to cache misses. - */ - order: Order; -} - -/** -* Interface describing function options. -*/ -interface Options extends BaseOptions { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: DataType; -} - -/** -* Interface describing function options. -*/ -interface Float64Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'float64'; -} - -/** -* Interface describing function options. -*/ -interface Float32Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'float32'; -} - -/** -* Interface describing function options. -*/ -interface Complex128Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'complex128'; -} - -/** -* Interface describing function options. -*/ -interface Complex64Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'complex64'; -} - -/** -* Interface describing function options. -*/ -interface Int32Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'int32'; -} - -/** -* Interface describing function options. -*/ -interface Int16Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'int16'; -} - -/** -* Interface describing function options. -*/ -interface Int8Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'int8'; -} - -/** -* Interface describing function options. -*/ -interface Uint32Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'uint32'; -} - -/** -* Interface describing function options. -*/ -interface Uint16Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'uint16'; -} - -/** -* Interface describing function options. -*/ -interface Uint8Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'uint8'; -} - -/** -* Interface describing function options. -*/ -interface Uint8COptions extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'uint8c'; -} - -/** -* Interface describing function options. -*/ -interface BoolOptions extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'bool'; -} - -/** -* Interface describing function options. -*/ -interface GenericOptions extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'generic'; -} - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: float64ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): float64ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float32Array = require( '@stdlib/array-float32' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Float32Array( [ 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( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: float32ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): float32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var Complex64Array = require( '@stdlib/array-complex64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* function predicate( z, idx ) { -* return idx[ 0 ] > 0; -* } -* -* var buffer = new Complex64Array( [ 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 = [ 3, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, predicate ); -* // returns -*/ -declare function filter( x: complex64ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): complex64ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* function predicate( z, idx ) { -* return idx[ 0 ] > 0; -* } -* -* var buffer = new Complex128Array( [ 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 = [ 3, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, predicate ); -* // returns -*/ -declare function filter( x: complex128ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): complex128ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Int32Array = require( '@stdlib/array-int32' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Int32Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: int32ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): int32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Int16Array = require( '@stdlib/array-int16' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Int16Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: int16ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): int16ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Int8Array = require( '@stdlib/array-int8' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Int8Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: int8ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): int8ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint32Array = require( '@stdlib/array-uint32' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint32Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint32ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): uint32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint16Array = require( '@stdlib/array-uint16' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint16Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint16ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): uint16ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint8Array = require( '@stdlib/array-uint8' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint8Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint8ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): uint8ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint8ClampedArray( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint8cndarray, predicate: Predicate, thisArg?: ThisParameterType> ): uint8cndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var BooleanArray = require( '@stdlib/array-bool' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* function predicate( z ) { -* return z; -* } -* -* var buffer = new BooleanArray( [ false, true, false, true, false, true, false, true, false, true, false, true ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'bool', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, predicate ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ true, true, true, true ] -*/ -declare function filter( x: boolndarray, predicate: Predicate, thisArg?: ThisParameterType> ): boolndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 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( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: genericndarray, predicate: Predicate, thisArg?: ThisParameterType> ): genericndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: float64ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): float64ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float32Array = require( '@stdlib/array-float32' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Float32Array( [ 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( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: float32ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): float32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var Complex64Array = require( '@stdlib/array-complex64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* function predicate( z, idx ) { -* return idx[ 0 ] > 0; -* } -* -* var buffer = new Complex64Array( [ 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 = [ 3, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, predicate ); -* // returns -*/ -declare function filter( x: complex64ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): complex64ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* function predicate( z, idx ) { -* return idx[ 0 ] > 0; -* } -* -* var buffer = new Complex128Array( [ 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 = [ 3, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, predicate ); -* // returns -*/ -declare function filter( x: complex128ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): complex128ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Int32Array = require( '@stdlib/array-int32' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Int32Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: int32ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): int32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Int16Array = require( '@stdlib/array-int16' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Int16Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: int16ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): int16ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Int8Array = require( '@stdlib/array-int8' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Int8Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: int8ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): int8ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint32Array = require( '@stdlib/array-uint32' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint32Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint32ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): uint32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint16Array = require( '@stdlib/array-uint16' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint16Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint16ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): uint16ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint8Array = require( '@stdlib/array-uint8' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint8Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint8ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): uint8ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint8ClampedArray( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint8cndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): uint8cndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var BooleanArray = require( '@stdlib/array-bool' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* function predicate( z ) { -* return z; -* } -* -* var buffer = new BooleanArray( [ false, true, false, true, false, true, false, true, false, true, false, true ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'bool', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, predicate ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ true, true, true, true ] -*/ -declare function filter( x: boolndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): boolndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 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( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: genericndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): genericndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'float64' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: typedndarray, options: Float64Options, predicate: Predicate, thisArg?: ThisParameterType> ): float64ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'float32' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: typedndarray, options: Float32Options, predicate: Predicate, thisArg?: ThisParameterType> ): float32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* function predicate( z, idx ) { -* return idx[ 0 ] > 0; -* } -* -* var buffer = new Complex128Array( [ 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 = [ 3, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'dtype': 'complex128' -* }; -* var y = filter( x, opts, predicate ); -* // returns -*/ -declare function filter( x: typedndarray, options: Complex128Options, predicate: Predicate, thisArg?: ThisParameterType> ): complex128ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* function predicate( z, idx ) { -* return idx[ 0 ] > 0; -* } -* -* var buffer = new Complex128Array( [ 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 = [ 3, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'dtype': 'complex64' -* }; -* var y = filter( x, opts, predicate ); -* // returns -*/ -declare function filter( x: typedndarray, options: Complex64Options, predicate: Predicate, thisArg?: ThisParameterType> ): complex64ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'int32' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: typedndarray, options: Int32Options, predicate: Predicate, thisArg?: ThisParameterType> ): int32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'int16' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: typedndarray, options: Int16Options, predicate: Predicate, thisArg?: ThisParameterType> ): int16ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'int8' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: typedndarray, options: Int8Options, predicate: Predicate, thisArg?: ThisParameterType> ): int8ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'uint32' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: typedndarray, options: Uint32Options, predicate: Predicate, thisArg?: ThisParameterType> ): uint32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'uint16' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: typedndarray, options: Uint16Options, predicate: Predicate, thisArg?: ThisParameterType> ): uint16ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'uint8' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: typedndarray, options: Uint8Options, predicate: Predicate, thisArg?: ThisParameterType> ): uint8ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'uint8c' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: typedndarray, options: Uint8COptions, predicate: Predicate, thisArg?: ThisParameterType> ): uint8cndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'bool' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ true, true, true, true ] -*/ -declare function filter( x: typedndarray, options: BoolOptions, predicate: Predicate, thisArg?: ThisParameterType> ): boolndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'generic' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: typedndarray, options: GenericOptions, predicate: Predicate, thisArg?: ThisParameterType> ): genericndarray; - - -// EXPORTS // - -export = filter; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 483f25f..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import 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)),D=v.get.apply(v,B),w.call(T,D,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 deleted file mode 100644 index 2c1ae93..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 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* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate 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 {boolean} [options.order] - index iteration order\n* @param {Callback} predicate - predicate function\n* @param {*} [thisArg] - predicate 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 { isPrimitive as isEven } from '@stdlib/assert-is-even';\n* import Float64Array from '@stdlib/array-float64';\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndarray2array from '@stdlib/ndarray-to-array';\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 = filter( x, isEven );\n* // returns \n*\n* var arr = ndarray2array( y );\n* // returns [ 2.0, 4.0, 8.0, 10.0 ]\n*/\nfunction filter( x, options, predicate, 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 = predicate;\n\t\t} else {\n\t\t\thasOpts = true;\n\t\t\topts = options;\n\t\t\tclbk = predicate;\n\t\t}\n\t} else {\n\t\thasOpts = true;\n\t\topts = options;\n\t\tclbk = predicate;\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 predicate 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 elements according to a predicate 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 = x.get.apply( x, idx );\n\t\tif ( clbk.call( ctx, v, idx.slice(), x ) ) {\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 filter;\n"],"names":["filter","x","options","predicate","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","get","apply","call","slice","gcopy","constructor"],"mappings":";;6zCA0EA,SAASA,EAAQC,EAAGC,EAASC,EAAWC,GACvC,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,IAE9CK,EAAIlB,EAAEsC,IAAIC,MAAOvC,EAAGa,GACfN,EAAKiC,KAAM9B,EAAKQ,EAAGL,EAAI4B,QAASzC,KACpCM,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/stats.html b/stats.html deleted file mode 100644 index 135eeac..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Codestin Search App - - - -
- - - - - From 54dfd49d31daa3a09e35c3a6ebc42b5a9b5b5d04 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 20 Jan 2025 01:35:51 +0000 Subject: [PATCH 29/35] Auto-generated commit --- .editorconfig | 180 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 57 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 79 +- SECURITY.md | 5 - benchmark/benchmark.1d.js | 150 - benchmark/benchmark.2d.js | 161 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 51 - docs/types/test.ts | 195 - examples/index.js | 38 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 55 - lib/main.js | 196 - package.json | 84 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 892 ---- 45 files changed, 4885 insertions(+), 5325 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.1d.js delete mode 100644 benchmark/benchmark.2d.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index dab5d2a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,180 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 73a2d18..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-01-20T01:28:13.161Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 03a0613..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) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 48af73a..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) 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 443f7ec..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: '9 21 * * 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 + + ```
@@ -257,7 +248,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]. @@ -320,21 +311,21 @@ Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-filter/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-map]: https://github.com/stdlib-js/ndarray-filter-map +[@stdlib/ndarray/filter-map]: https://github.com/stdlib-js/ndarray-filter-map/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 6958f29..0000000 --- a/benchmark/benchmark.1d.js +++ /dev/null @@ -1,150 +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 filter = require( './../lib' ); - - -// VARIABLES // - -var xtypes = [ 'generic' ]; -var ytypes = [ 'float64' ]; -var orders = [ 'row-major', 'column-major' ]; - - -// FUNCTIONS // - -/** -* Predicate function. -* -* @private -* @param {number} value - array element -* @param {NonNegativeIntegerArray} indices - element indices -* @param {ndarray} arr - input array -* @returns {boolean} result -*/ -function predicate( value ) { - return value > 0.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 = filter( x, opts, predicate ); - 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 c70a9f1..0000000 --- a/benchmark/benchmark.2d.js +++ /dev/null @@ -1,161 +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 filter = require( './../lib' ); - - -// VARIABLES // - -var xtypes = [ 'generic' ]; -var ytypes = [ 'float64' ]; -var orders = [ 'row-major', 'column-major' ]; - - -// FUNCTIONS // - -/** -* Predicate function. -* -* @private -* @param {number} value - array element -* @param {NonNegativeIntegerArray} indices - element indices -* @param {ndarray} arr - input array -* @returns {boolean} result -*/ -function predicate( value ) { - return value > 0.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 = filter( x, opts, predicate ); - 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 51e4f91..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" -%% click B href "https://github.com/stdlib-js/ndarray-filter/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-filter/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-filter/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-filter/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-filter/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/filter -[production-url]: https://github.com/stdlib-js/ndarray-filter/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-filter/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-filter/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-filter/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-filter/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-filter/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-filter/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 aafb9cb..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import filter from '../docs/types/index'; -export = filter; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index b5b2378..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(J,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"),N=require("@stdlib/ndarray-base-numel"),S=require("@stdlib/ndarray-base-next-cartesian-index").assign,A=require("@stdlib/blas-base-gcopy"),v=require("@stdlib/string-format");function B(r,a,g,k){var f,p,t,i,e,c,m,n,h,u,y,s,l,o,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=g):(f=!0,e=a,i=g):(f=!0,e=a,i=g,m=k),!b(i))throw new TypeError(v("invalid argument. Callback argument must be a function. Value: `%s`.",i));if(f){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(c=P(s),c===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),o=N(l),p=l.length,n==="row-major"?h=p-1:h=0,u=D(p),t={length:0},d=0;d0&&(u=S(l,n,u,h,u)),q=r.get.apply(r,u),i.call(m,q,u.slice(),r)&&(t[t.length]=q,t.length+=1);return o=t.length,y=new c(o),A(o,t,1,y,1),w=new r.constructor(s,y,[o],[1],0,n),w}E.exports=B});var G=j();module.exports=G; -/** -* @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 cfadd98..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* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate 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 {boolean} [options.order] - index iteration order\n* @param {Callback} predicate - predicate function\n* @param {*} [thisArg] - predicate 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 isEven = require( '@stdlib/assert-is-even' ).isPrimitive;\n* var Float64Array = require( '@stdlib/array-float64' );\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\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 = filter( x, isEven );\n* // returns \n*\n* var arr = ndarray2array( y );\n* // returns [ 2.0, 4.0, 8.0, 10.0 ]\n*/\nfunction filter( x, options, predicate, 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 = predicate;\n\t\t} else {\n\t\t\thasOpts = true;\n\t\t\topts = options;\n\t\t\tclbk = predicate;\n\t\t}\n\t} else {\n\t\thasOpts = true;\n\t\topts = options;\n\t\tclbk = predicate;\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 predicate 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 elements according to a predicate 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 = x.get.apply( x, idx );\n\t\tif ( clbk.call( ctx, v, idx.slice(), x ) ) {\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 = filter;\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* Return a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function.\n*\n* @module @stdlib/ndarray-filter\n*\n* @example\n* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive;\n* var Float64Array = require( '@stdlib/array-float64' );\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var filter = require( '@stdlib/ndarray-filter' );\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 = filter( x, isEven );\n* // returns \n*\n* var arr = ndarray2array( y );\n* // returns [ 2.0, 4.0, 8.0, 10.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,EAuC9C,SAASC,EAAQC,EAAGC,EAASC,EAAWC,EAAU,CACjD,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,EAAInB,EAAE,IAAI,MAAOA,EAAGa,CAAI,EACnBN,EAAK,KAAMG,EAAKS,EAAGN,EAAI,MAAM,EAAGb,CAAE,IACtCM,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", "filter", "x", "options", "predicate", "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 75de7ed..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,51 +0,0 @@ - -{{alias}}( x[, options], predicate[, thisArg] ) - Returns a shallow copy of an ndarray containing only those elements which - pass a test implemented by a predicate function. - - The predicate function is provided the following arguments: - - - value: current array element. - - indices: current array element indices. - - arr: the input 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'. - - predicate: Function - Predicate function. - - thisArg: any (optional) - Predicate function execution context. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ); - > function f( v ) { return v > 2.0; }; - > var y = {{alias}}( x, f ); - > {{alias:@stdlib/ndarray/to-array}}( y ) - [ 3.0, 4.0 ] - - See Also - -------- diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 046dffb..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,195 +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 empty = require( '@stdlib/ndarray-base-empty' ); -import zeros = require( '@stdlib/ndarray-base-zeros' ); -import filter = require( './index' ); - -/** -* Predicate function. -* -* @param x - input value -* @returns result -*/ -function predicate( x: any ): boolean { - return Boolean( x ); -} - -// The function returns an ndarray... -{ - const sh = [ 2, 2 ]; - const ord = 'row-major'; - - filter( zeros( 'float64', sh, ord ), predicate ); // $ExpectType float64ndarray - filter( zeros( 'float64', sh, ord ), predicate, {} ); // $ExpectType float64ndarray - filter( zeros( 'float32', sh, ord ), predicate ); // $ExpectType float32ndarray - filter( zeros( 'float32', sh, ord ), predicate, {} ); // $ExpectType float32ndarray - filter( zeros( 'complex64', sh, ord ), predicate ); // $ExpectType complex64ndarray - filter( zeros( 'complex64', sh, ord ), predicate, {} ); // $ExpectType complex64ndarray - filter( zeros( 'complex128', sh, ord ), predicate ); // $ExpectType complex128ndarray - filter( zeros( 'complex128', sh, ord ), predicate, {} ); // $ExpectType complex128ndarray - filter( zeros( 'int32', sh, ord ), predicate ); // $ExpectType int32ndarray - filter( zeros( 'int32', sh, ord ), predicate, {} ); // $ExpectType int32ndarray - filter( zeros( 'int16', sh, ord ), predicate ); // $ExpectType int16ndarray - filter( zeros( 'int16', sh, ord ), predicate, {} ); // $ExpectType int16ndarray - filter( zeros( 'int8', sh, ord ), predicate ); // $ExpectType int8ndarray - filter( zeros( 'int8', sh, ord ), predicate, {} ); // $ExpectType int8ndarray - filter( zeros( 'uint32', sh, ord ), predicate ); // $ExpectType uint32ndarray - filter( zeros( 'uint32', sh, ord ), predicate, {} ); // $ExpectType uint32ndarray - filter( zeros( 'uint16', sh, ord ), predicate ); // $ExpectType uint16ndarray - filter( zeros( 'uint16', sh, ord ), predicate, {} ); // $ExpectType uint16ndarray - filter( zeros( 'uint8', sh, ord ), predicate ); // $ExpectType uint8ndarray - filter( zeros( 'uint8', sh, ord ), predicate, {} ); // $ExpectType uint8ndarray - filter( zeros( 'uint8c', sh, ord ), predicate ); // $ExpectType uint8cndarray - filter( zeros( 'uint8c', sh, ord ), predicate, {} ); // $ExpectType uint8cndarray - filter( empty( 'bool', sh, ord ), predicate ); // $ExpectType boolndarray - filter( empty( 'bool', sh, ord ), predicate, {} ); // $ExpectType boolndarray - filter( zeros( 'generic', sh, ord ), predicate ); // $ExpectType genericndarray - filter( zeros( 'generic', sh, ord ), predicate, {} ); // $ExpectType genericndarray - - - filter( zeros( 'generic', sh, ord ), { 'dtype': 'float64' }, predicate ); // $ExpectType float64ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'float64' }, predicate, {} ); // $ExpectType float64ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'float32' }, predicate ); // $ExpectType float32ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'float32' }, predicate, {} ); // $ExpectType float32ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'complex64' }, predicate ); // $ExpectType complex64ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'complex64' }, predicate, {} ); // $ExpectType complex64ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'complex128' }, predicate ); // $ExpectType complex128ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'complex128' }, predicate, {} ); // $ExpectType complex128ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'int32' }, predicate ); // $ExpectType int32ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'int32' }, predicate, {} ); // $ExpectType int32ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'int16' }, predicate ); // $ExpectType int16ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'int16' }, predicate, {} ); // $ExpectType int16ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'int8' }, predicate ); // $ExpectType int8ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'int8' }, predicate, {} ); // $ExpectType int8ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint32' }, predicate ); // $ExpectType uint32ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint32' }, predicate, {} ); // $ExpectType uint32ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint16' }, predicate ); // $ExpectType uint16ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint16' }, predicate, {} ); // $ExpectType uint16ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint8' }, predicate ); // $ExpectType uint8ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint8' }, predicate, {} ); // $ExpectType uint8ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint8c' }, predicate ); // $ExpectType uint8cndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint8c' }, predicate, {} ); // $ExpectType uint8cndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'bool' }, predicate ); // $ExpectType boolndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'bool' }, predicate, {} ); // $ExpectType boolndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'generic' }, predicate ); // $ExpectType genericndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'generic' }, predicate, {} ); // $ExpectType genericndarray - - - filter( zeros( 'float64', sh, ord ), { 'order': ord }, predicate ); // $ExpectType float64ndarray - filter( zeros( 'float64', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType float64ndarray - filter( zeros( 'float32', sh, ord ), { 'order': ord }, predicate ); // $ExpectType float32ndarray - filter( zeros( 'float32', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType float32ndarray - filter( zeros( 'complex64', sh, ord ), { 'order': ord }, predicate ); // $ExpectType complex64ndarray - filter( zeros( 'complex64', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType complex64ndarray - filter( zeros( 'complex128', sh, ord ), { 'order': ord }, predicate ); // $ExpectType complex128ndarray - filter( zeros( 'complex128', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType complex128ndarray - filter( zeros( 'int32', sh, ord ), { 'order': ord }, predicate ); // $ExpectType int32ndarray - filter( zeros( 'int32', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType int32ndarray - filter( zeros( 'int16', sh, ord ), { 'order': ord }, predicate ); // $ExpectType int16ndarray - filter( zeros( 'int16', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType int16ndarray - filter( zeros( 'int8', sh, ord ), { 'order': ord }, predicate ); // $ExpectType int8ndarray - filter( zeros( 'int8', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType int8ndarray - filter( zeros( 'uint32', sh, ord ), { 'order': ord }, predicate ); // $ExpectType uint32ndarray - filter( zeros( 'uint32', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType uint32ndarray - filter( zeros( 'uint16', sh, ord ), { 'order': ord }, predicate ); // $ExpectType uint16ndarray - filter( zeros( 'uint16', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType uint16ndarray - filter( zeros( 'uint8', sh, ord ), { 'order': ord }, predicate ); // $ExpectType uint8ndarray - filter( zeros( 'uint8', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType uint8ndarray - filter( zeros( 'uint8c', sh, ord ), { 'order': ord }, predicate ); // $ExpectType uint8cndarray - filter( zeros( 'uint8c', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType uint8cndarray - filter( empty( 'bool', sh, ord ), { 'order': ord }, predicate ); // $ExpectType boolndarray - filter( empty( 'bool', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType boolndarray - filter( zeros( 'generic', sh, ord ), { 'order': ord }, predicate ); // $ExpectType genericndarray - filter( zeros( 'generic', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType genericndarray - -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - filter( 5, predicate ); // $ExpectError - filter( true, predicate ); // $ExpectError - filter( false, predicate ); // $ExpectError - filter( null, predicate ); // $ExpectError - filter( undefined, predicate ); // $ExpectError - filter( {}, predicate ); // $ExpectError - filter( [ 1 ], predicate ); // $ExpectError - filter( ( x: number ): number => x, predicate ); // $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' ); - - filter( x, '5' ); // $ExpectError - filter( x, true ); // $ExpectError - filter( x, false ); // $ExpectError - filter( x, null ); // $ExpectError - filter( x, undefined ); // $ExpectError - filter( x, {} ); // $ExpectError - filter( 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' ); - - filter( x, '10', predicate, {} ); // $ExpectError - filter( x, 10, predicate, {} ); // $ExpectError - filter( x, false, predicate, {} ); // $ExpectError - filter( x, true, predicate, {} ); // $ExpectError - filter( x, [], predicate, {} ); // $ExpectError - filter( x, ( x: number ): number => x, predicate, {} ); // $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' ); - - filter( x, { 'dtype': '10' }, predicate ); // $ExpectError - filter( x, { 'dtype': 10 }, predicate ); // $ExpectError - filter( x, { 'dtype': null }, predicate ); // $ExpectError - filter( x, { 'dtype': false }, predicate ); // $ExpectError - filter( x, { 'dtype': true }, predicate ); // $ExpectError - filter( x, { 'dtype': [] }, predicate ); // $ExpectError - filter( x, { 'dtype': {} }, predicate ); // $ExpectError - filter( x, { 'dtype': ( x: number ): number => x }, predicate ); // $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' ); - - filter( x, { 'order': '10' }, predicate ); // $ExpectError - filter( x, { 'order': 10 }, predicate ); // $ExpectError - filter( x, { 'order': null }, predicate ); // $ExpectError - filter( x, { 'order': false }, predicate ); // $ExpectError - filter( x, { 'order': true }, predicate ); // $ExpectError - filter( x, { 'order': [] }, predicate ); // $ExpectError - filter( x, { 'order': {} }, predicate ); // $ExpectError - filter( x, { 'order': ( x: number ): number => x }, predicate ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - filter(); // $ExpectError - filter( zeros( 'float64', [ 2, 2 ], 'row-major' ) ); // $ExpectError - filter( 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 e2dd6cb..0000000 --- a/examples/index.js +++ /dev/null @@ -1,38 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var array = require( '@stdlib/ndarray-array' ); -var isPositive = require( '@stdlib/assert-is-positive-number' ).isPrimitive; -var filter = require( './../lib' ); - -var buffer = discreteUniform( 10, -100, 100, { - 'dtype': 'generic' -}); -var x = array( buffer, { - 'shape': [ 5, 2 ], - 'dtype': 'generic' -}); -console.log( ndarray2array( x ) ); - -var y = filter( x, naryFunction( isPositive, 1 ) ); -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 c4dadbe..7f6ff4a 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..483f25f --- /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)),D=v.get.apply(v,B),w.call(T,D,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..2c1ae93 --- /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* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate 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 {boolean} [options.order] - index iteration order\n* @param {Callback} predicate - predicate function\n* @param {*} [thisArg] - predicate 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 { isPrimitive as isEven } from '@stdlib/assert-is-even';\n* import Float64Array from '@stdlib/array-float64';\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndarray2array from '@stdlib/ndarray-to-array';\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 = filter( x, isEven );\n* // returns \n*\n* var arr = ndarray2array( y );\n* // returns [ 2.0, 4.0, 8.0, 10.0 ]\n*/\nfunction filter( x, options, predicate, 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 = predicate;\n\t\t} else {\n\t\t\thasOpts = true;\n\t\t\topts = options;\n\t\t\tclbk = predicate;\n\t\t}\n\t} else {\n\t\thasOpts = true;\n\t\topts = options;\n\t\tclbk = predicate;\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 predicate 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 elements according to a predicate 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 = x.get.apply( x, idx );\n\t\tif ( clbk.call( ctx, v, idx.slice(), x ) ) {\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 filter;\n"],"names":["filter","x","options","predicate","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","get","apply","call","slice","gcopy","constructor"],"mappings":";;6zCA0EA,SAASA,EAAQC,EAAGC,EAASC,EAAWC,GACvC,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,IAE9CK,EAAIlB,EAAEsC,IAAIC,MAAOvC,EAAGa,GACfN,EAAKiC,KAAM9B,EAAKQ,EAAGL,EAAI4B,QAASzC,KACpCM,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 46f5998..0000000 --- a/lib/index.js +++ /dev/null @@ -1,55 +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'; - -/** -* Return a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @module @stdlib/ndarray-filter -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var filter = require( '@stdlib/ndarray-filter' ); -* -* 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 = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.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 3cd50e0..0000000 --- a/lib/main.js +++ /dev/null @@ -1,196 +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/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param {ndarray} x - input ndarray -* @param {Options} [options] - function options -* @param {string} [options.dtype] - output array data type -* @param {boolean} [options.order] - index iteration order -* @param {Callback} predicate - predicate function -* @param {*} [thisArg] - predicate 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 isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -function filter( x, options, predicate, 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( 'null5t', x ) ); - } - if ( arguments.length < 3 ) { - clbk = options; - } else if ( arguments.length === 3 ) { - if ( isFunction( options ) ) { - clbk = options; - ctx = predicate; - } else { - hasOpts = true; - opts = options; - clbk = predicate; - } - } else { - hasOpts = true; - opts = options; - clbk = predicate; - ctx = thisArg; - } - if ( !isFunction( clbk ) ) { - throw new TypeError( format( 'null2b', clbk ) ); - } - if ( hasOpts ) { - if ( !isPlainObject( opts ) ) { - throw new TypeError( format( 'null2V', opts ) ); - } - if ( hasOwnProp( opts, 'dtype' ) ) { - dt = opts.dtype; - } else { - dt = getDType( x ); - } - if ( hasOwnProp( opts, 'order' ) ) { - if ( !isOrder( opts.order ) ) { - throw new TypeError( format( 'null5C', '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( 'nullBf', '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 predicate 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 elements according to a predicate function... - for ( i = 0; i < N; i++ ) { - if ( i > 0 ) { - idx = nextCartesianIndex( sh, ord, idx, dim, idx ); - } - v = x.get.apply( x, idx ); - if ( clbk.call( ctx, v, idx.slice(), x ) ) { - 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 = filter; diff --git a/package.json b/package.json index a44b313..2473eda 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Return a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate 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,62 +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/error-tools-fmtprodmsg": "^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-positive-number": "^0.2.2", - "@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", - "@stdlib/utils-nary-function": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "strided", @@ -104,7 +25,6 @@ "select", "take" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..135eeac --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Codestin Search App + + + +
+ + + + + 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 3bea6b3..0000000 --- a/test/test.js +++ /dev/null @@ -1,892 +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 filter = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof filter, '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() { - filter( value, predicate ); - }; - } - - function predicate( z ) { - return ( z > 0.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() { - filter( 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() { - filter( 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() { - filter( x, value, predicate ); - }; - } - - function predicate( z ) { - return ( z > 0.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 - }; - filter( x, opts, predicate ); - }; - } - - function predicate( z ) { - return ( z > 0.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 - }; - filter( x, opts, predicate ); - }; - } - - function predicate( z ) { - return ( z > 0.0 ); - } -}); - -tape( 'the function filters an array according to a predicate 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 = filter( x, predicate ); - - expected = new Float64Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - - t.end(); - - function predicate( z ) { - return ( z > 0.0 ); - } -}); - -tape( 'the function filters an array according to a predicate 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 = filter( x, predicate ); - - expected = new Float64Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - - t.end(); - - function predicate( z ) { - return ( z > 0.0 ); - } -}); - -tape( 'the function filters an array according to a predicate 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 = filter( x, opts, predicate ); - - expected = new Float64Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - - opts = { - 'dtype': 'float32' - }; - y = filter( x, opts, predicate ); - - expected = new Float32Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat32Array( y.data, expected ), true, 'returns expected value' ); - - t.end(); - - function predicate( z ) { - return ( z > 0.0 ); - } -}); - -tape( 'the function filters an array according to a predicate 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 = filter( x, opts, predicate ); - - expected = new Float64Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - - opts = { - 'dtype': 'float32' - }; - y = filter( x, opts, predicate ); - - expected = new Float32Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat32Array( y.data, expected ), true, 'returns expected value' ); - - t.end(); - - function predicate( z ) { - return ( z > 0.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 = filter( x, predicate, ctx ); - - expected = new Float64Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function predicate( z ) { - this.count += 1; // eslint-disable-line no-invalid-this - return ( z > 0.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 = filter( x, {}, predicate, ctx ); - - expected = new Float64Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function predicate( z ) { - this.count += 1; // eslint-disable-line no-invalid-this - return ( z > 0.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 = filter( x, predicate ); - - expected = new Float64Array([ - 1.0, - 3.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 predicate( z, idx, arr ) { - values.push( z ); - indices.push( idx ); - arrays.push( arr ); - return ( z > 0.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 = filter( x, predicate ); - - expected = new Float64Array([ - 1.0, - 3.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 predicate( z, idx, arr ) { - values.push( z ); - indices.push( idx ); - arrays.push( arr ); - return ( z > 0.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 = filter( x, opts, predicate ); - - expected = new Float64Array([ - 1.0, - 3.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 predicate( z, idx, arr ) { - values.push( z ); - indices.push( idx ); - arrays.push( arr ); - return ( z > 0.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 = filter( x, opts, predicate ); - - expected = new Float64Array([ - 1.0, - 3.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 predicate( z, idx, arr ) { - values.push( z ); - indices.push( idx ); - arrays.push( arr ); - return ( z > 0.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 = filter( x, opts, predicate ); - - expected = new Float64Array([ - 1.0, - 3.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 predicate( z, idx, arr ) { - values.push( z ); - indices.push( idx ); - arrays.push( arr ); - return ( z > 0.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 = filter( x, opts, predicate ); - - expected = new Float64Array([ - 1.0, - 3.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 predicate( z, idx, arr ) { - values.push( z ); - indices.push( idx ); - arrays.push( arr ); - return ( z > 0.0 ); - } -}); From d16d4c607f3691455b8e5d63995d976d8ab4b960 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 2 Feb 2025 15:08:34 +0000 Subject: [PATCH 30/35] Transform error messages --- lib/main.js | 12 ++++++------ package.json | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/main.js b/lib/main.js index 6ad824e..3cd50e0 100644 --- a/lib/main.js +++ b/lib/main.js @@ -33,7 +33,7 @@ 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' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -91,7 +91,7 @@ function filter( x, options, predicate, thisArg ) { var v; var i; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray-like object. Value: `%s`.', x ) ); + throw new TypeError( format( 'null5t', x ) ); } if ( arguments.length < 3 ) { clbk = options; @@ -111,11 +111,11 @@ function filter( x, options, predicate, thisArg ) { ctx = thisArg; } if ( !isFunction( clbk ) ) { - throw new TypeError( format( 'invalid argument. Callback argument must be a function. Value: `%s`.', clbk ) ); + throw new TypeError( format( 'null2b', clbk ) ); } if ( hasOpts ) { if ( !isPlainObject( opts ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) ); + throw new TypeError( format( 'null2V', opts ) ); } if ( hasOwnProp( opts, 'dtype' ) ) { dt = opts.dtype; @@ -124,7 +124,7 @@ function filter( x, options, predicate, thisArg ) { } 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 ) ); + throw new TypeError( format( 'null5C', 'order', opts.order ) ); } ord = opts.order; } @@ -135,7 +135,7 @@ function filter( x, options, predicate, thisArg ) { 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 ) ); + throw new TypeError( format( 'nullBf', 'dtype', opts.dtype ) ); } // Resolve the iteration order: if ( ord === void 0 ) { diff --git a/package.json b/package.json index 22065aa..a44b313 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@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/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From 1f822c99ee14a0f33863e5436efc76cfc0af4814 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 2 Feb 2025 15:23:14 +0000 Subject: [PATCH 31/35] Remove files --- index.d.ts | 1612 ---------------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 6459 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 7f6ff4a..0000000 --- a/index.d.ts +++ /dev/null @@ -1,1612 +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. -*/ - -// TypeScript Version: 4.1 - -/// - -/* eslint-disable max-lines */ - -import { typedndarray, DataType, Order, float64ndarray, float32ndarray, complex128ndarray, complex64ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, boolndarray, genericndarray } from '@stdlib/types/ndarray'; -import { Complex64, Complex128 } from '@stdlib/types/complex'; - -/** -* Returns a boolean indicating whether an element passes a test. -* -* @returns boolean indicating whether an element passes a test -*/ -type Nullary = ( this: V ) => boolean; - -/** -* Returns a boolean indicating whether an element passes a test. -* -* @param value - current array element -* @returns boolean indicating whether an element passes a test -*/ -type Unary = ( this: V, value: T ) => boolean; - -/** -* Returns a boolean indicating whether an element passes a test. -* -* @param value - current array element -* @param indices - current array element indices -* @returns boolean indicating whether an element passes a test -*/ -type Binary = ( this: V, value: T, indices: Array ) => boolean; - -/** -* Returns a boolean indicating whether an element passes a test. -* -* @param value - current array element -* @param indices - current array element indices -* @param arr - input array -* @returns boolean indicating whether an element passes a test -*/ -type Ternary = ( this: V, value: T, indices: Array, arr: typedndarray ) => boolean; - -/** -* Returns a boolean indicating whether an element passes a test. -* -* @param value - current array element -* @param indices - current array element indices -* @param arr - input array -* @returns boolean indicating whether an element passes a test -*/ -type Predicate = Nullary | Unary | Binary | Ternary; - -/** -* Interface describing "base" function options. -*/ -interface BaseOptions { - /** - * Index iteration order. - * - * ## Notes - * - * - By default, the function iterates over elements according to the layout order of the provided ndarray. Accordingly, for row-major input ndarrays, the last dimension indices increment fastest. For column-major input ndarrays, the first dimension indices increment fastest. To override the inferred order and ensure that indices increment in a specific manner, regardless of the input ndarray's layout order, explicitly set the iteration order. Note, however, that iterating according to an order which does not match that of the input ndarray may, in some circumstances, result in performance degradation due to cache misses. - */ - order?: Order; -} - -/** -* Interface describing function options. -*/ -interface OrderOptions { - /** - * Index iteration order. - * - * ## Notes - * - * - By default, the function iterates over elements according to the layout order of the provided ndarray. Accordingly, for row-major input ndarrays, the last dimension indices increment fastest. For column-major input ndarrays, the first dimension indices increment fastest. To override the inferred order and ensure that indices increment in a specific manner, regardless of the input ndarray's layout order, explicitly set the iteration order. Note, however, that iterating according to an order which does not match that of the input ndarray may, in some circumstances, result in performance degradation due to cache misses. - */ - order: Order; -} - -/** -* Interface describing function options. -*/ -interface Options extends BaseOptions { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: DataType; -} - -/** -* Interface describing function options. -*/ -interface Float64Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'float64'; -} - -/** -* Interface describing function options. -*/ -interface Float32Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'float32'; -} - -/** -* Interface describing function options. -*/ -interface Complex128Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'complex128'; -} - -/** -* Interface describing function options. -*/ -interface Complex64Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'complex64'; -} - -/** -* Interface describing function options. -*/ -interface Int32Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'int32'; -} - -/** -* Interface describing function options. -*/ -interface Int16Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'int16'; -} - -/** -* Interface describing function options. -*/ -interface Int8Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'int8'; -} - -/** -* Interface describing function options. -*/ -interface Uint32Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'uint32'; -} - -/** -* Interface describing function options. -*/ -interface Uint16Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'uint16'; -} - -/** -* Interface describing function options. -*/ -interface Uint8Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'uint8'; -} - -/** -* Interface describing function options. -*/ -interface Uint8COptions extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'uint8c'; -} - -/** -* Interface describing function options. -*/ -interface BoolOptions extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'bool'; -} - -/** -* Interface describing function options. -*/ -interface GenericOptions extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'generic'; -} - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: float64ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): float64ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float32Array = require( '@stdlib/array-float32' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Float32Array( [ 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( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: float32ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): float32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var Complex64Array = require( '@stdlib/array-complex64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* function predicate( z, idx ) { -* return idx[ 0 ] > 0; -* } -* -* var buffer = new Complex64Array( [ 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 = [ 3, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, predicate ); -* // returns -*/ -declare function filter( x: complex64ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): complex64ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* function predicate( z, idx ) { -* return idx[ 0 ] > 0; -* } -* -* var buffer = new Complex128Array( [ 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 = [ 3, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, predicate ); -* // returns -*/ -declare function filter( x: complex128ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): complex128ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Int32Array = require( '@stdlib/array-int32' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Int32Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: int32ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): int32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Int16Array = require( '@stdlib/array-int16' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Int16Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: int16ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): int16ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Int8Array = require( '@stdlib/array-int8' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Int8Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: int8ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): int8ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint32Array = require( '@stdlib/array-uint32' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint32Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint32ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): uint32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint16Array = require( '@stdlib/array-uint16' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint16Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint16ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): uint16ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint8Array = require( '@stdlib/array-uint8' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint8Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint8ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): uint8ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint8ClampedArray( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint8cndarray, predicate: Predicate, thisArg?: ThisParameterType> ): uint8cndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var BooleanArray = require( '@stdlib/array-bool' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* function predicate( z ) { -* return z; -* } -* -* var buffer = new BooleanArray( [ false, true, false, true, false, true, false, true, false, true, false, true ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'bool', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, predicate ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ true, true, true, true ] -*/ -declare function filter( x: boolndarray, predicate: Predicate, thisArg?: ThisParameterType> ): boolndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 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( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: genericndarray, predicate: Predicate, thisArg?: ThisParameterType> ): genericndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: float64ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): float64ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float32Array = require( '@stdlib/array-float32' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Float32Array( [ 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( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: float32ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): float32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var Complex64Array = require( '@stdlib/array-complex64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* function predicate( z, idx ) { -* return idx[ 0 ] > 0; -* } -* -* var buffer = new Complex64Array( [ 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 = [ 3, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, predicate ); -* // returns -*/ -declare function filter( x: complex64ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): complex64ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* function predicate( z, idx ) { -* return idx[ 0 ] > 0; -* } -* -* var buffer = new Complex128Array( [ 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 = [ 3, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, predicate ); -* // returns -*/ -declare function filter( x: complex128ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): complex128ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Int32Array = require( '@stdlib/array-int32' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Int32Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: int32ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): int32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Int16Array = require( '@stdlib/array-int16' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Int16Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: int16ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): int16ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Int8Array = require( '@stdlib/array-int8' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Int8Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: int8ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): int8ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint32Array = require( '@stdlib/array-uint32' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint32Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint32ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): uint32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint16Array = require( '@stdlib/array-uint16' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint16Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint16ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): uint16ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint8Array = require( '@stdlib/array-uint8' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint8Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint8ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): uint8ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint8ClampedArray( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint8cndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): uint8cndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var BooleanArray = require( '@stdlib/array-bool' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* function predicate( z ) { -* return z; -* } -* -* var buffer = new BooleanArray( [ false, true, false, true, false, true, false, true, false, true, false, true ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'bool', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, predicate ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ true, true, true, true ] -*/ -declare function filter( x: boolndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): boolndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 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( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: genericndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): genericndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'float64' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: typedndarray, options: Float64Options, predicate: Predicate, thisArg?: ThisParameterType> ): float64ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'float32' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: typedndarray, options: Float32Options, predicate: Predicate, thisArg?: ThisParameterType> ): float32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* function predicate( z, idx ) { -* return idx[ 0 ] > 0; -* } -* -* var buffer = new Complex128Array( [ 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 = [ 3, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'dtype': 'complex128' -* }; -* var y = filter( x, opts, predicate ); -* // returns -*/ -declare function filter( x: typedndarray, options: Complex128Options, predicate: Predicate, thisArg?: ThisParameterType> ): complex128ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* function predicate( z, idx ) { -* return idx[ 0 ] > 0; -* } -* -* var buffer = new Complex128Array( [ 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 = [ 3, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'dtype': 'complex64' -* }; -* var y = filter( x, opts, predicate ); -* // returns -*/ -declare function filter( x: typedndarray, options: Complex64Options, predicate: Predicate, thisArg?: ThisParameterType> ): complex64ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'int32' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: typedndarray, options: Int32Options, predicate: Predicate, thisArg?: ThisParameterType> ): int32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'int16' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: typedndarray, options: Int16Options, predicate: Predicate, thisArg?: ThisParameterType> ): int16ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'int8' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: typedndarray, options: Int8Options, predicate: Predicate, thisArg?: ThisParameterType> ): int8ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'uint32' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: typedndarray, options: Uint32Options, predicate: Predicate, thisArg?: ThisParameterType> ): uint32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'uint16' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: typedndarray, options: Uint16Options, predicate: Predicate, thisArg?: ThisParameterType> ): uint16ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'uint8' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: typedndarray, options: Uint8Options, predicate: Predicate, thisArg?: ThisParameterType> ): uint8ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'uint8c' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: typedndarray, options: Uint8COptions, predicate: Predicate, thisArg?: ThisParameterType> ): uint8cndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'bool' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ true, true, true, true ] -*/ -declare function filter( x: typedndarray, options: BoolOptions, predicate: Predicate, thisArg?: ThisParameterType> ): boolndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'generic' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: typedndarray, options: GenericOptions, predicate: Predicate, thisArg?: ThisParameterType> ): genericndarray; - - -// EXPORTS // - -export = filter; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 483f25f..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import 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)),D=v.get.apply(v,B),w.call(T,D,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 deleted file mode 100644 index 2c1ae93..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 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* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate 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 {boolean} [options.order] - index iteration order\n* @param {Callback} predicate - predicate function\n* @param {*} [thisArg] - predicate 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 { isPrimitive as isEven } from '@stdlib/assert-is-even';\n* import Float64Array from '@stdlib/array-float64';\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndarray2array from '@stdlib/ndarray-to-array';\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 = filter( x, isEven );\n* // returns \n*\n* var arr = ndarray2array( y );\n* // returns [ 2.0, 4.0, 8.0, 10.0 ]\n*/\nfunction filter( x, options, predicate, 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 = predicate;\n\t\t} else {\n\t\t\thasOpts = true;\n\t\t\topts = options;\n\t\t\tclbk = predicate;\n\t\t}\n\t} else {\n\t\thasOpts = true;\n\t\topts = options;\n\t\tclbk = predicate;\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 predicate 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 elements according to a predicate 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 = x.get.apply( x, idx );\n\t\tif ( clbk.call( ctx, v, idx.slice(), x ) ) {\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 filter;\n"],"names":["filter","x","options","predicate","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","get","apply","call","slice","gcopy","constructor"],"mappings":";;6zCA0EA,SAASA,EAAQC,EAAGC,EAASC,EAAWC,GACvC,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,IAE9CK,EAAIlB,EAAEsC,IAAIC,MAAOvC,EAAGa,GACfN,EAAKiC,KAAM9B,EAAKQ,EAAGL,EAAI4B,QAASzC,KACpCM,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/stats.html b/stats.html deleted file mode 100644 index 135eeac..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Codestin Search App - - - -
- - - - - From 47d648a2608f32c0348f1f0af5ec75e85b43fbc4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 2 Feb 2025 15:24:01 +0000 Subject: [PATCH 32/35] Auto-generated commit --- .editorconfig | 180 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 57 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 79 +- SECURITY.md | 5 - benchmark/benchmark.1d.js | 150 - benchmark/benchmark.2d.js | 161 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 51 - docs/types/test.ts | 195 - examples/index.js | 38 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 55 - lib/main.js | 196 - package.json | 84 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 892 ---- 45 files changed, 4885 insertions(+), 5325 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.1d.js delete mode 100644 benchmark/benchmark.2d.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index dab5d2a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,180 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 54a0327..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-02-02T15:04:07.791Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 03a0613..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) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 48af73a..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) 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 443f7ec..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: '9 21 * * 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 + + ```
@@ -257,7 +248,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]. @@ -320,21 +311,21 @@ Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-filter/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-map]: https://github.com/stdlib-js/ndarray-filter-map +[@stdlib/ndarray/filter-map]: https://github.com/stdlib-js/ndarray-filter-map/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 6958f29..0000000 --- a/benchmark/benchmark.1d.js +++ /dev/null @@ -1,150 +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 filter = require( './../lib' ); - - -// VARIABLES // - -var xtypes = [ 'generic' ]; -var ytypes = [ 'float64' ]; -var orders = [ 'row-major', 'column-major' ]; - - -// FUNCTIONS // - -/** -* Predicate function. -* -* @private -* @param {number} value - array element -* @param {NonNegativeIntegerArray} indices - element indices -* @param {ndarray} arr - input array -* @returns {boolean} result -*/ -function predicate( value ) { - return value > 0.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 = filter( x, opts, predicate ); - 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 c70a9f1..0000000 --- a/benchmark/benchmark.2d.js +++ /dev/null @@ -1,161 +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 filter = require( './../lib' ); - - -// VARIABLES // - -var xtypes = [ 'generic' ]; -var ytypes = [ 'float64' ]; -var orders = [ 'row-major', 'column-major' ]; - - -// FUNCTIONS // - -/** -* Predicate function. -* -* @private -* @param {number} value - array element -* @param {NonNegativeIntegerArray} indices - element indices -* @param {ndarray} arr - input array -* @returns {boolean} result -*/ -function predicate( value ) { - return value > 0.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 = filter( x, opts, predicate ); - 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 51e4f91..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" -%% click B href "https://github.com/stdlib-js/ndarray-filter/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-filter/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-filter/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-filter/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-filter/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/filter -[production-url]: https://github.com/stdlib-js/ndarray-filter/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-filter/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-filter/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-filter/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-filter/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-filter/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-filter/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 aafb9cb..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import filter from '../docs/types/index'; -export = filter; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index b5b2378..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(J,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"),N=require("@stdlib/ndarray-base-numel"),S=require("@stdlib/ndarray-base-next-cartesian-index").assign,A=require("@stdlib/blas-base-gcopy"),v=require("@stdlib/string-format");function B(r,a,g,k){var f,p,t,i,e,c,m,n,h,u,y,s,l,o,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=g):(f=!0,e=a,i=g):(f=!0,e=a,i=g,m=k),!b(i))throw new TypeError(v("invalid argument. Callback argument must be a function. Value: `%s`.",i));if(f){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(c=P(s),c===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),o=N(l),p=l.length,n==="row-major"?h=p-1:h=0,u=D(p),t={length:0},d=0;d0&&(u=S(l,n,u,h,u)),q=r.get.apply(r,u),i.call(m,q,u.slice(),r)&&(t[t.length]=q,t.length+=1);return o=t.length,y=new c(o),A(o,t,1,y,1),w=new r.constructor(s,y,[o],[1],0,n),w}E.exports=B});var G=j();module.exports=G; -/** -* @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 cfadd98..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* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate 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 {boolean} [options.order] - index iteration order\n* @param {Callback} predicate - predicate function\n* @param {*} [thisArg] - predicate 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 isEven = require( '@stdlib/assert-is-even' ).isPrimitive;\n* var Float64Array = require( '@stdlib/array-float64' );\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\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 = filter( x, isEven );\n* // returns \n*\n* var arr = ndarray2array( y );\n* // returns [ 2.0, 4.0, 8.0, 10.0 ]\n*/\nfunction filter( x, options, predicate, 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 = predicate;\n\t\t} else {\n\t\t\thasOpts = true;\n\t\t\topts = options;\n\t\t\tclbk = predicate;\n\t\t}\n\t} else {\n\t\thasOpts = true;\n\t\topts = options;\n\t\tclbk = predicate;\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 predicate 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 elements according to a predicate 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 = x.get.apply( x, idx );\n\t\tif ( clbk.call( ctx, v, idx.slice(), x ) ) {\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 = filter;\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* Return a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function.\n*\n* @module @stdlib/ndarray-filter\n*\n* @example\n* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive;\n* var Float64Array = require( '@stdlib/array-float64' );\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var filter = require( '@stdlib/ndarray-filter' );\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 = filter( x, isEven );\n* // returns \n*\n* var arr = ndarray2array( y );\n* // returns [ 2.0, 4.0, 8.0, 10.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,EAuC9C,SAASC,EAAQC,EAAGC,EAASC,EAAWC,EAAU,CACjD,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,EAAInB,EAAE,IAAI,MAAOA,EAAGa,CAAI,EACnBN,EAAK,KAAMG,EAAKS,EAAGN,EAAI,MAAM,EAAGb,CAAE,IACtCM,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", "filter", "x", "options", "predicate", "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 75de7ed..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,51 +0,0 @@ - -{{alias}}( x[, options], predicate[, thisArg] ) - Returns a shallow copy of an ndarray containing only those elements which - pass a test implemented by a predicate function. - - The predicate function is provided the following arguments: - - - value: current array element. - - indices: current array element indices. - - arr: the input 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'. - - predicate: Function - Predicate function. - - thisArg: any (optional) - Predicate function execution context. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ); - > function f( v ) { return v > 2.0; }; - > var y = {{alias}}( x, f ); - > {{alias:@stdlib/ndarray/to-array}}( y ) - [ 3.0, 4.0 ] - - See Also - -------- diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 046dffb..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,195 +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 empty = require( '@stdlib/ndarray-base-empty' ); -import zeros = require( '@stdlib/ndarray-base-zeros' ); -import filter = require( './index' ); - -/** -* Predicate function. -* -* @param x - input value -* @returns result -*/ -function predicate( x: any ): boolean { - return Boolean( x ); -} - -// The function returns an ndarray... -{ - const sh = [ 2, 2 ]; - const ord = 'row-major'; - - filter( zeros( 'float64', sh, ord ), predicate ); // $ExpectType float64ndarray - filter( zeros( 'float64', sh, ord ), predicate, {} ); // $ExpectType float64ndarray - filter( zeros( 'float32', sh, ord ), predicate ); // $ExpectType float32ndarray - filter( zeros( 'float32', sh, ord ), predicate, {} ); // $ExpectType float32ndarray - filter( zeros( 'complex64', sh, ord ), predicate ); // $ExpectType complex64ndarray - filter( zeros( 'complex64', sh, ord ), predicate, {} ); // $ExpectType complex64ndarray - filter( zeros( 'complex128', sh, ord ), predicate ); // $ExpectType complex128ndarray - filter( zeros( 'complex128', sh, ord ), predicate, {} ); // $ExpectType complex128ndarray - filter( zeros( 'int32', sh, ord ), predicate ); // $ExpectType int32ndarray - filter( zeros( 'int32', sh, ord ), predicate, {} ); // $ExpectType int32ndarray - filter( zeros( 'int16', sh, ord ), predicate ); // $ExpectType int16ndarray - filter( zeros( 'int16', sh, ord ), predicate, {} ); // $ExpectType int16ndarray - filter( zeros( 'int8', sh, ord ), predicate ); // $ExpectType int8ndarray - filter( zeros( 'int8', sh, ord ), predicate, {} ); // $ExpectType int8ndarray - filter( zeros( 'uint32', sh, ord ), predicate ); // $ExpectType uint32ndarray - filter( zeros( 'uint32', sh, ord ), predicate, {} ); // $ExpectType uint32ndarray - filter( zeros( 'uint16', sh, ord ), predicate ); // $ExpectType uint16ndarray - filter( zeros( 'uint16', sh, ord ), predicate, {} ); // $ExpectType uint16ndarray - filter( zeros( 'uint8', sh, ord ), predicate ); // $ExpectType uint8ndarray - filter( zeros( 'uint8', sh, ord ), predicate, {} ); // $ExpectType uint8ndarray - filter( zeros( 'uint8c', sh, ord ), predicate ); // $ExpectType uint8cndarray - filter( zeros( 'uint8c', sh, ord ), predicate, {} ); // $ExpectType uint8cndarray - filter( empty( 'bool', sh, ord ), predicate ); // $ExpectType boolndarray - filter( empty( 'bool', sh, ord ), predicate, {} ); // $ExpectType boolndarray - filter( zeros( 'generic', sh, ord ), predicate ); // $ExpectType genericndarray - filter( zeros( 'generic', sh, ord ), predicate, {} ); // $ExpectType genericndarray - - - filter( zeros( 'generic', sh, ord ), { 'dtype': 'float64' }, predicate ); // $ExpectType float64ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'float64' }, predicate, {} ); // $ExpectType float64ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'float32' }, predicate ); // $ExpectType float32ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'float32' }, predicate, {} ); // $ExpectType float32ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'complex64' }, predicate ); // $ExpectType complex64ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'complex64' }, predicate, {} ); // $ExpectType complex64ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'complex128' }, predicate ); // $ExpectType complex128ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'complex128' }, predicate, {} ); // $ExpectType complex128ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'int32' }, predicate ); // $ExpectType int32ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'int32' }, predicate, {} ); // $ExpectType int32ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'int16' }, predicate ); // $ExpectType int16ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'int16' }, predicate, {} ); // $ExpectType int16ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'int8' }, predicate ); // $ExpectType int8ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'int8' }, predicate, {} ); // $ExpectType int8ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint32' }, predicate ); // $ExpectType uint32ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint32' }, predicate, {} ); // $ExpectType uint32ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint16' }, predicate ); // $ExpectType uint16ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint16' }, predicate, {} ); // $ExpectType uint16ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint8' }, predicate ); // $ExpectType uint8ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint8' }, predicate, {} ); // $ExpectType uint8ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint8c' }, predicate ); // $ExpectType uint8cndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint8c' }, predicate, {} ); // $ExpectType uint8cndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'bool' }, predicate ); // $ExpectType boolndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'bool' }, predicate, {} ); // $ExpectType boolndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'generic' }, predicate ); // $ExpectType genericndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'generic' }, predicate, {} ); // $ExpectType genericndarray - - - filter( zeros( 'float64', sh, ord ), { 'order': ord }, predicate ); // $ExpectType float64ndarray - filter( zeros( 'float64', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType float64ndarray - filter( zeros( 'float32', sh, ord ), { 'order': ord }, predicate ); // $ExpectType float32ndarray - filter( zeros( 'float32', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType float32ndarray - filter( zeros( 'complex64', sh, ord ), { 'order': ord }, predicate ); // $ExpectType complex64ndarray - filter( zeros( 'complex64', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType complex64ndarray - filter( zeros( 'complex128', sh, ord ), { 'order': ord }, predicate ); // $ExpectType complex128ndarray - filter( zeros( 'complex128', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType complex128ndarray - filter( zeros( 'int32', sh, ord ), { 'order': ord }, predicate ); // $ExpectType int32ndarray - filter( zeros( 'int32', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType int32ndarray - filter( zeros( 'int16', sh, ord ), { 'order': ord }, predicate ); // $ExpectType int16ndarray - filter( zeros( 'int16', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType int16ndarray - filter( zeros( 'int8', sh, ord ), { 'order': ord }, predicate ); // $ExpectType int8ndarray - filter( zeros( 'int8', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType int8ndarray - filter( zeros( 'uint32', sh, ord ), { 'order': ord }, predicate ); // $ExpectType uint32ndarray - filter( zeros( 'uint32', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType uint32ndarray - filter( zeros( 'uint16', sh, ord ), { 'order': ord }, predicate ); // $ExpectType uint16ndarray - filter( zeros( 'uint16', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType uint16ndarray - filter( zeros( 'uint8', sh, ord ), { 'order': ord }, predicate ); // $ExpectType uint8ndarray - filter( zeros( 'uint8', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType uint8ndarray - filter( zeros( 'uint8c', sh, ord ), { 'order': ord }, predicate ); // $ExpectType uint8cndarray - filter( zeros( 'uint8c', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType uint8cndarray - filter( empty( 'bool', sh, ord ), { 'order': ord }, predicate ); // $ExpectType boolndarray - filter( empty( 'bool', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType boolndarray - filter( zeros( 'generic', sh, ord ), { 'order': ord }, predicate ); // $ExpectType genericndarray - filter( zeros( 'generic', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType genericndarray - -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - filter( 5, predicate ); // $ExpectError - filter( true, predicate ); // $ExpectError - filter( false, predicate ); // $ExpectError - filter( null, predicate ); // $ExpectError - filter( undefined, predicate ); // $ExpectError - filter( {}, predicate ); // $ExpectError - filter( [ 1 ], predicate ); // $ExpectError - filter( ( x: number ): number => x, predicate ); // $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' ); - - filter( x, '5' ); // $ExpectError - filter( x, true ); // $ExpectError - filter( x, false ); // $ExpectError - filter( x, null ); // $ExpectError - filter( x, undefined ); // $ExpectError - filter( x, {} ); // $ExpectError - filter( 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' ); - - filter( x, '10', predicate, {} ); // $ExpectError - filter( x, 10, predicate, {} ); // $ExpectError - filter( x, false, predicate, {} ); // $ExpectError - filter( x, true, predicate, {} ); // $ExpectError - filter( x, [], predicate, {} ); // $ExpectError - filter( x, ( x: number ): number => x, predicate, {} ); // $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' ); - - filter( x, { 'dtype': '10' }, predicate ); // $ExpectError - filter( x, { 'dtype': 10 }, predicate ); // $ExpectError - filter( x, { 'dtype': null }, predicate ); // $ExpectError - filter( x, { 'dtype': false }, predicate ); // $ExpectError - filter( x, { 'dtype': true }, predicate ); // $ExpectError - filter( x, { 'dtype': [] }, predicate ); // $ExpectError - filter( x, { 'dtype': {} }, predicate ); // $ExpectError - filter( x, { 'dtype': ( x: number ): number => x }, predicate ); // $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' ); - - filter( x, { 'order': '10' }, predicate ); // $ExpectError - filter( x, { 'order': 10 }, predicate ); // $ExpectError - filter( x, { 'order': null }, predicate ); // $ExpectError - filter( x, { 'order': false }, predicate ); // $ExpectError - filter( x, { 'order': true }, predicate ); // $ExpectError - filter( x, { 'order': [] }, predicate ); // $ExpectError - filter( x, { 'order': {} }, predicate ); // $ExpectError - filter( x, { 'order': ( x: number ): number => x }, predicate ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - filter(); // $ExpectError - filter( zeros( 'float64', [ 2, 2 ], 'row-major' ) ); // $ExpectError - filter( 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 e2dd6cb..0000000 --- a/examples/index.js +++ /dev/null @@ -1,38 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var array = require( '@stdlib/ndarray-array' ); -var isPositive = require( '@stdlib/assert-is-positive-number' ).isPrimitive; -var filter = require( './../lib' ); - -var buffer = discreteUniform( 10, -100, 100, { - 'dtype': 'generic' -}); -var x = array( buffer, { - 'shape': [ 5, 2 ], - 'dtype': 'generic' -}); -console.log( ndarray2array( x ) ); - -var y = filter( x, naryFunction( isPositive, 1 ) ); -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 c4dadbe..7f6ff4a 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..483f25f --- /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)),D=v.get.apply(v,B),w.call(T,D,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..2c1ae93 --- /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* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate 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 {boolean} [options.order] - index iteration order\n* @param {Callback} predicate - predicate function\n* @param {*} [thisArg] - predicate 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 { isPrimitive as isEven } from '@stdlib/assert-is-even';\n* import Float64Array from '@stdlib/array-float64';\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndarray2array from '@stdlib/ndarray-to-array';\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 = filter( x, isEven );\n* // returns \n*\n* var arr = ndarray2array( y );\n* // returns [ 2.0, 4.0, 8.0, 10.0 ]\n*/\nfunction filter( x, options, predicate, 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 = predicate;\n\t\t} else {\n\t\t\thasOpts = true;\n\t\t\topts = options;\n\t\t\tclbk = predicate;\n\t\t}\n\t} else {\n\t\thasOpts = true;\n\t\topts = options;\n\t\tclbk = predicate;\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 predicate 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 elements according to a predicate 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 = x.get.apply( x, idx );\n\t\tif ( clbk.call( ctx, v, idx.slice(), x ) ) {\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 filter;\n"],"names":["filter","x","options","predicate","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","get","apply","call","slice","gcopy","constructor"],"mappings":";;6zCA0EA,SAASA,EAAQC,EAAGC,EAASC,EAAWC,GACvC,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,IAE9CK,EAAIlB,EAAEsC,IAAIC,MAAOvC,EAAGa,GACfN,EAAKiC,KAAM9B,EAAKQ,EAAGL,EAAI4B,QAASzC,KACpCM,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 46f5998..0000000 --- a/lib/index.js +++ /dev/null @@ -1,55 +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'; - -/** -* Return a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @module @stdlib/ndarray-filter -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var filter = require( '@stdlib/ndarray-filter' ); -* -* 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 = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.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 3cd50e0..0000000 --- a/lib/main.js +++ /dev/null @@ -1,196 +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/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param {ndarray} x - input ndarray -* @param {Options} [options] - function options -* @param {string} [options.dtype] - output array data type -* @param {boolean} [options.order] - index iteration order -* @param {Callback} predicate - predicate function -* @param {*} [thisArg] - predicate 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 isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -function filter( x, options, predicate, 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( 'null5t', x ) ); - } - if ( arguments.length < 3 ) { - clbk = options; - } else if ( arguments.length === 3 ) { - if ( isFunction( options ) ) { - clbk = options; - ctx = predicate; - } else { - hasOpts = true; - opts = options; - clbk = predicate; - } - } else { - hasOpts = true; - opts = options; - clbk = predicate; - ctx = thisArg; - } - if ( !isFunction( clbk ) ) { - throw new TypeError( format( 'null2b', clbk ) ); - } - if ( hasOpts ) { - if ( !isPlainObject( opts ) ) { - throw new TypeError( format( 'null2V', opts ) ); - } - if ( hasOwnProp( opts, 'dtype' ) ) { - dt = opts.dtype; - } else { - dt = getDType( x ); - } - if ( hasOwnProp( opts, 'order' ) ) { - if ( !isOrder( opts.order ) ) { - throw new TypeError( format( 'null5C', '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( 'nullBf', '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 predicate 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 elements according to a predicate function... - for ( i = 0; i < N; i++ ) { - if ( i > 0 ) { - idx = nextCartesianIndex( sh, ord, idx, dim, idx ); - } - v = x.get.apply( x, idx ); - if ( clbk.call( ctx, v, idx.slice(), x ) ) { - 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 = filter; diff --git a/package.json b/package.json index a44b313..2473eda 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Return a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate 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,62 +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/error-tools-fmtprodmsg": "^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-positive-number": "^0.2.2", - "@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", - "@stdlib/utils-nary-function": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "strided", @@ -104,7 +25,6 @@ "select", "take" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..135eeac --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Codestin Search App + + + +
+ + + + + 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 3bea6b3..0000000 --- a/test/test.js +++ /dev/null @@ -1,892 +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 filter = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof filter, '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() { - filter( value, predicate ); - }; - } - - function predicate( z ) { - return ( z > 0.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() { - filter( 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() { - filter( 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() { - filter( x, value, predicate ); - }; - } - - function predicate( z ) { - return ( z > 0.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 - }; - filter( x, opts, predicate ); - }; - } - - function predicate( z ) { - return ( z > 0.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 - }; - filter( x, opts, predicate ); - }; - } - - function predicate( z ) { - return ( z > 0.0 ); - } -}); - -tape( 'the function filters an array according to a predicate 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 = filter( x, predicate ); - - expected = new Float64Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - - t.end(); - - function predicate( z ) { - return ( z > 0.0 ); - } -}); - -tape( 'the function filters an array according to a predicate 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 = filter( x, predicate ); - - expected = new Float64Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - - t.end(); - - function predicate( z ) { - return ( z > 0.0 ); - } -}); - -tape( 'the function filters an array according to a predicate 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 = filter( x, opts, predicate ); - - expected = new Float64Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - - opts = { - 'dtype': 'float32' - }; - y = filter( x, opts, predicate ); - - expected = new Float32Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat32Array( y.data, expected ), true, 'returns expected value' ); - - t.end(); - - function predicate( z ) { - return ( z > 0.0 ); - } -}); - -tape( 'the function filters an array according to a predicate 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 = filter( x, opts, predicate ); - - expected = new Float64Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - - opts = { - 'dtype': 'float32' - }; - y = filter( x, opts, predicate ); - - expected = new Float32Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat32Array( y.data, expected ), true, 'returns expected value' ); - - t.end(); - - function predicate( z ) { - return ( z > 0.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 = filter( x, predicate, ctx ); - - expected = new Float64Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function predicate( z ) { - this.count += 1; // eslint-disable-line no-invalid-this - return ( z > 0.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 = filter( x, {}, predicate, ctx ); - - expected = new Float64Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function predicate( z ) { - this.count += 1; // eslint-disable-line no-invalid-this - return ( z > 0.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 = filter( x, predicate ); - - expected = new Float64Array([ - 1.0, - 3.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 predicate( z, idx, arr ) { - values.push( z ); - indices.push( idx ); - arrays.push( arr ); - return ( z > 0.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 = filter( x, predicate ); - - expected = new Float64Array([ - 1.0, - 3.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 predicate( z, idx, arr ) { - values.push( z ); - indices.push( idx ); - arrays.push( arr ); - return ( z > 0.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 = filter( x, opts, predicate ); - - expected = new Float64Array([ - 1.0, - 3.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 predicate( z, idx, arr ) { - values.push( z ); - indices.push( idx ); - arrays.push( arr ); - return ( z > 0.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 = filter( x, opts, predicate ); - - expected = new Float64Array([ - 1.0, - 3.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 predicate( z, idx, arr ) { - values.push( z ); - indices.push( idx ); - arrays.push( arr ); - return ( z > 0.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 = filter( x, opts, predicate ); - - expected = new Float64Array([ - 1.0, - 3.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 predicate( z, idx, arr ) { - values.push( z ); - indices.push( idx ); - arrays.push( arr ); - return ( z > 0.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 = filter( x, opts, predicate ); - - expected = new Float64Array([ - 1.0, - 3.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 predicate( z, idx, arr ) { - values.push( z ); - indices.push( idx ); - arrays.push( arr ); - return ( z > 0.0 ); - } -}); From f15344cd7625c6fd83118ec348ae733ff4ee5631 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 24 Mar 2025 00:28:08 +0000 Subject: [PATCH 33/35] Transform error messages --- lib/main.js | 12 ++++++------ package.json | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/main.js b/lib/main.js index 6ad824e..3cd50e0 100644 --- a/lib/main.js +++ b/lib/main.js @@ -33,7 +33,7 @@ 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' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -91,7 +91,7 @@ function filter( x, options, predicate, thisArg ) { var v; var i; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray-like object. Value: `%s`.', x ) ); + throw new TypeError( format( 'null5t', x ) ); } if ( arguments.length < 3 ) { clbk = options; @@ -111,11 +111,11 @@ function filter( x, options, predicate, thisArg ) { ctx = thisArg; } if ( !isFunction( clbk ) ) { - throw new TypeError( format( 'invalid argument. Callback argument must be a function. Value: `%s`.', clbk ) ); + throw new TypeError( format( 'null2b', clbk ) ); } if ( hasOpts ) { if ( !isPlainObject( opts ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) ); + throw new TypeError( format( 'null2V', opts ) ); } if ( hasOwnProp( opts, 'dtype' ) ) { dt = opts.dtype; @@ -124,7 +124,7 @@ function filter( x, options, predicate, thisArg ) { } 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 ) ); + throw new TypeError( format( 'null5C', 'order', opts.order ) ); } ord = opts.order; } @@ -135,7 +135,7 @@ function filter( x, options, predicate, thisArg ) { 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 ) ); + throw new TypeError( format( 'nullBf', 'dtype', opts.dtype ) ); } // Resolve the iteration order: if ( ord === void 0 ) { diff --git a/package.json b/package.json index 22065aa..a44b313 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@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/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From 793a66049c3fbf94a198788df917967cf39e036e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 24 Mar 2025 00:28:25 +0000 Subject: [PATCH 34/35] Remove files --- index.d.ts | 1612 ---------------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 6459 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 7f6ff4a..0000000 --- a/index.d.ts +++ /dev/null @@ -1,1612 +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. -*/ - -// TypeScript Version: 4.1 - -/// - -/* eslint-disable max-lines */ - -import { typedndarray, DataType, Order, float64ndarray, float32ndarray, complex128ndarray, complex64ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, boolndarray, genericndarray } from '@stdlib/types/ndarray'; -import { Complex64, Complex128 } from '@stdlib/types/complex'; - -/** -* Returns a boolean indicating whether an element passes a test. -* -* @returns boolean indicating whether an element passes a test -*/ -type Nullary = ( this: V ) => boolean; - -/** -* Returns a boolean indicating whether an element passes a test. -* -* @param value - current array element -* @returns boolean indicating whether an element passes a test -*/ -type Unary = ( this: V, value: T ) => boolean; - -/** -* Returns a boolean indicating whether an element passes a test. -* -* @param value - current array element -* @param indices - current array element indices -* @returns boolean indicating whether an element passes a test -*/ -type Binary = ( this: V, value: T, indices: Array ) => boolean; - -/** -* Returns a boolean indicating whether an element passes a test. -* -* @param value - current array element -* @param indices - current array element indices -* @param arr - input array -* @returns boolean indicating whether an element passes a test -*/ -type Ternary = ( this: V, value: T, indices: Array, arr: typedndarray ) => boolean; - -/** -* Returns a boolean indicating whether an element passes a test. -* -* @param value - current array element -* @param indices - current array element indices -* @param arr - input array -* @returns boolean indicating whether an element passes a test -*/ -type Predicate = Nullary | Unary | Binary | Ternary; - -/** -* Interface describing "base" function options. -*/ -interface BaseOptions { - /** - * Index iteration order. - * - * ## Notes - * - * - By default, the function iterates over elements according to the layout order of the provided ndarray. Accordingly, for row-major input ndarrays, the last dimension indices increment fastest. For column-major input ndarrays, the first dimension indices increment fastest. To override the inferred order and ensure that indices increment in a specific manner, regardless of the input ndarray's layout order, explicitly set the iteration order. Note, however, that iterating according to an order which does not match that of the input ndarray may, in some circumstances, result in performance degradation due to cache misses. - */ - order?: Order; -} - -/** -* Interface describing function options. -*/ -interface OrderOptions { - /** - * Index iteration order. - * - * ## Notes - * - * - By default, the function iterates over elements according to the layout order of the provided ndarray. Accordingly, for row-major input ndarrays, the last dimension indices increment fastest. For column-major input ndarrays, the first dimension indices increment fastest. To override the inferred order and ensure that indices increment in a specific manner, regardless of the input ndarray's layout order, explicitly set the iteration order. Note, however, that iterating according to an order which does not match that of the input ndarray may, in some circumstances, result in performance degradation due to cache misses. - */ - order: Order; -} - -/** -* Interface describing function options. -*/ -interface Options extends BaseOptions { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: DataType; -} - -/** -* Interface describing function options. -*/ -interface Float64Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'float64'; -} - -/** -* Interface describing function options. -*/ -interface Float32Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'float32'; -} - -/** -* Interface describing function options. -*/ -interface Complex128Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'complex128'; -} - -/** -* Interface describing function options. -*/ -interface Complex64Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'complex64'; -} - -/** -* Interface describing function options. -*/ -interface Int32Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'int32'; -} - -/** -* Interface describing function options. -*/ -interface Int16Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'int16'; -} - -/** -* Interface describing function options. -*/ -interface Int8Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'int8'; -} - -/** -* Interface describing function options. -*/ -interface Uint32Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'uint32'; -} - -/** -* Interface describing function options. -*/ -interface Uint16Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'uint16'; -} - -/** -* Interface describing function options. -*/ -interface Uint8Options extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'uint8'; -} - -/** -* Interface describing function options. -*/ -interface Uint8COptions extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'uint8c'; -} - -/** -* Interface describing function options. -*/ -interface BoolOptions extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'bool'; -} - -/** -* Interface describing function options. -*/ -interface GenericOptions extends Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - This option overrides using the input ndarray's inferred data type. - */ - dtype?: 'generic'; -} - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: float64ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): float64ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float32Array = require( '@stdlib/array-float32' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Float32Array( [ 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( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: float32ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): float32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var Complex64Array = require( '@stdlib/array-complex64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* function predicate( z, idx ) { -* return idx[ 0 ] > 0; -* } -* -* var buffer = new Complex64Array( [ 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 = [ 3, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, predicate ); -* // returns -*/ -declare function filter( x: complex64ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): complex64ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* function predicate( z, idx ) { -* return idx[ 0 ] > 0; -* } -* -* var buffer = new Complex128Array( [ 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 = [ 3, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, predicate ); -* // returns -*/ -declare function filter( x: complex128ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): complex128ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Int32Array = require( '@stdlib/array-int32' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Int32Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: int32ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): int32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Int16Array = require( '@stdlib/array-int16' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Int16Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: int16ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): int16ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Int8Array = require( '@stdlib/array-int8' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Int8Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: int8ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): int8ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint32Array = require( '@stdlib/array-uint32' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint32Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint32ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): uint32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint16Array = require( '@stdlib/array-uint16' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint16Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint16ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): uint16ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint8Array = require( '@stdlib/array-uint8' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint8Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint8ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): uint8ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint8ClampedArray( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint8cndarray, predicate: Predicate, thisArg?: ThisParameterType> ): uint8cndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var BooleanArray = require( '@stdlib/array-bool' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* function predicate( z ) { -* return z; -* } -* -* var buffer = new BooleanArray( [ false, true, false, true, false, true, false, true, false, true, false, true ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'bool', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, predicate ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ true, true, true, true ] -*/ -declare function filter( x: boolndarray, predicate: Predicate, thisArg?: ThisParameterType> ): boolndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 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( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: genericndarray, predicate: Predicate, thisArg?: ThisParameterType> ): genericndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: float64ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): float64ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float32Array = require( '@stdlib/array-float32' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Float32Array( [ 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( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: float32ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): float32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var Complex64Array = require( '@stdlib/array-complex64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* function predicate( z, idx ) { -* return idx[ 0 ] > 0; -* } -* -* var buffer = new Complex64Array( [ 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 = [ 3, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, predicate ); -* // returns -*/ -declare function filter( x: complex64ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): complex64ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* function predicate( z, idx ) { -* return idx[ 0 ] > 0; -* } -* -* var buffer = new Complex128Array( [ 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 = [ 3, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, predicate ); -* // returns -*/ -declare function filter( x: complex128ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): complex128ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Int32Array = require( '@stdlib/array-int32' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Int32Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: int32ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): int32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Int16Array = require( '@stdlib/array-int16' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Int16Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: int16ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): int16ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Int8Array = require( '@stdlib/array-int8' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Int8Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: int8ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): int8ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint32Array = require( '@stdlib/array-uint32' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint32Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint32ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): uint32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint16Array = require( '@stdlib/array-uint16' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint16Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint16ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): uint16ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint8Array = require( '@stdlib/array-uint8' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint8Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint8ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): uint8ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = new Uint8ClampedArray( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: uint8cndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): uint8cndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var BooleanArray = require( '@stdlib/array-bool' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* function predicate( z ) { -* return z; -* } -* -* var buffer = new BooleanArray( [ false, true, false, true, false, true, false, true, false, true, false, true ] ); -* var shape = [ 2, 3 ]; -* var strides = [ 6, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'bool', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, predicate ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ true, true, true, true ] -*/ -declare function filter( x: boolndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): boolndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - function options -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 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( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'order': 'row-major' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: genericndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): genericndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'float64' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: typedndarray, options: Float64Options, predicate: Predicate, thisArg?: ThisParameterType> ): float64ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'float32' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: typedndarray, options: Float32Options, predicate: Predicate, thisArg?: ThisParameterType> ): float32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* function predicate( z, idx ) { -* return idx[ 0 ] > 0; -* } -* -* var buffer = new Complex128Array( [ 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 = [ 3, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'dtype': 'complex128' -* }; -* var y = filter( x, opts, predicate ); -* // returns -*/ -declare function filter( x: typedndarray, options: Complex128Options, predicate: Predicate, thisArg?: ThisParameterType> ): complex128ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* function predicate( z, idx ) { -* return idx[ 0 ] > 0; -* } -* -* var buffer = new Complex128Array( [ 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 = [ 3, 1 ]; -* var offset = 1; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var opts = { -* 'dtype': 'complex64' -* }; -* var y = filter( x, opts, predicate ); -* // returns -*/ -declare function filter( x: typedndarray, options: Complex64Options, predicate: Predicate, thisArg?: ThisParameterType> ): complex64ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'int32' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: typedndarray, options: Int32Options, predicate: Predicate, thisArg?: ThisParameterType> ): int32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'int16' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: typedndarray, options: Int16Options, predicate: Predicate, thisArg?: ThisParameterType> ): int16ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'int8' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: typedndarray, options: Int8Options, predicate: Predicate, thisArg?: ThisParameterType> ): int8ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'uint32' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: typedndarray, options: Uint32Options, predicate: Predicate, thisArg?: ThisParameterType> ): uint32ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'uint16' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: typedndarray, options: Uint16Options, predicate: Predicate, thisArg?: ThisParameterType> ): uint16ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'uint8' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: typedndarray, options: Uint8Options, predicate: Predicate, thisArg?: ThisParameterType> ): uint8ndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'uint8c' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2, 4, 8, 10 ] -*/ -declare function filter( x: typedndarray, options: Uint8COptions, predicate: Predicate, thisArg?: ThisParameterType> ): uint8cndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'bool' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ true, true, true, true ] -*/ -declare function filter( x: typedndarray, options: BoolOptions, predicate: Predicate, thisArg?: ThisParameterType> ): boolndarray; - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param x - input ndarray -* @param options - options -* @param options.dtype - output ndarray data type -* @param options.order - iteration order -* @param predicate - predicate function -* @param thisArg - predicate function execution context -* @returns output ndarray -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 opts = { -* 'dtype': 'generic' -* }; -* var y = filter( x, opts, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -declare function filter( x: typedndarray, options: GenericOptions, predicate: Predicate, thisArg?: ThisParameterType> ): genericndarray; - - -// EXPORTS // - -export = filter; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 483f25f..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import 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)),D=v.get.apply(v,B),w.call(T,D,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 deleted file mode 100644 index 2c1ae93..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 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* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate 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 {boolean} [options.order] - index iteration order\n* @param {Callback} predicate - predicate function\n* @param {*} [thisArg] - predicate 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 { isPrimitive as isEven } from '@stdlib/assert-is-even';\n* import Float64Array from '@stdlib/array-float64';\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndarray2array from '@stdlib/ndarray-to-array';\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 = filter( x, isEven );\n* // returns \n*\n* var arr = ndarray2array( y );\n* // returns [ 2.0, 4.0, 8.0, 10.0 ]\n*/\nfunction filter( x, options, predicate, 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 = predicate;\n\t\t} else {\n\t\t\thasOpts = true;\n\t\t\topts = options;\n\t\t\tclbk = predicate;\n\t\t}\n\t} else {\n\t\thasOpts = true;\n\t\topts = options;\n\t\tclbk = predicate;\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 predicate 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 elements according to a predicate 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 = x.get.apply( x, idx );\n\t\tif ( clbk.call( ctx, v, idx.slice(), x ) ) {\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 filter;\n"],"names":["filter","x","options","predicate","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","get","apply","call","slice","gcopy","constructor"],"mappings":";;6zCA0EA,SAASA,EAAQC,EAAGC,EAASC,EAAWC,GACvC,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,IAE9CK,EAAIlB,EAAEsC,IAAIC,MAAOvC,EAAGa,GACfN,EAAKiC,KAAM9B,EAAKQ,EAAGL,EAAI4B,QAASzC,KACpCM,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/stats.html b/stats.html deleted file mode 100644 index 135eeac..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Codestin Search App - - - -
- - - - - From cb30dca3b1a8afdeec719880641234fa9ebb9c91 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 24 Mar 2025 00:28:46 +0000 Subject: [PATCH 35/35] Auto-generated commit --- .editorconfig | 180 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 194 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 57 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 79 +- SECURITY.md | 5 - benchmark/benchmark.1d.js | 150 - benchmark/benchmark.2d.js | 161 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 51 - docs/types/test.ts | 195 - examples/index.js | 38 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 55 - lib/main.js | 196 - package.json | 84 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 892 ---- 45 files changed, 4885 insertions(+), 5329 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.1d.js delete mode 100644 benchmark/benchmark.2d.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index dab5d2a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,180 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 3fc6d81..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-03-24T00:27:42.328Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 7f5f9af..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) 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 48af73a..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) 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 443f7ec..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: '9 21 * * 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 + + ```
@@ -257,7 +248,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]. @@ -320,21 +311,21 @@ Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-filter/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-map]: https://github.com/stdlib-js/ndarray-filter-map +[@stdlib/ndarray/filter-map]: https://github.com/stdlib-js/ndarray-filter-map/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 6958f29..0000000 --- a/benchmark/benchmark.1d.js +++ /dev/null @@ -1,150 +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 filter = require( './../lib' ); - - -// VARIABLES // - -var xtypes = [ 'generic' ]; -var ytypes = [ 'float64' ]; -var orders = [ 'row-major', 'column-major' ]; - - -// FUNCTIONS // - -/** -* Predicate function. -* -* @private -* @param {number} value - array element -* @param {NonNegativeIntegerArray} indices - element indices -* @param {ndarray} arr - input array -* @returns {boolean} result -*/ -function predicate( value ) { - return value > 0.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 = filter( x, opts, predicate ); - 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 c70a9f1..0000000 --- a/benchmark/benchmark.2d.js +++ /dev/null @@ -1,161 +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 filter = require( './../lib' ); - - -// VARIABLES // - -var xtypes = [ 'generic' ]; -var ytypes = [ 'float64' ]; -var orders = [ 'row-major', 'column-major' ]; - - -// FUNCTIONS // - -/** -* Predicate function. -* -* @private -* @param {number} value - array element -* @param {NonNegativeIntegerArray} indices - element indices -* @param {ndarray} arr - input array -* @returns {boolean} result -*/ -function predicate( value ) { - return value > 0.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 = filter( x, opts, predicate ); - 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 51e4f91..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" -%% click B href "https://github.com/stdlib-js/ndarray-filter/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-filter/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-filter/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-filter/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-filter/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/filter -[production-url]: https://github.com/stdlib-js/ndarray-filter/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-filter/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-filter/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-filter/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-filter/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-filter/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-filter/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 aafb9cb..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import filter from '../docs/types/index'; -export = filter; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index b5b2378..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(J,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"),N=require("@stdlib/ndarray-base-numel"),S=require("@stdlib/ndarray-base-next-cartesian-index").assign,A=require("@stdlib/blas-base-gcopy"),v=require("@stdlib/string-format");function B(r,a,g,k){var f,p,t,i,e,c,m,n,h,u,y,s,l,o,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=g):(f=!0,e=a,i=g):(f=!0,e=a,i=g,m=k),!b(i))throw new TypeError(v("invalid argument. Callback argument must be a function. Value: `%s`.",i));if(f){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(c=P(s),c===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),o=N(l),p=l.length,n==="row-major"?h=p-1:h=0,u=D(p),t={length:0},d=0;d0&&(u=S(l,n,u,h,u)),q=r.get.apply(r,u),i.call(m,q,u.slice(),r)&&(t[t.length]=q,t.length+=1);return o=t.length,y=new c(o),A(o,t,1,y,1),w=new r.constructor(s,y,[o],[1],0,n),w}E.exports=B});var G=j();module.exports=G; -/** -* @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 cfadd98..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* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate 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 {boolean} [options.order] - index iteration order\n* @param {Callback} predicate - predicate function\n* @param {*} [thisArg] - predicate 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 isEven = require( '@stdlib/assert-is-even' ).isPrimitive;\n* var Float64Array = require( '@stdlib/array-float64' );\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\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 = filter( x, isEven );\n* // returns \n*\n* var arr = ndarray2array( y );\n* // returns [ 2.0, 4.0, 8.0, 10.0 ]\n*/\nfunction filter( x, options, predicate, 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 = predicate;\n\t\t} else {\n\t\t\thasOpts = true;\n\t\t\topts = options;\n\t\t\tclbk = predicate;\n\t\t}\n\t} else {\n\t\thasOpts = true;\n\t\topts = options;\n\t\tclbk = predicate;\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 predicate 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 elements according to a predicate 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 = x.get.apply( x, idx );\n\t\tif ( clbk.call( ctx, v, idx.slice(), x ) ) {\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 = filter;\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* Return a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function.\n*\n* @module @stdlib/ndarray-filter\n*\n* @example\n* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive;\n* var Float64Array = require( '@stdlib/array-float64' );\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var filter = require( '@stdlib/ndarray-filter' );\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 = filter( x, isEven );\n* // returns \n*\n* var arr = ndarray2array( y );\n* // returns [ 2.0, 4.0, 8.0, 10.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,EAuC9C,SAASC,EAAQC,EAAGC,EAASC,EAAWC,EAAU,CACjD,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,EAAInB,EAAE,IAAI,MAAOA,EAAGa,CAAI,EACnBN,EAAK,KAAMG,EAAKS,EAAGN,EAAI,MAAM,EAAGb,CAAE,IACtCM,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", "filter", "x", "options", "predicate", "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 75de7ed..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,51 +0,0 @@ - -{{alias}}( x[, options], predicate[, thisArg] ) - Returns a shallow copy of an ndarray containing only those elements which - pass a test implemented by a predicate function. - - The predicate function is provided the following arguments: - - - value: current array element. - - indices: current array element indices. - - arr: the input 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'. - - predicate: Function - Predicate function. - - thisArg: any (optional) - Predicate function execution context. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ); - > function f( v ) { return v > 2.0; }; - > var y = {{alias}}( x, f ); - > {{alias:@stdlib/ndarray/to-array}}( y ) - [ 3.0, 4.0 ] - - See Also - -------- diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 046dffb..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,195 +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 empty = require( '@stdlib/ndarray-base-empty' ); -import zeros = require( '@stdlib/ndarray-base-zeros' ); -import filter = require( './index' ); - -/** -* Predicate function. -* -* @param x - input value -* @returns result -*/ -function predicate( x: any ): boolean { - return Boolean( x ); -} - -// The function returns an ndarray... -{ - const sh = [ 2, 2 ]; - const ord = 'row-major'; - - filter( zeros( 'float64', sh, ord ), predicate ); // $ExpectType float64ndarray - filter( zeros( 'float64', sh, ord ), predicate, {} ); // $ExpectType float64ndarray - filter( zeros( 'float32', sh, ord ), predicate ); // $ExpectType float32ndarray - filter( zeros( 'float32', sh, ord ), predicate, {} ); // $ExpectType float32ndarray - filter( zeros( 'complex64', sh, ord ), predicate ); // $ExpectType complex64ndarray - filter( zeros( 'complex64', sh, ord ), predicate, {} ); // $ExpectType complex64ndarray - filter( zeros( 'complex128', sh, ord ), predicate ); // $ExpectType complex128ndarray - filter( zeros( 'complex128', sh, ord ), predicate, {} ); // $ExpectType complex128ndarray - filter( zeros( 'int32', sh, ord ), predicate ); // $ExpectType int32ndarray - filter( zeros( 'int32', sh, ord ), predicate, {} ); // $ExpectType int32ndarray - filter( zeros( 'int16', sh, ord ), predicate ); // $ExpectType int16ndarray - filter( zeros( 'int16', sh, ord ), predicate, {} ); // $ExpectType int16ndarray - filter( zeros( 'int8', sh, ord ), predicate ); // $ExpectType int8ndarray - filter( zeros( 'int8', sh, ord ), predicate, {} ); // $ExpectType int8ndarray - filter( zeros( 'uint32', sh, ord ), predicate ); // $ExpectType uint32ndarray - filter( zeros( 'uint32', sh, ord ), predicate, {} ); // $ExpectType uint32ndarray - filter( zeros( 'uint16', sh, ord ), predicate ); // $ExpectType uint16ndarray - filter( zeros( 'uint16', sh, ord ), predicate, {} ); // $ExpectType uint16ndarray - filter( zeros( 'uint8', sh, ord ), predicate ); // $ExpectType uint8ndarray - filter( zeros( 'uint8', sh, ord ), predicate, {} ); // $ExpectType uint8ndarray - filter( zeros( 'uint8c', sh, ord ), predicate ); // $ExpectType uint8cndarray - filter( zeros( 'uint8c', sh, ord ), predicate, {} ); // $ExpectType uint8cndarray - filter( empty( 'bool', sh, ord ), predicate ); // $ExpectType boolndarray - filter( empty( 'bool', sh, ord ), predicate, {} ); // $ExpectType boolndarray - filter( zeros( 'generic', sh, ord ), predicate ); // $ExpectType genericndarray - filter( zeros( 'generic', sh, ord ), predicate, {} ); // $ExpectType genericndarray - - - filter( zeros( 'generic', sh, ord ), { 'dtype': 'float64' }, predicate ); // $ExpectType float64ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'float64' }, predicate, {} ); // $ExpectType float64ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'float32' }, predicate ); // $ExpectType float32ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'float32' }, predicate, {} ); // $ExpectType float32ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'complex64' }, predicate ); // $ExpectType complex64ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'complex64' }, predicate, {} ); // $ExpectType complex64ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'complex128' }, predicate ); // $ExpectType complex128ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'complex128' }, predicate, {} ); // $ExpectType complex128ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'int32' }, predicate ); // $ExpectType int32ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'int32' }, predicate, {} ); // $ExpectType int32ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'int16' }, predicate ); // $ExpectType int16ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'int16' }, predicate, {} ); // $ExpectType int16ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'int8' }, predicate ); // $ExpectType int8ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'int8' }, predicate, {} ); // $ExpectType int8ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint32' }, predicate ); // $ExpectType uint32ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint32' }, predicate, {} ); // $ExpectType uint32ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint16' }, predicate ); // $ExpectType uint16ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint16' }, predicate, {} ); // $ExpectType uint16ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint8' }, predicate ); // $ExpectType uint8ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint8' }, predicate, {} ); // $ExpectType uint8ndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint8c' }, predicate ); // $ExpectType uint8cndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'uint8c' }, predicate, {} ); // $ExpectType uint8cndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'bool' }, predicate ); // $ExpectType boolndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'bool' }, predicate, {} ); // $ExpectType boolndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'generic' }, predicate ); // $ExpectType genericndarray - filter( zeros( 'generic', sh, ord ), { 'dtype': 'generic' }, predicate, {} ); // $ExpectType genericndarray - - - filter( zeros( 'float64', sh, ord ), { 'order': ord }, predicate ); // $ExpectType float64ndarray - filter( zeros( 'float64', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType float64ndarray - filter( zeros( 'float32', sh, ord ), { 'order': ord }, predicate ); // $ExpectType float32ndarray - filter( zeros( 'float32', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType float32ndarray - filter( zeros( 'complex64', sh, ord ), { 'order': ord }, predicate ); // $ExpectType complex64ndarray - filter( zeros( 'complex64', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType complex64ndarray - filter( zeros( 'complex128', sh, ord ), { 'order': ord }, predicate ); // $ExpectType complex128ndarray - filter( zeros( 'complex128', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType complex128ndarray - filter( zeros( 'int32', sh, ord ), { 'order': ord }, predicate ); // $ExpectType int32ndarray - filter( zeros( 'int32', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType int32ndarray - filter( zeros( 'int16', sh, ord ), { 'order': ord }, predicate ); // $ExpectType int16ndarray - filter( zeros( 'int16', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType int16ndarray - filter( zeros( 'int8', sh, ord ), { 'order': ord }, predicate ); // $ExpectType int8ndarray - filter( zeros( 'int8', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType int8ndarray - filter( zeros( 'uint32', sh, ord ), { 'order': ord }, predicate ); // $ExpectType uint32ndarray - filter( zeros( 'uint32', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType uint32ndarray - filter( zeros( 'uint16', sh, ord ), { 'order': ord }, predicate ); // $ExpectType uint16ndarray - filter( zeros( 'uint16', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType uint16ndarray - filter( zeros( 'uint8', sh, ord ), { 'order': ord }, predicate ); // $ExpectType uint8ndarray - filter( zeros( 'uint8', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType uint8ndarray - filter( zeros( 'uint8c', sh, ord ), { 'order': ord }, predicate ); // $ExpectType uint8cndarray - filter( zeros( 'uint8c', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType uint8cndarray - filter( empty( 'bool', sh, ord ), { 'order': ord }, predicate ); // $ExpectType boolndarray - filter( empty( 'bool', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType boolndarray - filter( zeros( 'generic', sh, ord ), { 'order': ord }, predicate ); // $ExpectType genericndarray - filter( zeros( 'generic', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType genericndarray - -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - filter( 5, predicate ); // $ExpectError - filter( true, predicate ); // $ExpectError - filter( false, predicate ); // $ExpectError - filter( null, predicate ); // $ExpectError - filter( undefined, predicate ); // $ExpectError - filter( {}, predicate ); // $ExpectError - filter( [ 1 ], predicate ); // $ExpectError - filter( ( x: number ): number => x, predicate ); // $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' ); - - filter( x, '5' ); // $ExpectError - filter( x, true ); // $ExpectError - filter( x, false ); // $ExpectError - filter( x, null ); // $ExpectError - filter( x, undefined ); // $ExpectError - filter( x, {} ); // $ExpectError - filter( 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' ); - - filter( x, '10', predicate, {} ); // $ExpectError - filter( x, 10, predicate, {} ); // $ExpectError - filter( x, false, predicate, {} ); // $ExpectError - filter( x, true, predicate, {} ); // $ExpectError - filter( x, [], predicate, {} ); // $ExpectError - filter( x, ( x: number ): number => x, predicate, {} ); // $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' ); - - filter( x, { 'dtype': '10' }, predicate ); // $ExpectError - filter( x, { 'dtype': 10 }, predicate ); // $ExpectError - filter( x, { 'dtype': null }, predicate ); // $ExpectError - filter( x, { 'dtype': false }, predicate ); // $ExpectError - filter( x, { 'dtype': true }, predicate ); // $ExpectError - filter( x, { 'dtype': [] }, predicate ); // $ExpectError - filter( x, { 'dtype': {} }, predicate ); // $ExpectError - filter( x, { 'dtype': ( x: number ): number => x }, predicate ); // $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' ); - - filter( x, { 'order': '10' }, predicate ); // $ExpectError - filter( x, { 'order': 10 }, predicate ); // $ExpectError - filter( x, { 'order': null }, predicate ); // $ExpectError - filter( x, { 'order': false }, predicate ); // $ExpectError - filter( x, { 'order': true }, predicate ); // $ExpectError - filter( x, { 'order': [] }, predicate ); // $ExpectError - filter( x, { 'order': {} }, predicate ); // $ExpectError - filter( x, { 'order': ( x: number ): number => x }, predicate ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - filter(); // $ExpectError - filter( zeros( 'float64', [ 2, 2 ], 'row-major' ) ); // $ExpectError - filter( 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 e2dd6cb..0000000 --- a/examples/index.js +++ /dev/null @@ -1,38 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var array = require( '@stdlib/ndarray-array' ); -var isPositive = require( '@stdlib/assert-is-positive-number' ).isPrimitive; -var filter = require( './../lib' ); - -var buffer = discreteUniform( 10, -100, 100, { - 'dtype': 'generic' -}); -var x = array( buffer, { - 'shape': [ 5, 2 ], - 'dtype': 'generic' -}); -console.log( ndarray2array( x ) ); - -var y = filter( x, naryFunction( isPositive, 1 ) ); -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 c4dadbe..7f6ff4a 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..483f25f --- /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)),D=v.get.apply(v,B),w.call(T,D,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..2c1ae93 --- /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* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate 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 {boolean} [options.order] - index iteration order\n* @param {Callback} predicate - predicate function\n* @param {*} [thisArg] - predicate 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 { isPrimitive as isEven } from '@stdlib/assert-is-even';\n* import Float64Array from '@stdlib/array-float64';\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndarray2array from '@stdlib/ndarray-to-array';\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 = filter( x, isEven );\n* // returns \n*\n* var arr = ndarray2array( y );\n* // returns [ 2.0, 4.0, 8.0, 10.0 ]\n*/\nfunction filter( x, options, predicate, 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 = predicate;\n\t\t} else {\n\t\t\thasOpts = true;\n\t\t\topts = options;\n\t\t\tclbk = predicate;\n\t\t}\n\t} else {\n\t\thasOpts = true;\n\t\topts = options;\n\t\tclbk = predicate;\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 predicate 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 elements according to a predicate 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 = x.get.apply( x, idx );\n\t\tif ( clbk.call( ctx, v, idx.slice(), x ) ) {\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 filter;\n"],"names":["filter","x","options","predicate","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","get","apply","call","slice","gcopy","constructor"],"mappings":";;6zCA0EA,SAASA,EAAQC,EAAGC,EAASC,EAAWC,GACvC,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,IAE9CK,EAAIlB,EAAEsC,IAAIC,MAAOvC,EAAGa,GACfN,EAAKiC,KAAM9B,EAAKQ,EAAGL,EAAI4B,QAASzC,KACpCM,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 46f5998..0000000 --- a/lib/index.js +++ /dev/null @@ -1,55 +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'; - -/** -* Return a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @module @stdlib/ndarray-filter -* -* @example -* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var filter = require( '@stdlib/ndarray-filter' ); -* -* 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 = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.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 3cd50e0..0000000 --- a/lib/main.js +++ /dev/null @@ -1,196 +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/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function. -* -* @param {ndarray} x - input ndarray -* @param {Options} [options] - function options -* @param {string} [options.dtype] - output array data type -* @param {boolean} [options.order] - index iteration order -* @param {Callback} predicate - predicate function -* @param {*} [thisArg] - predicate 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 isEven = require( '@stdlib/assert-is-even' ).isPrimitive; -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* 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 = filter( x, isEven ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ 2.0, 4.0, 8.0, 10.0 ] -*/ -function filter( x, options, predicate, 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( 'null5t', x ) ); - } - if ( arguments.length < 3 ) { - clbk = options; - } else if ( arguments.length === 3 ) { - if ( isFunction( options ) ) { - clbk = options; - ctx = predicate; - } else { - hasOpts = true; - opts = options; - clbk = predicate; - } - } else { - hasOpts = true; - opts = options; - clbk = predicate; - ctx = thisArg; - } - if ( !isFunction( clbk ) ) { - throw new TypeError( format( 'null2b', clbk ) ); - } - if ( hasOpts ) { - if ( !isPlainObject( opts ) ) { - throw new TypeError( format( 'null2V', opts ) ); - } - if ( hasOwnProp( opts, 'dtype' ) ) { - dt = opts.dtype; - } else { - dt = getDType( x ); - } - if ( hasOwnProp( opts, 'order' ) ) { - if ( !isOrder( opts.order ) ) { - throw new TypeError( format( 'null5C', '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( 'nullBf', '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 predicate 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 elements according to a predicate function... - for ( i = 0; i < N; i++ ) { - if ( i > 0 ) { - idx = nextCartesianIndex( sh, ord, idx, dim, idx ); - } - v = x.get.apply( x, idx ); - if ( clbk.call( ctx, v, idx.slice(), x ) ) { - 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 = filter; diff --git a/package.json b/package.json index a44b313..2473eda 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Return a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate 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,62 +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/error-tools-fmtprodmsg": "^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-positive-number": "^0.2.2", - "@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", - "@stdlib/utils-nary-function": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "strided", @@ -104,7 +25,6 @@ "select", "take" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..135eeac --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Codestin Search App + + + +
+ + + + + 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 3bea6b3..0000000 --- a/test/test.js +++ /dev/null @@ -1,892 +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 filter = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof filter, '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() { - filter( value, predicate ); - }; - } - - function predicate( z ) { - return ( z > 0.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() { - filter( 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() { - filter( 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() { - filter( x, value, predicate ); - }; - } - - function predicate( z ) { - return ( z > 0.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 - }; - filter( x, opts, predicate ); - }; - } - - function predicate( z ) { - return ( z > 0.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 - }; - filter( x, opts, predicate ); - }; - } - - function predicate( z ) { - return ( z > 0.0 ); - } -}); - -tape( 'the function filters an array according to a predicate 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 = filter( x, predicate ); - - expected = new Float64Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - - t.end(); - - function predicate( z ) { - return ( z > 0.0 ); - } -}); - -tape( 'the function filters an array according to a predicate 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 = filter( x, predicate ); - - expected = new Float64Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - - t.end(); - - function predicate( z ) { - return ( z > 0.0 ); - } -}); - -tape( 'the function filters an array according to a predicate 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 = filter( x, opts, predicate ); - - expected = new Float64Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - - opts = { - 'dtype': 'float32' - }; - y = filter( x, opts, predicate ); - - expected = new Float32Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat32Array( y.data, expected ), true, 'returns expected value' ); - - t.end(); - - function predicate( z ) { - return ( z > 0.0 ); - } -}); - -tape( 'the function filters an array according to a predicate 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 = filter( x, opts, predicate ); - - expected = new Float64Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - - opts = { - 'dtype': 'float32' - }; - y = filter( x, opts, predicate ); - - expected = new Float32Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat32Array( y.data, expected ), true, 'returns expected value' ); - - t.end(); - - function predicate( z ) { - return ( z > 0.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 = filter( x, predicate, ctx ); - - expected = new Float64Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function predicate( z ) { - this.count += 1; // eslint-disable-line no-invalid-this - return ( z > 0.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 = filter( x, {}, predicate, ctx ); - - expected = new Float64Array([ - 1.0, - 3.0 - ]); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function predicate( z ) { - this.count += 1; // eslint-disable-line no-invalid-this - return ( z > 0.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 = filter( x, predicate ); - - expected = new Float64Array([ - 1.0, - 3.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 predicate( z, idx, arr ) { - values.push( z ); - indices.push( idx ); - arrays.push( arr ); - return ( z > 0.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 = filter( x, predicate ); - - expected = new Float64Array([ - 1.0, - 3.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 predicate( z, idx, arr ) { - values.push( z ); - indices.push( idx ); - arrays.push( arr ); - return ( z > 0.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 = filter( x, opts, predicate ); - - expected = new Float64Array([ - 1.0, - 3.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 predicate( z, idx, arr ) { - values.push( z ); - indices.push( idx ); - arrays.push( arr ); - return ( z > 0.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 = filter( x, opts, predicate ); - - expected = new Float64Array([ - 1.0, - 3.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 predicate( z, idx, arr ) { - values.push( z ); - indices.push( idx ); - arrays.push( arr ); - return ( z > 0.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 = filter( x, opts, predicate ); - - expected = new Float64Array([ - 1.0, - 3.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 predicate( z, idx, arr ) { - values.push( z ); - indices.push( idx ); - arrays.push( arr ); - return ( z > 0.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 = filter( x, opts, predicate ); - - expected = new Float64Array([ - 1.0, - 3.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 predicate( z, idx, arr ) { - values.push( z ); - indices.push( idx ); - arrays.push( arr ); - return ( z > 0.0 ); - } -});