diff --git a/.github/labeler.yml b/.github/labeler.yml new file mode 100644 index 000000000000..8b9a45c415ab --- /dev/null +++ b/.github/labeler.yml @@ -0,0 +1,25 @@ +#/ +# @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. +#/ + +BLAS: +- changed-files: + - any-glob-to-all-files: '**/blas/**/*' + +Math: +- changed-files: + - any-glob-to-all-files: '**/math/**/*' diff --git a/.github/workflows/labeler.yml b/.github/workflows/labeler.yml new file mode 100644 index 000000000000..94e11706f074 --- /dev/null +++ b/.github/workflows/labeler.yml @@ -0,0 +1,55 @@ +#/ +# @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. +#/ + +# Workflow name: +name: 'labeler' + +# Workflow triggers: +on: + pull_request_target: + +# Workflow jobs: +jobs: + + # Define a job which automatically labels pull requests based on the contents of the pull request: + labeler: + + # Define job name: + name: 'Labeler' + + # Only run this job if the pull request did not have label `automated-pr`: + if: contains(github.event.pull_request.labels.*.name, 'automated-pr') == false + + # Define job permissions: + permissions: + contents: read + pull-requests: write + + # Define the type of virtual host machine: + runs-on: ubuntu-latest + + # Define the sequence of job steps: + steps: + + # Automatically label pull requests: + - name: 'Automatically label pull requests' + # Pin action to full length commit SHA + uses: actions/labeler@8558fd74291d67161a8a78ce36a881fa63b766a9 # v5.0.0 + with: + configuration-path: .github/labeler.yml + repo-token: ${{ secrets.CHATBOT_GITHUB_TOKEN }} diff --git a/.github/workflows/lint_autofix.yml b/.github/workflows/lint_autofix.yml index 61b7aa1fb0b2..8745292fefe9 100644 --- a/.github/workflows/lint_autofix.yml +++ b/.github/workflows/lint_autofix.yml @@ -17,156 +17,156 @@ #/ # Workflow name: - name: lint_autofix - - # Workflow triggers: - on: - - # Allow the workflow to be triggered by other workflows - workflow_call: - # Define the input parameters for the workflow: - inputs: - pull_request_number: - description: 'PR number' - required: true - type: number - # Define the secrets accessible by the workflow: - secrets: - STDLIB_BOT_GITHUB_TOKEN: - description: 'GitHub token for stdlb-bot' - required: true - REPO_GITHUB_TOKEN: - description: 'GitHub token for accessing the repository' - required: true - STDLIB_BOT_GPG_PRIVATE_KEY: - description: 'GPG private key for stdlb-bot' - required: true - STDLIB_BOT_GPG_PASSPHRASE: - description: 'GPG passphrase for stdlb-bot' - required: true - - # Workflow jobs: - jobs: - - # Define a job for automatically fixing lint errors: - autofix: - - # Define a display name: - name: 'Fix lint errors' - - # Define the type of virtual host machine: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Get PR details: - - name: 'Get PR details' - id: pr-details - run: | - pr_response=$(curl -s \ - -H "Accept: application/vnd.github.v3+json" \ - -H "Authorization: Bearer ${{ secrets.STDLIB_BOT_GITHUB_TOKEN }}" \ - "https://api.github.com/repos/stdlib-js/stdlib/pulls/${{ inputs.pull_request_number }}") - - # Escape control characters: - pr_response=$(echo "$pr_response" | tr -d '\000-\031') - - # Extract the needed details: - pr_branch=$(echo "$pr_response" | jq -r '.head.ref') # PR's branch - pr_repo_full_name=$(echo "$pr_response" | jq -r '.head.repo.full_name') # PR's repo full name - - # Set outputs for the branch and repository: - echo "branch=$pr_branch" >> $GITHUB_OUTPUT - echo "repository=$pr_repo_full_name" >> $GITHUB_OUTPUT - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - with: - # Refers to the branch name of the branch being pushed: - ref: ${{ steps.pr-details.outputs.branch }} - - # Refers to the repository name: - repository: ${{ steps.pr-details.outputs.repository }} - - # Token for accessing the repository: - token: ${{ secrets.REPO_GITHUB_TOKEN }} - - # File path to checkout to: - path: './' - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2 - with: - node-version: '20' # 'lts/*' - timeout-minutes: 5 - - # Install dependencies (accounting for possible network failures, etc, when installing node module dependencies): - - name: 'Install dependencies' - run: | - make install-node-modules || make install-node-modules || make install-node-modules - timeout-minutes: 15 - - # Initialize development environment: - - name: 'Initialize development environment' - run: | - make init - timeout-minutes: 5 - - # Get list of changed files: - - name: 'Get list of changed files' - id: changed-files - run: | - page=1 - files="" - while true; do - changed_files=$(curl -s -H "Accept: application/vnd.github.v3+json" -H "Authorization: Bearer ${{ secrets.STDLIB_BOT_GITHUB_TOKEN - }}" "https://api.github.com/repos/stdlib-js/stdlib/pulls/${{ inputs.pull_request_number }}/files?page=$page&per_page=100" | jq -r '.[] | .filename') - if [ -z "$changed_files" ]; then - break - fi - files="$files $changed_files" - page=$((page+1)) - done - files=$(echo "$files" | tr '\n' ' ' | sed 's/^ //;s/ $//') - echo "files=${files}" >> $GITHUB_OUTPUT - - # Fix JavaScript lint errors: - - name: 'Fix JavaScript lint errors' - id: fix-lint-errors - run: | - files="${{ steps.changed-files.outputs.files }}" - FIX=1 . "$GITHUB_WORKSPACE/.github/workflows/scripts/lint_javascript_files" "$files" - - # Disable Git hooks: - - name: 'Disable Git hooks' - run: | - rm -rf .git/hooks - - # Import GPG key to sign commits: - - name: 'Import GPG key to sign commits' - # Pin action to full length commit SHA - uses: crazy-max/ghaction-import-gpg@01dd5d3ca463c7f10f7f4f7b4f177225ac661ee4 # v6.1.0 - with: - gpg_private_key: ${{ secrets.STDLIB_BOT_GPG_PRIVATE_KEY }} - passphrase: ${{ secrets.STDLIB_BOT_GPG_PASSPHRASE }} - git_user_signingkey: true - git_commit_gpgsign: true - - # Commit and push changes: - - name: 'Commit and push changes' - env: - REPO_GITHUB_TOKEN: ${{ secrets.REPO_GITHUB_TOKEN }} - USER_NAME: stdlb-bot - BRANCH_NAME: ${{ steps.pr-details.outputs.branch }} - REPO_NAME: ${{ steps.pr-details.outputs.repository }} - run: | - git config --local user.email "82920195+stdlib-bot@users.noreply.github.com" - git config --local user.name "stdlib-bot" - git add . - git commit -m "fix: resolve lint errors" - git push "https://$USER_NAME:$REPO_GITHUB_TOKEN@github.com/$REPO_NAME.git" $BRANCH_NAME +name: lint_autofix + +# Workflow triggers: +on: + + # Allow the workflow to be triggered by other workflows + workflow_call: + # Define the input parameters for the workflow: + inputs: + pull_request_number: + description: 'PR number' + required: true + type: number + # Define the secrets accessible by the workflow: + secrets: + STDLIB_BOT_GITHUB_TOKEN: + description: 'GitHub token for stdlb-bot' + required: true + REPO_GITHUB_TOKEN: + description: 'GitHub token for accessing the repository' + required: true + STDLIB_BOT_GPG_PRIVATE_KEY: + description: 'GPG private key for stdlb-bot' + required: true + STDLIB_BOT_GPG_PASSPHRASE: + description: 'GPG passphrase for stdlb-bot' + required: true + +# Workflow jobs: +jobs: + + # Define a job for automatically fixing lint errors: + autofix: + + # Define a display name: + name: 'Fix lint errors' + + # Define the type of virtual host machine: + runs-on: ubuntu-latest + + # Define the sequence of job steps... + steps: + + # Get PR details: + - name: 'Get PR details' + id: pr-details + run: | + pr_response=$(curl -s \ + -H "Accept: application/vnd.github.v3+json" \ + -H "Authorization: Bearer ${{ secrets.STDLIB_BOT_GITHUB_TOKEN }}" \ + "https://api.github.com/repos/stdlib-js/stdlib/pulls/${{ inputs.pull_request_number }}") + + # Escape control characters: + pr_response=$(echo "$pr_response" | tr -d '\000-\031') + + # Extract the needed details: + pr_branch=$(echo "$pr_response" | jq -r '.head.ref') # PR's branch + pr_repo_full_name=$(echo "$pr_response" | jq -r '.head.repo.full_name') # PR's repo full name + + # Set outputs for the branch and repository: + echo "branch=$pr_branch" >> $GITHUB_OUTPUT + echo "repository=$pr_repo_full_name" >> $GITHUB_OUTPUT + + # Checkout the repository: + - name: 'Checkout repository' + # Pin action to full length commit SHA + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + with: + # Refers to the branch name of the branch being pushed: + ref: ${{ steps.pr-details.outputs.branch }} + + # Refers to the repository name: + repository: ${{ steps.pr-details.outputs.repository }} + + # Token for accessing the repository: + token: ${{ secrets.REPO_GITHUB_TOKEN }} + + # File path to checkout to: + path: './' + + # Install Node.js: + - name: 'Install Node.js' + # Pin action to full length commit SHA + uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2 + with: + node-version: '20' # 'lts/*' + timeout-minutes: 5 + + # Install dependencies (accounting for possible network failures, etc, when installing node module dependencies): + - name: 'Install dependencies' + run: | + make install-node-modules || make install-node-modules || make install-node-modules + timeout-minutes: 15 + + # Initialize development environment: + - name: 'Initialize development environment' + run: | + make init + timeout-minutes: 5 + + # Get list of changed files: + - name: 'Get list of changed files' + id: changed-files + run: | + page=1 + files="" + while true; do + changed_files=$(curl -s -H "Accept: application/vnd.github.v3+json" -H "Authorization: Bearer ${{ secrets.STDLIB_BOT_GITHUB_TOKEN + }}" "https://api.github.com/repos/stdlib-js/stdlib/pulls/${{ inputs.pull_request_number }}/files?page=$page&per_page=100" | jq -r '.[] | .filename') + if [ -z "$changed_files" ]; then + break + fi + files="$files $changed_files" + page=$((page+1)) + done + files=$(echo "$files" | tr '\n' ' ' | sed 's/^ //;s/ $//') + echo "files=${files}" >> $GITHUB_OUTPUT + + # Fix JavaScript lint errors: + - name: 'Fix JavaScript lint errors' + id: fix-lint-errors + run: | + files="${{ steps.changed-files.outputs.files }}" + FIX=1 . "$GITHUB_WORKSPACE/.github/workflows/scripts/lint_javascript_files" "$files" + + # Disable Git hooks: + - name: 'Disable Git hooks' + run: | + rm -rf .git/hooks + + # Import GPG key to sign commits: + - name: 'Import GPG key to sign commits' + # Pin action to full length commit SHA + uses: crazy-max/ghaction-import-gpg@01dd5d3ca463c7f10f7f4f7b4f177225ac661ee4 # v6.1.0 + with: + gpg_private_key: ${{ secrets.STDLIB_BOT_GPG_PRIVATE_KEY }} + passphrase: ${{ secrets.STDLIB_BOT_GPG_PASSPHRASE }} + git_user_signingkey: true + git_commit_gpgsign: true + + # Commit and push changes: + - name: 'Commit and push changes' + env: + REPO_GITHUB_TOKEN: ${{ secrets.REPO_GITHUB_TOKEN }} + USER_NAME: stdlb-bot + BRANCH_NAME: ${{ steps.pr-details.outputs.branch }} + REPO_NAME: ${{ steps.pr-details.outputs.repository }} + run: | + git config --local user.email "82920195+stdlib-bot@users.noreply.github.com" + git config --local user.name "stdlib-bot" + git add . + git commit -m "fix: resolve lint errors" + git push "https://$USER_NAME:$REPO_GITHUB_TOKEN@github.com/$REPO_NAME.git" $BRANCH_NAME diff --git a/.github/workflows/lint_random_files.yml b/.github/workflows/lint_random_files.yml index c753ee425e53..b84b6417c749 100644 --- a/.github/workflows/lint_random_files.yml +++ b/.github/workflows/lint_random_files.yml @@ -316,7 +316,7 @@ jobs: # Pin action to full length commit SHA uses: r-lib/actions/setup-r@0ed4cdf40958ef43a6b33b9792e07ac76c3239e3 # v2.6.4 with: - r-version: '3.5.3' + r-version: '4.3.3' # Lint R files: - name: 'Lint R files' diff --git a/.github/workflows/run_affected_benchmarks.yml b/.github/workflows/run_affected_benchmarks.yml index 735f299a816c..677107bd5d52 100644 --- a/.github/workflows/run_affected_benchmarks.yml +++ b/.github/workflows/run_affected_benchmarks.yml @@ -119,3 +119,12 @@ jobs: make benchmark-javascript-files FILES="${files}" fi timeout-minutes: 30 + + # Run C benchmarks: + - name: 'Run C benchmarks' + run: | + files=$(echo "${{ steps.changed-files.outputs.files }}" | tr ' ' '\n' | grep -E '\.c$' | sed "s|^|${GITHUB_WORKSPACE}/|" | tr '\n' ' ' | sed 's/ $//') + if [ -n "$files" ]; then + make benchmark-c-files FILES="${files}" + fi + timeout-minutes: 15 diff --git a/.github/workflows/scripts/run_affected_tests b/.github/workflows/scripts/run_affected_tests index 9932f836f002..cda0b7b342a1 100644 --- a/.github/workflows/scripts/run_affected_tests +++ b/.github/workflows/scripts/run_affected_tests @@ -145,7 +145,7 @@ main() { # Build native add-ons for packages (if applicable): for pkg in ${packages}; do - if [ -f "lib/node_modules/@stdlib/${pkg}/binding.gyp" ]; then + if [ -f "lib/node_modules/${pkg}/binding.gyp" ]; then NODE_ADDONS_PATTERN="${pkg}" make install-node-addons fi done diff --git a/.mailmap b/.mailmap index 6281d3d0495e..7b5a845ca611 100644 --- a/.mailmap +++ b/.mailmap @@ -8,9 +8,21 @@ # A +Adarsh Palaskar <83298237+adarshpalaskar1@users.noreply.github.com> +Adarsh Palaskar adarshpalaskar1 + +Aditya Sapra <110766802+adityacodes30@users.noreply.github.com> +Aditya Sapra adityacodes30 + +Aman Bhansali <92033532+aman-095@users.noreply.github.com> +Aman Bhansali aman-095 + Amit Jimiwal <90555965+amitjimiwal@users.noreply.github.com> Amit Jimiwal drunken_devv +Anudeep Sanapala <71971574+anudeeps0306@users.noreply.github.com> +Anudeep Sanapala anudeeps0306 + Athan Reines kgryte Athan Reines Athan @@ -18,6 +30,10 @@ Athan Reines Athan Bruno Fenzl +# C + +Chinmay Joshi <86140365+JawHawk@users.noreply.github.com> Chinmay J + # D Dorrin Sotoudeh <59933477+dorrin-sot@users.noreply.github.com> @@ -27,24 +43,39 @@ Dorrin Sotoudeh dorrin-sot Frank Kovacs +# G + +Golden Kumar <103646877+AuenKr@users.noreply.github.com> Golden +Golden Kumar <103646877+AuenKr@users.noreply.github.com> AuenKr + +Gunj Joshi GUNJ JOSHI + # H Harshita Kalani <95532771+HarshitaKalani@users.noreply.github.com> # J +Jaimin Godhani <112328542+Jai0401@users.noreply.github.com> Jai0401 + James Gelok James Jaysukh Makvana <111515433+Jaysukh-409@users.noreply.github.com> Jordan Gallivan <115050475+Jordan-Gallivan@users.noreply.github.com> Jordan-Gallivan +# K + +Karthik Prakash <116057817+skoriop@users.noreply.github.com> skoriop + # M Marcus Fantham Marcus Matt Cochrane +Mihir Pandit <129577900+MSP20086@users.noreply.github.com> MSP20086 + # N Naresh Jagadeesan <37257700+Infinage@users.noreply.github.com> @@ -58,25 +89,65 @@ Philipp Burckhardt Planeshifter Pranav Goswami <85227306+Pranavchiku@users.noreply.github.com> Pranav Goswami Pranav +Praneki <97080887+PraneGIT@users.noreply.github.com> PraneGIT + +Pratik <97464067+Pratik772846@users.noreply.github.com> Pratik772846 + +Priyansh <88396544+itsspriyansh@users.noreply.github.com> itsspriyansh + # R +Raunak Kumar Gupta <95216822+raunak-dev-edu@users.noreply.github.com> +Raunak Kumar Gupta raunak-dev-edu + rei2hu +Rejoan Sardar <119718513+Rejoan-Sardar@users.noreply.github.com> Rejoan-Sardar + Ricky Reusser Ricky Reusser <572717+rreusser@users.noreply.github.com> Robert Gislason rgizz +Rutam <138517416+performant23@users.noreply.github.com> performant23 + Ryan Seal Splrk # S +Sai Srikar Dumpeti <80447788+the-r3aper7@users.noreply.github.com> the-r3aper7 + +Shashank Shekhar Singh <123410790+Shashankss1205@users.noreply.github.com> +Shashank Shekhar Singh Shashankss1205 + +Shubham Mishra +Shubham Mishra shubham + +Snehil Shah <130062020+Snehil-Shah@users.noreply.github.com> Snehil-Shah + +Spandan Barve <114365550+marsian83@users.noreply.github.com> +Spandan Barve marsian83 + stdlib-bot <82920195+stdlib-bot@users.noreply.github.com> Stephannie Jiménez Gacha Stephannie Jiménez Gacha Stephannie Jimenez Stephannie Jiménez Gacha Stephannie Jimenez Gacha +# U + +Utkarsh <137638507+Ut-the-pro@users.noreply.github.com> +Utkarsh Ut-the-pro + +Utkarsh Raj <49344502+rajutkarsh07@users.noreply.github.com> +Utkarsh Raj rajutkarsh07 +Utkarsh Raj utkarsh_raj + +# V + +Varad Gupta <114755221+vr-varad@users.noreply.github.com> +Varad Gupta vr-varad + # Y Yernar Yergaziyev diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 0ad498e65985..6917be2bd659 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -2,17 +2,17 @@ # # Contributors listed in alphabetical order. -Adarsh Palaskar <83298237+adarshpalaskar1@users.noreply.github.com> -Aditya Sapra <110766802+adityacodes30@users.noreply.github.com> +Adarsh Palaskar +Aditya Sapra AgPriyanshu18 <113460573+AgPriyanshu18@users.noreply.github.com> Ali Salesi -Aman Bhansali <92033532+aman-095@users.noreply.github.com> +Aman Bhansali Amit Jimiwal -Anudeep Sanapala <71971574+anudeeps0306@users.noreply.github.com> +Anudeep Sanapala Athan Reines Brendan Graetz Bruno Fenzl -Chinmay J <86140365+JawHawk@users.noreply.github.com> +Chinmay Joshi <86140365+JawHawk@users.noreply.github.com> Christopher Dambamuromo Dan Rose Daniel Killenberger @@ -20,13 +20,14 @@ Dominik Moritz Dorrin Sotoudeh EuniceSim142 <77243938+EuniceSim142@users.noreply.github.com> Frank Kovacs -GUNJ JOSHI -Golden <103646877+AuenKr@users.noreply.github.com> +Golden Kumar <103646877+AuenKr@users.noreply.github.com> +Gunj Joshi Harshita Kalani Jaimin Godhani <112328542+Jai0401@users.noreply.github.com> James Gelok Jaysukh Makvana Jithin KS +Joel Mathew Koshy Joey Reed Jordan Gallivan <115050475+Jordan-Gallivan@users.noreply.github.com> Joris Labie @@ -50,6 +51,7 @@ Pranav Goswami Praneki <97080887+PraneGIT@users.noreply.github.com> Pratik <97464067+Pratik772846@users.noreply.github.com> Priyansh <88396544+itsspriyansh@users.noreply.github.com> +Raunak Kumar Gupta Rejoan Sardar <119718513+Rejoan-Sardar@users.noreply.github.com> Ricky Reusser Robert Gislason @@ -58,16 +60,16 @@ Rutam <138517416+performant23@users.noreply.github.com> Ryan Seal Sai Srikar Dumpeti <80447788+the-r3aper7@users.noreply.github.com> Seyyed Parsa Neshaei -Shashank Shekhar Singh <123410790+Shashankss1205@users.noreply.github.com> +Shashank Shekhar Singh Shraddheya Shendre -Shubham +Shubham Mishra Snehil Shah <130062020+Snehil-Shah@users.noreply.github.com> -Spandan Barve <114365550+marsian83@users.noreply.github.com> +Spandan Barve Stephannie Jiménez Gacha -Utkarsh <137638507+Ut-the-pro@users.noreply.github.com> +Utkarsh +Utkarsh Raj +Varad Gupta Yernar Yergaziyev nishant-s7 <97207366+nishant-s7@users.noreply.github.com> orimiles5 <97595296+orimiles5@users.noreply.github.com> rei2hu -utkarsh_raj <49344502+rajutkarsh07@users.noreply.github.com> -vr-varad <114755221+vr-varad@users.noreply.github.com> diff --git a/lib/node_modules/@stdlib/_tools/package-json/scripts/update_gypfile b/lib/node_modules/@stdlib/_tools/package-json/scripts/update_gypfile index db82bdc9de80..f5ffcc57006e 100755 --- a/lib/node_modules/@stdlib/_tools/package-json/scripts/update_gypfile +++ b/lib/node_modules/@stdlib/_tools/package-json/scripts/update_gypfile @@ -108,6 +108,8 @@ function main( dir ) { if ( exists( join( pkgs[ i ], GYPFILES[ j ] ) ) ) { pkg.gypfile = true; break; + } else { + delete pkg.gypfile; } } diff --git a/lib/node_modules/@stdlib/array/base/README.md b/lib/node_modules/@stdlib/array/base/README.md index 91820a24b21d..a94717ce5560 100644 --- a/lib/node_modules/@stdlib/array/base/README.md +++ b/lib/node_modules/@stdlib/array/base/README.md @@ -89,6 +89,8 @@ The namespace exports the following: - [`copyIndexed( x )`][@stdlib/array/base/copy-indexed]: copy the elements of an indexed array-like object to a new "generic" array. - [`copy( x )`][@stdlib/array/base/copy]: copy the elements of an array-like object to a new "generic" array. - [`countFalsy( x )`][@stdlib/array/base/count-falsy]: count the number of falsy elements in an array. +- [`countSameValueZero( x, value )`][@stdlib/array/base/count-same-value-zero]: count the number of elements in an array that are equal to a specified value. +- [`countSameValue( x, value )`][@stdlib/array/base/count-same-value]: count the number of elements in an array that are equal to a specified value. - [`countTruthy( x )`][@stdlib/array/base/count-truthy]: count the number of truthy elements in an array. - [`dedupe( x, limit, equalNaNs )`][@stdlib/array/base/dedupe]: remove consecutive duplicated values. - [`everyByRight( x, predicate[, thisArg] )`][@stdlib/array/base/every-by-right]: test whether all elements in an array pass a test implemented by a predicate function, iterating from right to left. @@ -337,6 +339,10 @@ console.log( objectKeys( ns ) ); [@stdlib/array/base/count-falsy]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/count-falsy +[@stdlib/array/base/count-same-value-zero]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/count-same-value-zero + +[@stdlib/array/base/count-same-value]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/count-same-value + [@stdlib/array/base/count-truthy]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/count-truthy [@stdlib/array/base/dedupe]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/dedupe diff --git a/lib/node_modules/@stdlib/array/base/count-same-value-zero/README.md b/lib/node_modules/@stdlib/array/base/count-same-value-zero/README.md index cb75ff0c3283..5e68b041e2e5 100644 --- a/lib/node_modules/@stdlib/array/base/count-same-value-zero/README.md +++ b/lib/node_modules/@stdlib/array/base/count-same-value-zero/README.md @@ -20,7 +20,7 @@ limitations under the License. # countSameValueZero -> Count the number of elements that are equal to a given value in an array. +> Count the number of elements in an array that are equal to a specified value. @@ -42,7 +42,7 @@ var countSameValueZero = require( '@stdlib/array/base/count-same-value-zero' ); #### countSameValueZero( x, value ) -Counts the number of elements that are equal to a given value in an array. +Counts the number of elements in an array that are equal to a specified value. ```javascript var x = [ 0, 1, 0, 1, 2 ]; @@ -51,6 +51,24 @@ var out = countSameValueZero( x, 1 ); // returns 2 ``` +In contrast to an implementation using the strict equality operator `===`, the function treats `NaNs` as the same value. + +```javascript +var x = [ NaN, NaN, NaN ]; + +var out = countSameValueZero( x, NaN ); +// returns 3 +``` + +In contrast to an implementation using the [SameValue Algorithm][@stdlib/array/base/count-same-value] (as specified in ECMAScript 5), the function does not distinguish between `+0` and `-0`. + +```javascript +var x = [ 0.0, -0.0, 0.0 ]; + +var out = countSameValueZero( x, 0.0 ); +// returns 3 +``` + @@ -72,10 +90,12 @@ var out = countSameValueZero( x, 1 ); ```javascript -var sample = require( '@stdlib/random/sample' ); +var bernoulli = require( '@stdlib/random/array/bernoulli' ); var countSameValueZero = require( '@stdlib/array/base/count-same-value-zero' ); -var x = sample( [ 1, 2, 3, 4, 5 ] ); +var x = bernoulli( 10, 0.5, { + 'dtype': 'generic' +}); console.log( x ); var n = countSameValueZero( x, 1 ); @@ -106,6 +126,8 @@ console.log( n ); diff --git a/lib/node_modules/@stdlib/array/base/count-same-value-zero/docs/repl.txt b/lib/node_modules/@stdlib/array/base/count-same-value-zero/docs/repl.txt index dd1d1fc13c78..f74b77f678a8 100644 --- a/lib/node_modules/@stdlib/array/base/count-same-value-zero/docs/repl.txt +++ b/lib/node_modules/@stdlib/array/base/count-same-value-zero/docs/repl.txt @@ -1,6 +1,9 @@ {{alias}}( x, value ) - Counts the number of elements that are equal to a given value in an array. + Counts the number of elements in an array that are equal to a specified + value. + + The function treats `NaN` values as the same value. Parameters ---------- @@ -13,7 +16,7 @@ Returns ------- out: integer - Number of elements that are equal to the given value. + Number of elements that are equal to a specified value. Examples -------- diff --git a/lib/node_modules/@stdlib/array/base/count-same-value-zero/docs/types/index.d.ts b/lib/node_modules/@stdlib/array/base/count-same-value-zero/docs/types/index.d.ts index fdc419661b32..4ba495962164 100644 --- a/lib/node_modules/@stdlib/array/base/count-same-value-zero/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/array/base/count-same-value-zero/docs/types/index.d.ts @@ -23,11 +23,15 @@ import { Collection } from '@stdlib/types/array'; /** -* Counts the number of elements that are equal to a given value in an array. +* Counts the number of elements in an array that are equal to a specified value. +* +* ## Notes +* +* - In contrast to an implementation based on the strict equality operator `===`, the function treats `NaNs` as the same value. * * @param x - input array -* @param value - given value -* @returns number of elements that are equal to the given value +* @param value - search value +* @returns number of elements that are equal to a specified value * * @example * var x = [ 0, 1, 0, 1, 1 ]; diff --git a/lib/node_modules/@stdlib/array/base/count-same-value-zero/example/index.js b/lib/node_modules/@stdlib/array/base/count-same-value-zero/examples/index.js similarity index 82% rename from lib/node_modules/@stdlib/array/base/count-same-value-zero/example/index.js rename to lib/node_modules/@stdlib/array/base/count-same-value-zero/examples/index.js index c85282e909e4..27e165dc27c0 100644 --- a/lib/node_modules/@stdlib/array/base/count-same-value-zero/example/index.js +++ b/lib/node_modules/@stdlib/array/base/count-same-value-zero/examples/index.js @@ -18,13 +18,13 @@ 'use strict'; -var sample = require( '@stdlib/random/sample' ); +var bernoulli = require( '@stdlib/random/array/bernoulli' ); var countSameValueZero = require( './../lib' ); -var x; -var n; -x = sample( [ 1, 2, 3, 4, 5 ] ); +var x = bernoulli( 10, 0.5, { + 'dtype': 'generic' +}); console.log( x ); -n = countSameValueZero( x, 1 ); +var n = countSameValueZero( x, 1 ); console.log( n ); diff --git a/lib/node_modules/@stdlib/array/base/count-same-value-zero/lib/index.js b/lib/node_modules/@stdlib/array/base/count-same-value-zero/lib/index.js index 75abf6a6044c..a115d7736b42 100644 --- a/lib/node_modules/@stdlib/array/base/count-same-value-zero/lib/index.js +++ b/lib/node_modules/@stdlib/array/base/count-same-value-zero/lib/index.js @@ -19,7 +19,7 @@ 'use strict'; /** -* Count the number of elements that are equal to a given value in an array. +* Count the number of elements in an array that are equal to a specified value. * * @module @stdlib/array/base/count-same-value-zero * diff --git a/lib/node_modules/@stdlib/array/base/count-same-value-zero/lib/main.js b/lib/node_modules/@stdlib/array/base/count-same-value-zero/lib/main.js index da037d08e1c3..cdff888a7ae6 100644 --- a/lib/node_modules/@stdlib/array/base/count-same-value-zero/lib/main.js +++ b/lib/node_modules/@stdlib/array/base/count-same-value-zero/lib/main.js @@ -33,12 +33,12 @@ var isSameValueZero = require( '@stdlib/assert/is-same-value-zero' ); // FUNCTIONS // /** -* Counts the number of elements that are equal to a given value in an indexed array. +* Counts the number of elements in an indexed array that are equal to a specified value. * * @private * @param {Collection} x - input array -* @param {*} value - given value -* @returns {NonNegativeInteger} number of elements that are equal to the given value +* @param {*} value - search value +* @returns {NonNegativeInteger} number of elements that are equal to a specified value * * @example * var x = [ 0, 0, 1, 0, 1 ]; @@ -60,12 +60,12 @@ function indexed( x, value ) { } /** -* Counts the number of elements that are equal to a given value in an accessor array. +* Counts the number of elements in an accessor array that are equal to a specified value. * * @private * @param {Collection} x - input array -* @param {*} value - given value -* @returns {NonNegativeInteger} number of elements that are equal to the given value +* @param {*} value - search value +* @returns {NonNegativeInteger} number of elements that are equal to a specified value * * @example * var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); @@ -92,16 +92,16 @@ function accessors( x, value ) { } /** -* Counts the number of elements that are equal to a given value in a complex array. +* Counts the number of elements in a complex array that are equal to a specified value. * * @private * @param {Collection} x - input array -* @param {*} value - given value -* @returns {NonNegativeInteger} number of elements that are equal to the given value +* @param {*} value - search value +* @returns {NonNegativeInteger} number of elements that are equal to a specified value * * @example -* var Complex128 = require( '@stdlib/complex/float64' ); * var Complex128Array = require( '@stdlib/array/complex128' ); +* var Complex128 = require( '@stdlib/complex/float64' ); * * var x = new Complex128Array( [ 1.0, 2.0, 0.0, 0.0, 3.0, 4.0, 0.0, 0.0 ] ); * @@ -118,7 +118,6 @@ function complex( x, value ) { if ( !isComplexLike( value ) ) { return 0; } - re = real( value ); im = imag( value ); @@ -126,10 +125,7 @@ function complex( x, value ) { n = 0; for ( i = 0; i < view.length; i += 2 ) { - if ( - isSameValueZero( view[ i ], re ) && - isSameValueZero( view[ i + 1 ], im ) - ) { + if ( isSameValueZero( view[ i ], re ) && isSameValueZero( view[ i+1 ], im ) ) { // eslint-disable-line max-len n += 1; } } @@ -140,11 +136,16 @@ function complex( x, value ) { // MAIN // /** -* Counts the number of elements that are equal to a given value in an array. +* Counts the number of elements in an array that are equal to a specified value. +* +* ## Notes +* +* - The function uses the SameValueZero Algorithm used by `TypedArray` and `ArrayBuffer` constructors, `Map` and `Set` operations, `String.prototype.includes`, and `Array.prototype.includes` since ES2016. +* - In contrast to an implementation based on the strict equality operator `===`, the function treats `NaNs` as the same value. * * @param {Collection} x - input array -* @param {*} value - given value -* @returns {NonNegativeInteger} number of elements that are equal to the given value +* @param {*} value - search value +* @returns {NonNegativeInteger} number of elements that are equal to a specified value * * @example * var countSameValueZero = require( '@stdlib/array/base/count-same-value-zero' ); diff --git a/lib/node_modules/@stdlib/array/base/count-same-value-zero/package.json b/lib/node_modules/@stdlib/array/base/count-same-value-zero/package.json index 130c9f6c734d..7ac01393e98b 100644 --- a/lib/node_modules/@stdlib/array/base/count-same-value-zero/package.json +++ b/lib/node_modules/@stdlib/array/base/count-same-value-zero/package.json @@ -1,7 +1,7 @@ { "name": "@stdlib/array/base/count-same-value-zero", "version": "0.0.0", - "description": "Count the number of elements that are equal to a given value in an array.", + "description": "Count the number of elements in an array that are equal to a specified value.", "license": "Apache-2.0", "author": { "name": "The Stdlib Authors", @@ -17,6 +17,7 @@ "directories": { "benchmark": "./benchmark", "doc": "./docs", + "example": "./examples", "lib": "./lib", "test": "./test" }, @@ -59,6 +60,7 @@ "summation", "countif", "total", - "same" + "same", + "equal" ] } diff --git a/lib/node_modules/@stdlib/array/base/count-same-value-zero/test/test.js b/lib/node_modules/@stdlib/array/base/count-same-value-zero/test/test.js index 65327a5b4a41..6fb5820d0592 100644 --- a/lib/node_modules/@stdlib/array/base/count-same-value-zero/test/test.js +++ b/lib/node_modules/@stdlib/array/base/count-same-value-zero/test/test.js @@ -45,11 +45,12 @@ tape( 'the function counts the number of same values (generic)', function test( x = [ 0, 1, 0, 1, 2 ]; expected = 2; actual = countSameValueZero( x, 1 ); + t.strictEqual( actual, expected, 'returns expected value' ); t.end(); }); -tape( 'the function consider positive and negative zeros to be indentical (generic)', function test( t ) { +tape( 'the function considers positive and negative zeros to be identical (generic)', function test( t ) { var expected; var actual; var x; @@ -67,7 +68,7 @@ tape( 'the function considers all NaN values to be identical (generic)', functio var actual; var x; - x = [ NaN, 0, NaN, 2, NaN, 9, NaN ]; + x = [ NaN, 0.0, NaN, 2.0, NaN, 9.0, NaN ]; expected = 4; actual = countSameValueZero( x, NaN ); @@ -87,7 +88,7 @@ tape( 'the function counts the number of same values (accessors)', function test t.end(); }); -tape( 'the function consider positive and negative zeros to be indentical (accessors)', function test( t ) { +tape( 'the function considers positive and negative zeros to be identical (accessors)', function test( t ) { var expected; var actual; var x; @@ -105,7 +106,7 @@ tape( 'the function considers all NaN values to be identical (accessors)', funct var actual; var x; - x = toAccessorArray( [ NaN, 0, NaN, 2, NaN, 9, NaN ] ); + x = toAccessorArray( [ NaN, 0.0, NaN, 2.0, NaN, 9.0, NaN ] ); expected = 4; actual = countSameValueZero( x, NaN ); @@ -126,7 +127,7 @@ tape( 'the function counts the number of same values (real typed array)', functi t.end(); }); -tape( 'the function consider positive and negative zeros to be indentical (real typed array)', function test( t ) { +tape( 'the function considers positive and negative zeros to be identical (real typed array)', function test( t ) { var expected; var actual; var x; @@ -144,7 +145,7 @@ tape( 'the function considers all NaN values to be identical (real typed array)' var actual; var x; - x = new Float32Array( [ NaN, 0, NaN, 2, NaN, 9, NaN ] ); + x = new Float32Array( [ NaN, 0.0, NaN, 2.0, NaN, 9.0, NaN ] ); expected = 4; actual = countSameValueZero( x, NaN ); @@ -160,16 +161,23 @@ tape( 'the function counts the number of same values (complex typed array)', fun x = new Complex128Array( [ 0.0, 0.0, 1.0, 0.0, 3.0, 4.0, 0.0, 5.0 ] ); expected = 1; actual = countSameValueZero( x, new Complex128( 3.0, 4.0 ) ); + + t.strictEqual( actual, expected, 'returns expected value' ); + + x = new Complex128Array( [ 0.0, 0.0, 1.0, 0.0, 3.0, 4.0, 0.0, 5.0 ] ); + expected = 0; + actual = countSameValueZero( x, 0.0 ); + t.strictEqual( actual, expected, 'returns expected value' ); t.end(); }); -tape( 'the function consider positive and negative zeros to be indentical (complex typed array)', function test( t ) { +tape( 'the function considers positive and negative zeros to be identical (complex typed array)', function test( t ) { var expected; var actual; var x; - x = new Complex128Array( [ 0.0, -0.0, 0.0, -0.0, 0.0, 0.0, -0.0, -0.0, -0.0, 0.0 ] ); + x = new Complex128Array( [ 0.0, -0.0, 0.0, -0.0, 0.0, 0.0, -0.0, -0.0, -0.0, 0.0 ] ); // eslint-disable-line max-len expected = 5; actual = countSameValueZero( x, new Complex128( 0.0, -0.0 ) ); diff --git a/lib/node_modules/@stdlib/array/base/count-same-value/README.md b/lib/node_modules/@stdlib/array/base/count-same-value/README.md index 92b701e2cae4..9fea78d76138 100644 --- a/lib/node_modules/@stdlib/array/base/count-same-value/README.md +++ b/lib/node_modules/@stdlib/array/base/count-same-value/README.md @@ -20,7 +20,7 @@ limitations under the License. # countSameValue -> Count the number of elements that are equal to a given value in an array. +> Count the number of elements in an array that are equal to a specified value. @@ -42,7 +42,7 @@ var countSameValue = require( '@stdlib/array/base/count-same-value' ); #### countSameValue( x, value ) -Counts the number of elements that are equal to a given value in an array. +Counts the number of elements in an array that are equal to a specified value. ```javascript var x = [ 0, 1, 0, 1, 2 ]; @@ -51,6 +51,15 @@ var out = countSameValue( x, 1 ); // returns 2 ``` +In contrast to an implementation using the strict equality operator `===`, the function distinguishes between `+0` and `-0` and treats `NaNs` as the same value. + +```javascript +var x = [ NaN, NaN, NaN ]; + +var out = countSameValue( x, NaN ); +// returns 3 +``` + @@ -59,6 +68,10 @@ var out = countSameValue( x, 1 );
+## Notes + +- The function uses the [SameValue Algorithm][@stdlib/assert/is-same-value] as specified in ECMAScript 5. +
@@ -72,10 +85,12 @@ var out = countSameValue( x, 1 ); ```javascript -var sample = require( '@stdlib/random/sample' ); +var bernoulli = require( '@stdlib/random/array/bernoulli' ); var countSameValue = require( '@stdlib/array/base/count-same-value' ); -var x = sample( [ 1, 2, 3, 4, 5 ] ); +var x = bernoulli( 10, 0.5, { + 'dtype': 'generic' +}); console.log( x ); var n = countSameValue( x, 1 ); @@ -106,6 +121,8 @@ console.log( n ); diff --git a/lib/node_modules/@stdlib/array/base/count-same-value/docs/repl.txt b/lib/node_modules/@stdlib/array/base/count-same-value/docs/repl.txt index dd1d1fc13c78..5fdd65f6dfa3 100644 --- a/lib/node_modules/@stdlib/array/base/count-same-value/docs/repl.txt +++ b/lib/node_modules/@stdlib/array/base/count-same-value/docs/repl.txt @@ -1,6 +1,9 @@ {{alias}}( x, value ) - Counts the number of elements that are equal to a given value in an array. + Counts the number of elements in an array that are equal to a specified + value. + + The function treats `-0` and `+0` as distinct and `NaNs` as the same. Parameters ---------- @@ -13,7 +16,7 @@ Returns ------- out: integer - Number of elements that are equal to the given value. + Number of elements that are equal to the specified value. Examples -------- diff --git a/lib/node_modules/@stdlib/array/base/count-same-value/docs/types/index.d.ts b/lib/node_modules/@stdlib/array/base/count-same-value/docs/types/index.d.ts index 3a656bd87735..24ccc5ab2957 100644 --- a/lib/node_modules/@stdlib/array/base/count-same-value/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/array/base/count-same-value/docs/types/index.d.ts @@ -23,11 +23,18 @@ import { Collection } from '@stdlib/types/array'; /** -* Counts the number of elements that are equal to a given value in an array. +* Counts the number of elements in an array that are equal to a specified value. +* +* ## Notes +* +* - The function uses the [SameValue Algorithm][ecma-262-same-value-algorithm], as specified in ECMAScript 5. +* - In contrast to the strict equality operator `===`, `-0` and `+0` are distinguishable and `NaNs` are the same. +* +* [ecma-262-same-value-algorithm]: http://ecma-international.org/ecma-262/5.1/#sec-9.12 * * @param x - input array -* @param value - given value -* @returns number of elements that are equal to the given value +* @param value - search value +* @returns number of elements that are equal to a specified value * * @example * var x = [ 0, 1, 0, 1, 1 ]; diff --git a/lib/node_modules/@stdlib/array/base/count-same-value/examples/index.js b/lib/node_modules/@stdlib/array/base/count-same-value/examples/index.js index f76a9ff3642c..7306f2b034c8 100644 --- a/lib/node_modules/@stdlib/array/base/count-same-value/examples/index.js +++ b/lib/node_modules/@stdlib/array/base/count-same-value/examples/index.js @@ -18,10 +18,12 @@ 'use strict'; -var sample = require( '@stdlib/random/sample' ); +var bernoulli = require( '@stdlib/random/array/bernoulli' ); var countSameValue = require( './../lib' ); -var x = sample( [ 1, 2, 3, 4, 5 ] ); +var x = bernoulli( 10, 0.5, { + 'dtype': 'generic' +}); console.log( x ); var n = countSameValue( x, 1 ); diff --git a/lib/node_modules/@stdlib/array/base/count-same-value/lib/index.js b/lib/node_modules/@stdlib/array/base/count-same-value/lib/index.js index bccf8d32d85f..9e28a14dde75 100644 --- a/lib/node_modules/@stdlib/array/base/count-same-value/lib/index.js +++ b/lib/node_modules/@stdlib/array/base/count-same-value/lib/index.js @@ -19,7 +19,7 @@ 'use strict'; /** -* Count the number of elements that are equal to a given value in an array. +* Count the number of elements in an array that are equal to a specified value. * * @module @stdlib/array/base/count-same-value * diff --git a/lib/node_modules/@stdlib/array/base/count-same-value/lib/main.js b/lib/node_modules/@stdlib/array/base/count-same-value/lib/main.js index 72de05892f6a..685cd1ef7c03 100644 --- a/lib/node_modules/@stdlib/array/base/count-same-value/lib/main.js +++ b/lib/node_modules/@stdlib/array/base/count-same-value/lib/main.js @@ -21,30 +21,30 @@ // MODULES // var isComplexLike = require( '@stdlib/assert/is-complex-like' ); -var real = require( '@stdlib/complex/real' ); -var imag = require( '@stdlib/complex/imag' ); var reinterpret = require( '@stdlib/strided/base/reinterpret-complex' ); var isComplexTypedArray = require( '@stdlib/array/base/assert/is-complex-typed-array' ); var isAccessorArray = require( '@stdlib/array/base/assert/is-accessor-array' ); var resolveGetter = require( '@stdlib/array/base/resolve-getter' ); var isSameValue = require( '@stdlib/assert/is-same-value' ); +var real = require( '@stdlib/complex/real' ); +var imag = require( '@stdlib/complex/imag' ); // FUNCTIONS // /** -* Counts the number of elements that are equal to a given value in an indexed array. +* Counts the number of elements in an array that are equal to a specified value. * * @private * @param {Collection} x - input array -* @param {*} value - given value -* @returns {NonNegativeInteger} number of elements that are equal to the given value +* @param {*} value - search value +* @returns {NonNegativeInteger} number of elements that are equal to a specified value * * @example -* var x = [ 0, 1, 0, 1 ]; +* var x = [ 0, 1, 0, 1, 1 ]; * * var n = indexed( x, 1 ); -* // returns 2 +* // returns 3 */ function indexed( x, value ) { var n; @@ -60,20 +60,20 @@ function indexed( x, value ) { } /** -* Counts the number of elements that are equal to a given value in an accessor array. +* Counts the number of elements in an accessor array that are equal to a specified value. * * @private * @param {Collection} x - input array -* @param {*} value - given value -* @returns {NonNegativeInteger} number of elements that are equal to the given value +* @param {*} value - search value +* @returns {NonNegativeInteger} number of elements that are equal to a provided value * * @example * var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); * -* var x = toAccessorArray( [ 0, 1, 0, 1 ] ); +* var x = toAccessorArray( [ 0, 1, 0, 1, 1 ] ); * * var n = accessors( x, 1 ); -* // returns 2 +* // returns 3 */ function accessors( x, value ) { var get; @@ -92,16 +92,16 @@ function accessors( x, value ) { } /** -* Counts the number of elements that are equal to a given value in a complex array. +* Counts the number of elements in a complex array that are equal to a specified value. * * @private * @param {Collection} x - input array -* @param {*} value - given value -* @returns {NonNegativeInteger} number of elements that are equal to the given value +* @param {*} value - search value +* @returns {NonNegativeInteger} number of elements that are equal to a specified value * * @example -* var Complex128 = require( '@stdlib/complex/float64' ); * var Complex128Array = require( '@stdlib/array/complex128' ); +* var Complex128 = require( '@stdlib/complex/float64' ); * * var x = new Complex128Array( [ 1.0, 2.0, 0.0, 0.0, 3.0, 4.0, 0.0, 0.0 ] ); * @@ -118,7 +118,6 @@ function complex( x, value ) { if ( !isComplexLike( value ) ) { return 0; } - re = real( value ); im = imag( value ); @@ -126,7 +125,7 @@ function complex( x, value ) { n = 0; for ( i = 0; i < view.length; i += 2 ) { - if ( isSameValue( view[ i ], re ) && isSameValue( view[ i + 1 ], im ) ) { + if ( isSameValue( view[ i ], re ) && isSameValue( view[ i+1 ], im ) ) { n += 1; } } @@ -137,11 +136,18 @@ function complex( x, value ) { // MAIN // /** -* Counts the number of elements that are equal to a given value in an array. +* Counts the number of elements in an array that are equal to a specified value. +* +* ## Notes +* +* - The function uses the [SameValue Algorithm][ecma-262-same-value-algorithm], as specified in ECMAScript 5. +* - In contrast to the strict equality operator `===`, `-0` and `+0` are distinguishable and `NaNs` are the same. +* +* [ecma-262-same-value-algorithm]: http://ecma-international.org/ecma-262/5.1/#sec-9.12 * * @param {Collection} x - input array -* @param {*} value - given value -* @returns {NonNegativeInteger} number of elements that are equal to the given value +* @param {*} value - search value +* @returns {NonNegativeInteger} number of elements that are equal to a specified value * * @example * var x = [ 0, 1, 0, 1, 1 ]; diff --git a/lib/node_modules/@stdlib/array/base/count-same-value/package.json b/lib/node_modules/@stdlib/array/base/count-same-value/package.json index 17a9abe39c3e..731e0336c439 100644 --- a/lib/node_modules/@stdlib/array/base/count-same-value/package.json +++ b/lib/node_modules/@stdlib/array/base/count-same-value/package.json @@ -1,7 +1,7 @@ { "name": "@stdlib/array/base/count-same-value", "version": "0.0.0", - "description": "Count the number of elements that are equal to a given value in an array.", + "description": "Count the number of elements in an array that are equal to a specified value.", "license": "Apache-2.0", "author": { "name": "The Stdlib Authors", @@ -60,6 +60,7 @@ "summation", "countif", "total", - "same" + "same", + "equal" ] } diff --git a/lib/node_modules/@stdlib/array/base/count-same-value/test/test.js b/lib/node_modules/@stdlib/array/base/count-same-value/test/test.js index 0d56293b2337..12fd47acd869 100644 --- a/lib/node_modules/@stdlib/array/base/count-same-value/test/test.js +++ b/lib/node_modules/@stdlib/array/base/count-same-value/test/test.js @@ -56,10 +56,15 @@ tape( 'the function distinguishes between positive and negative zeros (generic)' var x; x = [ 0.0, -0.0, 0.0, -0.0, 0.0, NaN, 1.0 ]; + expected = 3; actual = countSameValue( x, 0.0 ); + t.strictEqual( actual, expected, 'returns expected value' ); + expected = 2; + actual = countSameValue( x, -0.0 ); t.strictEqual( actual, expected, 'returns expected value' ); + t.end(); }); @@ -68,7 +73,7 @@ tape( 'the function considers all NaN values to be identical (generic)', functio var actual; var x; - x = [ NaN, 0, NaN, 2, NaN, 9, NaN ]; + x = [ NaN, 0.0, NaN, 2.0, NaN, 9.0, NaN ]; expected = 4; actual = countSameValue( x, NaN ); @@ -95,10 +100,15 @@ tape( 'the function distinguishes between positive and negative zeros (accessors var x; x = toAccessorArray( [ 0.0, -0.0, 0.0, -0.0, 0.0, NaN, 1.0 ] ); + expected = 3; actual = countSameValue( x, 0.0 ); + t.strictEqual( actual, expected, 'returns expected value' ); + expected = 2; + actual = countSameValue( x, -0.0 ); t.strictEqual( actual, expected, 'returns expected value' ); + t.end(); }); @@ -107,7 +117,7 @@ tape( 'the function considers all NaN values to be identical (accessors)', funct var actual; var x; - x = toAccessorArray( [ NaN, 0, NaN, 2, NaN, 9, NaN ] ); + x = toAccessorArray( [ NaN, 0.0, NaN, 2.0, NaN, 9.0, NaN ] ); expected = 4; actual = countSameValue( x, NaN ); @@ -134,10 +144,15 @@ tape( 'the function distinguishes between positive and negative zeros (real type var x; x = new Float32Array( [ 0.0, -0.0, 0.0, -0.0, 0.0, NaN, 1.0 ] ); + expected = 3; actual = countSameValue( x, 0.0 ); + t.strictEqual( actual, expected, 'returns expected value' ); + expected = 2; + actual = countSameValue( x, -0.0 ); t.strictEqual( actual, expected, 'returns expected value' ); + t.end(); }); @@ -146,7 +161,7 @@ tape( 'the function considers all NaN values to be identical (real typed array)' var actual; var x; - x = new Float32Array( [ NaN, 0, NaN, 2, NaN, 9, NaN ] ); + x = new Float32Array( [ NaN, 0.0, NaN, 2.0, NaN, 9.0, NaN ] ); expected = 4; actual = countSameValue( x, NaN ); @@ -163,6 +178,12 @@ tape( 'the function counts the number of same values (complex typed array)', fun expected = 1; actual = countSameValue( x, new Complex128( 3.0, 4.0 ) ); + t.strictEqual( actual, expected, 'returns expected value' ); + + x = new Complex128Array( [ 0.0, 0.0, 1.0, 0.0, 3.0, 4.0, 0.0, 5.0 ] ); + expected = 0; + actual = countSameValue( x, 0.0 ); + t.strictEqual( actual, expected, 'returns expected value' ); t.end(); }); @@ -172,7 +193,7 @@ tape( 'the function distinguishes between positive and negative zeros (complex t var actual; var x; - x = new Complex128Array( [ 0.0, -0.0, 0.0, -0.0, 0.0, 0.0, -0.0, -0.0, -0.0, 0.0 ] ); + x = new Complex128Array( [ 0.0, -0.0, 0.0, -0.0, 0.0, 0.0, -0.0, -0.0, -0.0, 0.0 ] ); // eslint-disable-line max-len expected = 2; actual = countSameValue( x, new Complex128( 0.0, -0.0 ) ); diff --git a/lib/node_modules/@stdlib/array/base/docs/types/index.d.ts b/lib/node_modules/@stdlib/array/base/docs/types/index.d.ts index b5ad9be9f8a0..fc6058e1fcac 100644 --- a/lib/node_modules/@stdlib/array/base/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/array/base/docs/types/index.d.ts @@ -64,6 +64,8 @@ import cartesianSquare = require( '@stdlib/array/base/cartesian-square' ); import copy = require( '@stdlib/array/base/copy' ); import copyIndexed = require( '@stdlib/array/base/copy-indexed' ); import countFalsy = require( '@stdlib/array/base/count-falsy' ); +import countSameValue = require( '@stdlib/array/base/count-same-value' ); +import countSameValueZero = require( '@stdlib/array/base/count-same-value-zero' ); import countTruthy = require( '@stdlib/array/base/count-truthy' ); import dedupe = require( '@stdlib/array/base/dedupe' ); import every = require( '@stdlib/array/base/every' ); @@ -1340,6 +1342,47 @@ interface Namespace { */ countFalsy: typeof countFalsy; + /** + * Counts the number of elements in an array that are equal to a specified value. + * + * ## Notes + * + * - The function uses the [SameValue Algorithm][ecma-262-same-value-algorithm], as specified in ECMAScript 5. + * - In contrast to the strict equality operator `===`, `-0` and `+0` are distinguishable and `NaNs` are the same. + * + * [ecma-262-same-value-algorithm]: http://ecma-international.org/ecma-262/5.1/#sec-9.12 + * + * @param x - input array + * @param value - search value + * @returns number of elements that are equal to a specified value + * + * @example + * var x = [ 0, 1, 0, 1, 1 ]; + * + * var out = ns.countSameValue( x, 1 ); + * // returns 3 + */ + countSameValue: typeof countSameValue; + + /** + * Counts the number of elements in an array that are equal to a specified value. + * + * ## Notes + * + * - In contrast to an implementation based on the strict equality operator `===`, the function treats `NaNs` as the same value. + * + * @param x - input array + * @param value - search value + * @returns number of elements that are equal to a specified value + * + * @example + * var x = [ 0, 1, 0, 1, 1 ]; + * + * var out = ns.countSameValueZero( x, 1 ); + * // returns 3 + */ + countSameValueZero: typeof countSameValueZero; + /** * Counts the number of truthy values in an array. * diff --git a/lib/node_modules/@stdlib/array/base/lib/index.js b/lib/node_modules/@stdlib/array/base/lib/index.js index 118a547c2af6..6c87e6ee14be 100644 --- a/lib/node_modules/@stdlib/array/base/lib/index.js +++ b/lib/node_modules/@stdlib/array/base/lib/index.js @@ -432,6 +432,24 @@ setReadOnly( ns, 'copyIndexed', require( '@stdlib/array/base/copy-indexed' ) ); */ setReadOnly( ns, 'countFalsy', require( '@stdlib/array/base/count-falsy' ) ); +/** +* @name countSameValue +* @memberof ns +* @readonly +* @type {Function} +* @see {@link module:@stdlib/array/base/count-same-value} +*/ +setReadOnly( ns, 'countSameValue', require( '@stdlib/array/base/count-same-value' ) ); + +/** +* @name countSameValueZero +* @memberof ns +* @readonly +* @type {Function} +* @see {@link module:@stdlib/array/base/count-same-value-zero} +*/ +setReadOnly( ns, 'countSameValueZero', require( '@stdlib/array/base/count-same-value-zero' ) ); + /** * @name countTruthy * @memberof ns diff --git a/lib/node_modules/@stdlib/array/mskreject/README.md b/lib/node_modules/@stdlib/array/mskreject/README.md index cbafb6172f73..2a7565e534ac 100644 --- a/lib/node_modules/@stdlib/array/mskreject/README.md +++ b/lib/node_modules/@stdlib/array/mskreject/README.md @@ -95,6 +95,12 @@ console.log( y ); @@ -105,6 +111,12 @@ console.log( y ); [@stdlib/array/dtypes]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/dtypes + + +[@stdlib/array/mskfilter]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/mskfilter + + + diff --git a/lib/node_modules/@stdlib/array/safe-casts/README.md b/lib/node_modules/@stdlib/array/safe-casts/README.md index 04ef1662bce4..4a6363e934b5 100644 --- a/lib/node_modules/@stdlib/array/safe-casts/README.md +++ b/lib/node_modules/@stdlib/array/safe-casts/README.md @@ -128,6 +128,7 @@ for ( i = 0; i < DTYPES.length; i++ ) { - [`@stdlib/array/convert`][@stdlib/array/convert]: convert an array to an array of a different data type. - [`@stdlib/array/convert-same`][@stdlib/array/convert-same]: convert an array to the same data type as a second input array. - [`@stdlib/array/dtypes`][@stdlib/array/dtypes]: list of array data types. +- [`@stdlib/array/mostly-safe-casts`][@stdlib/array/mostly-safe-casts]: return a list of array data types to which a provided array data type can be safely cast and, for floating-point data types, can be downcast. - [`@stdlib/array/same-kind-casts`][@stdlib/array/same-kind-casts]: return a list of array data types to which a provided array data type can be safely cast or cast within the same kind. - [`@stdlib/ndarray/safe-casts`][@stdlib/ndarray/safe-casts]: return a list of ndarray data types to which a provided ndarray data type can be safely cast. @@ -147,6 +148,8 @@ for ( i = 0; i < DTYPES.length; i++ ) { [@stdlib/array/convert-same]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/convert-same +[@stdlib/array/mostly-safe-casts]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/mostly-safe-casts + [@stdlib/array/same-kind-casts]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/same-kind-casts [@stdlib/ndarray/safe-casts]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/safe-casts diff --git a/lib/node_modules/@stdlib/array/slice/README.md b/lib/node_modules/@stdlib/array/slice/README.md index b2ae6bb2c5ed..bd5dde0c88e6 100644 --- a/lib/node_modules/@stdlib/array/slice/README.md +++ b/lib/node_modules/@stdlib/array/slice/README.md @@ -145,6 +145,12 @@ s = slice( x, 2, 4 ); @@ -153,6 +159,12 @@ s = slice( x, 2, 4 ); diff --git a/lib/node_modules/@stdlib/assert/README.md b/lib/node_modules/@stdlib/assert/README.md index 78e679283ef2..906aaea12a3f 100644 --- a/lib/node_modules/@stdlib/assert/README.md +++ b/lib/node_modules/@stdlib/assert/README.md @@ -442,6 +442,7 @@ The remaining namespace utilities are as follows: - [`isNonConfigurableProperty( value, property )`][@stdlib/assert/is-nonconfigurable-property]: test if an object's own property is non-configurable. - [`isNonEnumerablePropertyIn( value, property )`][@stdlib/assert/is-nonenumerable-property-in]: test if an object's own or inherited property is non-enumerable. - [`isNonEnumerableProperty( value, property )`][@stdlib/assert/is-nonenumerable-property]: test if an object's own property is non-enumerable. +- [`isNonNegativeFinite( value )`][@stdlib/assert/is-nonnegative-finite]: test if a value is a number having a nonnegative finite value. - [`isObjectLike( value )`][@stdlib/assert/is-object-like]: test if a value is object-like. - [`isOdd( value )`][@stdlib/assert/is-odd]: test if a value is an odd number. - [`isPascalcase( value )`][@stdlib/assert/is-pascalcase]: test if a value is a string in Pascal case. @@ -686,6 +687,8 @@ console.log( objectKeys( assert ) ); [@stdlib/assert/is-nonenumerable-property]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/assert/is-nonenumerable-property +[@stdlib/assert/is-nonnegative-finite]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/assert/is-nonnegative-finite + [@stdlib/assert/is-object-like]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/assert/is-object-like [@stdlib/assert/is-odd]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/assert/is-odd diff --git a/lib/node_modules/@stdlib/assert/docs/types/index.d.ts b/lib/node_modules/@stdlib/assert/docs/types/index.d.ts index 58f61e58a7b5..dbc1fc4f0926 100644 --- a/lib/node_modules/@stdlib/assert/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/assert/docs/types/index.d.ts @@ -206,6 +206,7 @@ import isNonConfigurableProperty = require( '@stdlib/assert/is-nonconfigurable-p import isNonConfigurablePropertyIn = require( '@stdlib/assert/is-nonconfigurable-property-in' ); import isNonEnumerableProperty = require( '@stdlib/assert/is-nonenumerable-property' ); import isNonEnumerablePropertyIn = require( '@stdlib/assert/is-nonenumerable-property-in' ); +import isNonNegativeFinite = require( '@stdlib/assert/is-nonnegative-finite' ); import isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ); import isNonNegativeIntegerArray = require( '@stdlib/assert/is-nonnegative-integer-array' ); import isNonNegativeNumber = require( '@stdlib/assert/is-nonnegative-number' ); @@ -4336,6 +4337,8 @@ interface Namespace { */ isNonEnumerablePropertyIn: typeof isNonEnumerablePropertyIn; + isNonNegativeFinite: typeof isNonNegativeFinite; + /** * Tests if a value is a nonnegative integer. * diff --git a/lib/node_modules/@stdlib/assert/is-nonnegative-finite/benchmark/benchmark.js b/lib/node_modules/@stdlib/assert/is-nonnegative-finite/benchmark/benchmark.js index 4e146b6c08a5..fffc22248bfc 100644 --- a/lib/node_modules/@stdlib/assert/is-nonnegative-finite/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/assert/is-nonnegative-finite/benchmark/benchmark.js @@ -33,16 +33,39 @@ var isNonNegativeFinite = require( './../lib' ); // MAIN // -bench( pkg+'::primitives', function benchmark( b ) { +bench( pkg+'::true,primitives', function benchmark( b ) { var values; var bool; var i; values = [ - '5', 5.0, 4.0, - 3.14, + 3.14 + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + bool = isNonNegativeFinite( values[ i % values.length ] ); + if ( typeof bool !== 'boolean' ) { + b.fail( 'should return a boolean' ); + } + } + b.toc(); + if ( !isBoolean( bool ) ) { + b.fail( 'should return a boolean' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::false,primitives', function benchmark( b ) { + var values; + var bool; + var i; + + values = [ + '5', -5.0, -4.0, NaN, @@ -69,7 +92,32 @@ bench( pkg+'::primitives', function benchmark( b ) { b.end(); }); -bench( pkg+'::objects', function benchmark( b ) { +bench( pkg+'::true,objects', function benchmark( b ) { + var values; + var bool; + var i; + + values = [ + new Number( 2.0 ), + new Number( 3.14 ) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + bool = isNonNegativeFinite( values[ i % values.length ] ); + if ( typeof bool !== 'boolean' ) { + b.fail( 'should return a boolean' ); + } + } + b.toc(); + if ( !isBoolean( bool ) ) { + b.fail( 'should return a boolean' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::false,objects', function benchmark( b ) { var values; var bool; var i; @@ -78,9 +126,7 @@ bench( pkg+'::objects', function benchmark( b ) { [], {}, function noop() {}, - new Number( 2.0 ), - new Number( -3.0 ), - new Number( 3.14 ) + new Number( -3.0 ) ]; b.tic(); @@ -98,16 +144,39 @@ bench( pkg+'::objects', function benchmark( b ) { b.end(); }); -bench( pkg+'::primitives:isPrimitive', function benchmark( b ) { +bench( pkg+'::true,primitives:isPrimitive', function benchmark( b ) { var values; var bool; var i; values = [ - '5', 5.0, 4.0, - 3.14, + 3.14 + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + bool = isNonNegativeFinite.isPrimitive( values[ i % values.length ] ); + if ( typeof bool !== 'boolean' ) { + b.fail( 'should return a boolean' ); + } + } + b.toc(); + if ( !isBoolean( bool ) ) { + b.fail( 'should return a boolean' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::false,primitives:isPrimitive', function benchmark( b ) { + var values; + var bool; + var i; + + values = [ + '5', -5.0, -4.0, NaN, @@ -134,7 +203,7 @@ bench( pkg+'::primitives:isPrimitive', function benchmark( b ) { b.end(); }); -bench( pkg+'::objects:isPrimitive', function benchmark( b ) { +bench( pkg+'::false,objects:isPrimitive', function benchmark( b ) { var values; var bool; var i; @@ -144,8 +213,8 @@ bench( pkg+'::objects:isPrimitive', function benchmark( b ) { {}, function noop() {}, new Number( 2.0 ), - new Number( -3.0 ), - new Number( 3.14 ) + new Number( 3.14 ), + new Number( -3.0 ) ]; b.tic(); @@ -163,7 +232,7 @@ bench( pkg+'::objects:isPrimitive', function benchmark( b ) { b.end(); }); -bench( pkg+'::primitives:isObject', function benchmark( b ) { +bench( pkg+'::false,primitives:isObject', function benchmark( b ) { var values; var bool; var i; @@ -199,7 +268,32 @@ bench( pkg+'::primitives:isObject', function benchmark( b ) { b.end(); }); -bench( pkg+'::objects:isObject', function benchmark( b ) { +bench( pkg+'::true,objects:isObject', function benchmark( b ) { + var values; + var bool; + var i; + + values = [ + new Number( 2.0 ), + new Number( 3.14 ) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + bool = isNonNegativeFinite.isObject( values[ i % values.length ] ); + if ( typeof bool !== 'boolean' ) { + b.fail( 'should return a boolean' ); + } + } + b.toc(); + if ( !isBoolean( bool ) ) { + b.fail( 'should return a boolean' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::false,objects:isObject', function benchmark( b ) { var values; var bool; var i; @@ -208,9 +302,7 @@ bench( pkg+'::objects:isObject', function benchmark( b ) { [], {}, function noop() {}, - new Number( 2.0 ), new Number( -3.0 ), - new Number( 3.14 ), new Number( PINF ) ]; diff --git a/lib/node_modules/@stdlib/assert/is-nonnegative-finite/docs/repl.txt b/lib/node_modules/@stdlib/assert/is-nonnegative-finite/docs/repl.txt index 20cef1007620..a9c310760bd8 100644 --- a/lib/node_modules/@stdlib/assert/is-nonnegative-finite/docs/repl.txt +++ b/lib/node_modules/@stdlib/assert/is-nonnegative-finite/docs/repl.txt @@ -16,7 +16,7 @@ -------- > var bool = {{alias}}( 5.0 ) true - > bool = {{alias}}( new Number( 5.0 ) ) + > bool = {{alias}}( new {{alias:@stdlib/number/ctor}}( 5.0 ) ) true > bool = {{alias}}( 3.14 ) true @@ -46,7 +46,7 @@ -------- > var bool = {{alias}}.isPrimitive( 3.0 ) true - > bool = {{alias}}.isPrimitive( new Number( 3.0 ) ) + > bool = {{alias}}.isPrimitive( new {{alias:@stdlib/number/ctor}}( 3.0 ) ) false @@ -68,7 +68,7 @@ -------- > var bool = {{alias}}.isObject( 3.0 ) false - > bool = {{alias}}.isObject( new Number( 3.0 ) ) + > bool = {{alias}}.isObject( new {{alias:@stdlib/number/ctor}}( 3.0 ) ) true diff --git a/lib/node_modules/@stdlib/assert/is-nonnegative-finite/docs/types/test.ts b/lib/node_modules/@stdlib/assert/is-nonnegative-finite/docs/types/test.ts index 22b808241a5c..e5b6c039ee4f 100644 --- a/lib/node_modules/@stdlib/assert/is-nonnegative-finite/docs/types/test.ts +++ b/lib/node_modules/@stdlib/assert/is-nonnegative-finite/docs/types/test.ts @@ -33,27 +33,27 @@ import isNonNegativeFinite = require( './index' ); isNonNegativeFinite( 2, 123 ); // $ExpectError } -// Attached to main export is an isPrimitive method which returns a boolean... +// Attached to main export is an `isPrimitive` method which returns a boolean... { // eslint-disable-next-line no-new-wrappers isNonNegativeFinite.isPrimitive( new Number( 2 ) ); // $ExpectType boolean isNonNegativeFinite.isPrimitive( 2 ); // $ExpectType boolean } -// The compiler throws an error if the isPrimitive method is provided an unsupported number of arguments... +// The compiler throws an error if the `isPrimitive` method is provided an unsupported number of arguments... { isNonNegativeFinite.isPrimitive(); // $ExpectError isNonNegativeFinite.isPrimitive( 2, 123 ); // $ExpectError } -// Attached to main export is an isObject method which returns a boolean... +// Attached to main export is an `isObject` method which returns a boolean... { // eslint-disable-next-line no-new-wrappers isNonNegativeFinite.isObject( new Number( 2 ) ); // $ExpectType boolean isNonNegativeFinite.isObject( 2 ); // $ExpectType boolean } -// The compiler throws an error if the isObject method is provided an unsupported number of arguments... +// The compiler throws an error if the `isObject` method is provided an unsupported number of arguments... { isNonNegativeFinite.isObject(); // $ExpectError isNonNegativeFinite.isObject( 2, 123 ); // $ExpectError diff --git a/lib/node_modules/@stdlib/assert/is-nonnegative-finite/test/test.main.js b/lib/node_modules/@stdlib/assert/is-nonnegative-finite/test/test.main.js index 3b331d86ea9b..c21a7292c5d6 100644 --- a/lib/node_modules/@stdlib/assert/is-nonnegative-finite/test/test.main.js +++ b/lib/node_modules/@stdlib/assert/is-nonnegative-finite/test/test.main.js @@ -33,9 +33,9 @@ tape( 'main export is a function', function test( t ) { t.end(); }); -tape( 'the function returns `true` if provided a number having a nonnegative number value', function test( t ) { - t.equal( isNonNegativeFinite( 5.0 ), true, 'returns true' ); - t.equal( isNonNegativeFinite( new Number( 5.0 ) ), true, 'returns true' ); +tape( 'the function returns `true` if provided a number having a nonnegative finite value', function test( t ) { + t.equal( isNonNegativeFinite( 5.0 ), true, 'returns expected value' ); + t.equal( isNonNegativeFinite( new Number( 5.0 ) ), true, 'returns expected value' ); t.end(); }); @@ -58,7 +58,7 @@ tape( 'the function returns `false` if not provided a number having a nonnegativ ]; for ( i = 0; i < values.length; i++ ) { - t.equal( isNonNegativeFinite( values[i] ), false, 'returns false when provided '+values[i] ); + t.equal( isNonNegativeFinite( values[i] ), false, 'returns expected value when provided '+values[i] ); } t.end(); }); diff --git a/lib/node_modules/@stdlib/assert/is-nonnegative-finite/test/test.object.js b/lib/node_modules/@stdlib/assert/is-nonnegative-finite/test/test.object.js index 04634f55c59f..4e629c33242d 100644 --- a/lib/node_modules/@stdlib/assert/is-nonnegative-finite/test/test.object.js +++ b/lib/node_modules/@stdlib/assert/is-nonnegative-finite/test/test.object.js @@ -33,18 +33,18 @@ tape( 'main export is a function', function test( t ) { t.end(); }); -tape( 'the function returns `true` if provided a number object having a nonnegative number value', function test( t ) { - t.equal( isNonNegativeFinite( new Number( 5.0 ) ), true, 'returns true' ); +tape( 'the function returns `true` if provided a number object having a nonnegative finite value', function test( t ) { + t.equal( isNonNegativeFinite( new Number( 5.0 ) ), true, 'returns expected value' ); t.end(); }); -tape( 'the function returns `false` if provided positive infinity', function test( t ) { - t.equal( isNonNegativeFinite( 1.0/0.0 ), false, 'returns false' ); +tape( 'the function returns `false` if provided positive infinity (primitive)', function test( t ) { + t.equal( isNonNegativeFinite( 1.0/0.0 ), false, 'returns expected value' ); t.end(); }); -tape( 'the function returns `false` if provided positive infinity', function test( t ) { - t.equal( isNonNegativeFinite( new Number( 1.0/0.0 ) ), false, 'returns false' ); +tape( 'the function returns `false` if provided positive infinity (object)', function test( t ) { + t.equal( isNonNegativeFinite( new Number( 1.0/0.0 ) ), false, 'returns expected value' ); t.end(); }); @@ -68,7 +68,7 @@ tape( 'the function returns `false` if not provided a nonnegative number', funct ]; for ( i = 0; i < values.length; i++ ) { - t.equal( isNonNegativeFinite( values[i] ), false, 'returns false when provided '+values[i] ); + t.equal( isNonNegativeFinite( values[i] ), false, 'returns expected value when provided '+values[i] ); } t.end(); }); diff --git a/lib/node_modules/@stdlib/assert/is-nonnegative-finite/test/test.primitive.js b/lib/node_modules/@stdlib/assert/is-nonnegative-finite/test/test.primitive.js index c591b193225b..033d352c1444 100644 --- a/lib/node_modules/@stdlib/assert/is-nonnegative-finite/test/test.primitive.js +++ b/lib/node_modules/@stdlib/assert/is-nonnegative-finite/test/test.primitive.js @@ -34,22 +34,22 @@ tape( 'main export is a function', function test( t ) { }); tape( 'the function returns `true` if provided a primitive number having a nonnegative finite value', function test( t ) { - t.equal( isNonNegativeFinite( 3.0 ), true, 'returns true' ); + t.equal( isNonNegativeFinite( 3.0 ), true, 'returns expected value' ); t.end(); }); tape( 'the function returns `false` if provided a number object, even if the number has a nonnegative finite value', function test( t ) { - t.equal( isNonNegativeFinite( new Number( 5.0 ) ), false, 'returns false' ); + t.equal( isNonNegativeFinite( new Number( 5.0 ) ), false, 'returns expected value' ); t.end(); }); -tape( 'the function returns `false` if provided positive infinity', function test( t ) { - t.equal( isNonNegativeFinite( 1.0/0.0 ), false, 'returns false' ); +tape( 'the function returns `false` if provided positive infinity (primitive)', function test( t ) { + t.equal( isNonNegativeFinite( 1.0/0.0 ), false, 'returns expected value' ); t.end(); }); -tape( 'the function returns `false` if provided a number object with positive infinity', function test( t ) { - t.equal( isNonNegativeFinite( new Number( 1.0/0.0 ) ), false, 'returns false' ); +tape( 'the function returns `false` if provided positive infinity (object)', function test( t ) { + t.equal( isNonNegativeFinite( new Number( 1.0/0.0 ) ), false, 'returns expected value' ); t.end(); }); @@ -70,7 +70,7 @@ tape( 'the function returns `false` if not provided a nonnegative finite number' ]; for ( i = 0; i < values.length; i++ ) { - t.equal( isNonNegativeFinite( values[i] ), false, 'returns false when provided '+values[i] ); + t.equal( isNonNegativeFinite( values[i] ), false, 'returns expected value when provided '+values[i] ); } t.end(); }); diff --git a/lib/node_modules/@stdlib/assert/lib/index.js b/lib/node_modules/@stdlib/assert/lib/index.js index 8690646d6bc5..b108d78075a9 100644 --- a/lib/node_modules/@stdlib/assert/lib/index.js +++ b/lib/node_modules/@stdlib/assert/lib/index.js @@ -1710,6 +1710,15 @@ setReadOnly( ns, 'isNonEnumerableProperty', require( '@stdlib/assert/is-nonenume */ setReadOnly( ns, 'isNonEnumerablePropertyIn', require( '@stdlib/assert/is-nonenumerable-property-in' ) ); +/** +* @name isNonNegativeFinite +* @memberof ns +* @readonly +* @type {Function} +* @see {@link module:@stdlib/assert/is-nonnegative-finite} +*/ +setReadOnly( ns, 'isNonNegativeFinite', require( '@stdlib/assert/is-nonnegative-finite' ) ); + /** * @name isNonNegativeInteger * @memberof ns diff --git a/lib/node_modules/@stdlib/blas/base/ddot/src/ddot.c b/lib/node_modules/@stdlib/blas/base/ddot/src/ddot.c index f8158a9f5a1e..ce2e3f491916 100644 --- a/lib/node_modules/@stdlib/blas/base/ddot/src/ddot.c +++ b/lib/node_modules/@stdlib/blas/base/ddot/src/ddot.c @@ -31,7 +31,7 @@ * @param strideX X stride length * @param Y second array * @param strideY Y stride length -* @returns the dot product +* @return the dot product */ double c_ddot( const int N, const double *X, const int strideX, const double *Y, const int strideY ) { double dot; diff --git a/lib/node_modules/@stdlib/blas/base/ddot/src/ddot_cblas.c b/lib/node_modules/@stdlib/blas/base/ddot/src/ddot_cblas.c index 361c568c9c74..f4102a94bae4 100644 --- a/lib/node_modules/@stdlib/blas/base/ddot/src/ddot_cblas.c +++ b/lib/node_modules/@stdlib/blas/base/ddot/src/ddot_cblas.c @@ -27,7 +27,7 @@ * @param strideX X stride length * @param Y second array * @param strideY Y stride length -* @returns the dot product +* @return the dot product */ double c_ddot( const int N, const double *X, const int strideX, const double *Y, const int strideY ) { return cblas_ddot( N, X, strideX, Y, strideY ); diff --git a/lib/node_modules/@stdlib/blas/base/ddot/src/ddot_f.c b/lib/node_modules/@stdlib/blas/base/ddot/src/ddot_f.c index 5164387844b0..a9fbcd251f11 100644 --- a/lib/node_modules/@stdlib/blas/base/ddot/src/ddot_f.c +++ b/lib/node_modules/@stdlib/blas/base/ddot/src/ddot_f.c @@ -32,7 +32,7 @@ * @param strideX X stride length * @param Y second array * @param strideY Y stride length -* @returns the dot product +* @return the dot product */ double c_ddot( const int N, const double *X, const int strideX, const double *Y, const int strideY ) { double dot; diff --git a/lib/node_modules/@stdlib/blas/base/dsdot/src/dsdot.c b/lib/node_modules/@stdlib/blas/base/dsdot/src/dsdot.c index d931405d0e5d..21b1117e8fa1 100644 --- a/lib/node_modules/@stdlib/blas/base/dsdot/src/dsdot.c +++ b/lib/node_modules/@stdlib/blas/base/dsdot/src/dsdot.c @@ -31,7 +31,7 @@ * @param strideX X stride length * @param Y second array * @param strideY Y stride length -* @returns the dot product +* @return the dot product */ double c_dsdot( const int N, const float *X, const int strideX, const float *Y, const int strideY ) { double dot; diff --git a/lib/node_modules/@stdlib/blas/base/dsdot/src/dsdot_cblas.c b/lib/node_modules/@stdlib/blas/base/dsdot/src/dsdot_cblas.c index f12e8fa985f0..31cda7eaa7e8 100644 --- a/lib/node_modules/@stdlib/blas/base/dsdot/src/dsdot_cblas.c +++ b/lib/node_modules/@stdlib/blas/base/dsdot/src/dsdot_cblas.c @@ -27,7 +27,7 @@ * @param strideX X stride length * @param Y second array * @param strideY Y stride length -* @returns the dot product +* @return the dot product */ double c_dsdot( const int N, const float *X, const int strideX, const float *Y, const int strideY ) { return cblas_dsdot( N, X, strideX, Y, strideY ); diff --git a/lib/node_modules/@stdlib/blas/base/dsdot/src/dsdot_f.c b/lib/node_modules/@stdlib/blas/base/dsdot/src/dsdot_f.c index e8e3c7db1fba..1c06f1645a51 100644 --- a/lib/node_modules/@stdlib/blas/base/dsdot/src/dsdot_f.c +++ b/lib/node_modules/@stdlib/blas/base/dsdot/src/dsdot_f.c @@ -32,7 +32,7 @@ * @param strideX X stride length * @param Y second array * @param strideY Y stride length -* @returns the dot product +* @return the dot product */ double c_dsdot( const int N, const float *X, const int strideX, const float *Y, const int strideY ) { double dot; diff --git a/lib/node_modules/@stdlib/blas/base/sdot/src/sdot.c b/lib/node_modules/@stdlib/blas/base/sdot/src/sdot.c index e983ccf1f7d0..8ed48cfb8c07 100644 --- a/lib/node_modules/@stdlib/blas/base/sdot/src/sdot.c +++ b/lib/node_modules/@stdlib/blas/base/sdot/src/sdot.c @@ -31,7 +31,7 @@ * @param strideX X stride length * @param Y second array * @param strideY Y stride length -* @returns the dot product +* @return the dot product */ float c_sdot( const int N, const float *X, const int strideX, const float *Y, const int strideY ) { float dot; diff --git a/lib/node_modules/@stdlib/blas/base/sdot/src/sdot_cblas.c b/lib/node_modules/@stdlib/blas/base/sdot/src/sdot_cblas.c index 94080105ada1..a725236c56c3 100644 --- a/lib/node_modules/@stdlib/blas/base/sdot/src/sdot_cblas.c +++ b/lib/node_modules/@stdlib/blas/base/sdot/src/sdot_cblas.c @@ -27,7 +27,7 @@ * @param strideX X stride length * @param Y second array * @param strideY Y stride length -* @returns the dot product +* @return the dot product */ float c_sdot( const int N, const float *X, const int strideX, const float *Y, const int strideY ) { return cblas_sdot( N, X, strideX, Y, strideY ); diff --git a/lib/node_modules/@stdlib/blas/base/sdot/src/sdot_f.c b/lib/node_modules/@stdlib/blas/base/sdot/src/sdot_f.c index 34997c6e4c89..743baf7d52b8 100644 --- a/lib/node_modules/@stdlib/blas/base/sdot/src/sdot_f.c +++ b/lib/node_modules/@stdlib/blas/base/sdot/src/sdot_f.c @@ -34,7 +34,7 @@ * @param strideX X stride length * @param Y second array * @param strideY Y stride length -* @returns the dot product +* @return the dot product */ float c_sdot( const int N, const float *X, const int strideX, const float *Y, const int strideY ) { float dot; diff --git a/lib/node_modules/@stdlib/blas/base/sdsdot/src/sdsdot.c b/lib/node_modules/@stdlib/blas/base/sdsdot/src/sdsdot.c index b9a1ea335e0c..ba3d601c02d5 100644 --- a/lib/node_modules/@stdlib/blas/base/sdsdot/src/sdsdot.c +++ b/lib/node_modules/@stdlib/blas/base/sdsdot/src/sdsdot.c @@ -32,7 +32,7 @@ * @param strideX X stride length * @param Y second array * @param strideY Y stride length -* @returns dot product +* @return dot product */ float c_sdsdot( const int N, const float scalar, const float *X, const int strideX, const float *Y, const int strideY ) { double dot; diff --git a/lib/node_modules/@stdlib/blas/base/sdsdot/src/sdsdot_cblas.c b/lib/node_modules/@stdlib/blas/base/sdsdot/src/sdsdot_cblas.c index 99da4d35fde2..bd47331e1331 100644 --- a/lib/node_modules/@stdlib/blas/base/sdsdot/src/sdsdot_cblas.c +++ b/lib/node_modules/@stdlib/blas/base/sdsdot/src/sdsdot_cblas.c @@ -28,7 +28,7 @@ * @param strideX X stride length * @param Y second array * @param strideY Y stride length -* @returns dot product +* @return dot product */ float c_sdsdot( const int N, const float scalar, const float *X, const int strideX, const float *Y, const int strideY ) { return cblas_sdsdot( N, scalar, X, strideX, Y, strideY ); diff --git a/lib/node_modules/@stdlib/blas/base/sdsdot/src/sdsdot_f.c b/lib/node_modules/@stdlib/blas/base/sdsdot/src/sdsdot_f.c index 1b2dfeb84274..8e5de1ca0cde 100644 --- a/lib/node_modules/@stdlib/blas/base/sdsdot/src/sdsdot_f.c +++ b/lib/node_modules/@stdlib/blas/base/sdsdot/src/sdsdot_f.c @@ -35,7 +35,7 @@ * @param strideX X stride length * @param Y second array * @param strideY Y stride length -* @returns dot product +* @return dot product */ float c_sdsdot( const int N, const float scalar, const float *X, const int strideX, const float *Y, const int strideY ) { float dot; diff --git a/lib/node_modules/@stdlib/blas/ext/base/dfill/manifest.json b/lib/node_modules/@stdlib/blas/ext/base/dfill/manifest.json index 73f6ab7a43ce..ac53b3713b39 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dfill/manifest.json +++ b/lib/node_modules/@stdlib/blas/ext/base/dfill/manifest.json @@ -1,5 +1,7 @@ { - "options": {}, + "options": { + "task": "build" + }, "fields": [ { "field": "src", @@ -24,6 +26,7 @@ ], "confs": [ { + "task": "build", "src": [ "./src/dfill.c" ], @@ -37,10 +40,38 @@ "dependencies": [ "@stdlib/napi/export", "@stdlib/napi/argv", - "@stdlib/napi/argv-float", + "@stdlib/napi/argv-double", "@stdlib/napi/argv-int64", "@stdlib/napi/argv-strided-float64array" ] + }, + { + "task": "benchmark", + "src": [ + "./src/dfill.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lm" + ], + "libpath": [], + "dependencies": [] + }, + { + "task": "examples", + "src": [ + "./src/dfill.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lm" + ], + "libpath": [], + "dependencies": [] } ] } diff --git a/lib/node_modules/@stdlib/blas/ext/base/dfill/src/addon.c b/lib/node_modules/@stdlib/blas/ext/base/dfill/src/addon.c index 68f6c2932b46..7dad3fc5f75e 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dfill/src/addon.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dfill/src/addon.c @@ -19,7 +19,7 @@ #include "stdlib/blas/ext/base/dfill.h" #include "stdlib/napi/export.h" #include "stdlib/napi/argv.h" -#include "stdlib/napi/argv_float.h" +#include "stdlib/napi/argv_double.h" #include "stdlib/napi/argv_int64.h" #include "stdlib/napi/argv_strided_float64array.h" #include @@ -35,7 +35,7 @@ static napi_value addon( napi_env env, napi_callback_info info ) { STDLIB_NAPI_ARGV( env, info, argv, argc, 4 ); STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); - STDLIB_NAPI_ARGV_FLOAT( env, alpha, argv, 1 ); + STDLIB_NAPI_ARGV_DOUBLE( env, alpha, argv, 1 ); STDLIB_NAPI_ARGV_INT64( env, stride, argv, 3 ); STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, stride, argv, 2 ); c_dfill( N, alpha, X, stride ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnansum/README.md b/lib/node_modules/@stdlib/blas/ext/base/dnansum/README.md index 0953a2abe6a5..65d2e16fc993 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnansum/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/dnansum/README.md @@ -56,16 +56,14 @@ The function has the following parameters: - **x**: input [`Float64Array`][@stdlib/array/float64]. - **stride**: index increment for `x`. -The `N` and `stride` parameters determine which elements in `x` are accessed at runtime. For example, to compute the sum of every other element in `x`, +The `N` and `stride` parameters determine which elements in the strided array are accessed at runtime. For example, to compute the sum of every other element in the strided array, ```javascript var Float64Array = require( '@stdlib/array/float64' ); -var floor = require( '@stdlib/math/base/special/floor' ); var x = new Float64Array( [ 1.0, 2.0, NaN, -7.0, NaN, 3.0, 4.0, 2.0 ] ); -var N = floor( x.length / 2 ); -var v = dnansum( N, x, 2 ); +var v = dnansum( 4, x, 2 ); // returns 5.0 ``` @@ -75,14 +73,11 @@ Note that indexing is relative to the first index. To introduce an offset, use [ ```javascript var Float64Array = require( '@stdlib/array/float64' ); -var floor = require( '@stdlib/math/base/special/floor' ); var x0 = new Float64Array( [ 2.0, 1.0, NaN, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element -var N = floor( x0.length / 2 ); - -var v = dnansum( N, x1, 2 ); +var v = dnansum( 4, x1, 2 ); // returns 5.0 ``` @@ -94,9 +89,8 @@ Computes the sum of double-precision floating-point strided array elements, igno var Float64Array = require( '@stdlib/array/float64' ); var x = new Float64Array( [ 1.0, -2.0, NaN, 2.0 ] ); -var N = x.length; -var v = dnansum.ndarray( N, x, 1, 0 ); +var v = dnansum.ndarray( 4, x, 1, 0 ); // returns 1.0 ``` @@ -104,16 +98,14 @@ The function has the following additional parameters: - **offset**: starting index for `x`. -While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, the `offset` parameter supports indexing semantics based on a starting index. For example, to calculate the sum of every other value in `x` starting from the second value +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, the offset parameter supports indexing semantics based on a starting index. For example, to calculate the sum of every other value in the strided array starting from the second value ```javascript var Float64Array = require( '@stdlib/array/float64' ); -var floor = require( '@stdlib/math/base/special/floor' ); var x = new Float64Array( [ 2.0, 1.0, NaN, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); -var N = floor( x.length / 2 ); -var v = dnansum.ndarray( N, x, 2, 1 ); +var v = dnansum.ndarray( 4, x, 2, 1 ); // returns 5.0 ``` @@ -138,22 +130,20 @@ var v = dnansum.ndarray( N, x, 2, 1 ); ```javascript -var randu = require( '@stdlib/random/base/randu' ); -var round = require( '@stdlib/math/base/special/round' ); +var bernoulli = require( '@stdlib/random/base/bernoulli' ); +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); var Float64Array = require( '@stdlib/array/float64' ); var dnansum = require( '@stdlib/blas/ext/base/dnansum' ); -var x; -var i; - -x = new Float64Array( 10 ); -for ( i = 0; i < x.length; i++ ) { - if ( randu() < 0.2 ) { - x[ i ] = NaN; - } else { - x[ i ] = round( randu()*100.0 ); +function clbk() { + if ( bernoulli( 0.7 ) > 0 ) { + return discreteUniform( 0, 100 ); } + return NaN; } + +var x = filledarrayBy( 10, 'float64', clbk ); console.log( x ); var v = dnansum( x.length, x, 1 ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnansum/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/dnansum/benchmark/benchmark.js index 53d4f922b671..0fcbb379f7ee 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnansum/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dnansum/benchmark/benchmark.js @@ -21,10 +21,11 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var bernoulli = require( '@stdlib/random/base/bernoulli' ); +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); -var Float64Array = require( '@stdlib/array/float64' ); var pkg = require( './../package.json' ).name; var dnansum = require( './../lib/dnansum.js' ); @@ -39,18 +40,15 @@ var dnansum = require( './../lib/dnansum.js' ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; + var x = filledarrayBy( len, 'float64', clbk ); + return benchmark; - x = new Float64Array( len ); - for ( i = 0; i < x.length; i++ ) { - if ( randu() < 0.2 ) { - x[ i ] = NaN; - } else { - x[ i ] = ( randu()*10.0 ) - 20.0; + function clbk() { + if ( bernoulli( 0.7 ) > 0 ) { + return discreteUniform( -10, 10 ); } + return NaN; } - return benchmark; function benchmark( b ) { var v; diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnansum/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/blas/ext/base/dnansum/benchmark/benchmark.native.js index 04f0fe1e1ba2..4105b34fb5a7 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnansum/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dnansum/benchmark/benchmark.native.js @@ -22,10 +22,11 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var bernoulli = require( '@stdlib/random/base/bernoulli' ); +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); -var Float64Array = require( '@stdlib/array/float64' ); var tryRequire = require( '@stdlib/utils/try-require' ); var pkg = require( './../package.json' ).name; @@ -48,18 +49,15 @@ var opts = { * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; + var x = filledarrayBy( len, 'float64', clbk ); + return benchmark; - x = new Float64Array( len ); - for ( i = 0; i < x.length; i++ ) { - if ( randu() < 0.2 ) { - x[ i ] = NaN; - } else { - x[ i ] = ( randu()*10.0 ) - 20.0; + function clbk() { + if ( bernoulli( 0.7 ) > 0 ) { + return discreteUniform( -10, 10 ); } + return NaN; } - return benchmark; function benchmark( b ) { var v; diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnansum/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/dnansum/benchmark/benchmark.ndarray.js index 90f347619bd4..a9a8301bca10 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnansum/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dnansum/benchmark/benchmark.ndarray.js @@ -21,10 +21,11 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var bernoulli = require( '@stdlib/random/base/bernoulli' ); +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); -var Float64Array = require( '@stdlib/array/float64' ); var pkg = require( './../package.json' ).name; var dnansum = require( './../lib/ndarray.js' ); @@ -39,18 +40,15 @@ var dnansum = require( './../lib/ndarray.js' ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; + var x = filledarrayBy( len, 'float64', clbk ); + return benchmark; - x = new Float64Array( len ); - for ( i = 0; i < x.length; i++ ) { - if ( randu() < 0.2 ) { - x[ i ] = NaN; - } else { - x[ i ] = ( randu()*10.0 ) - 20.0; + function clbk() { + if ( bernoulli( 0.7 ) > 0 ) { + return discreteUniform( -10, 10 ); } + return NaN; } - return benchmark; function benchmark( b ) { var v; diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnansum/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/dnansum/benchmark/benchmark.ndarray.native.js index fd8a1af04a37..4555fee4066a 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnansum/benchmark/benchmark.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dnansum/benchmark/benchmark.ndarray.native.js @@ -22,10 +22,11 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var bernoulli = require( '@stdlib/random/base/bernoulli' ); +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); -var Float64Array = require( '@stdlib/array/float64' ); var tryRequire = require( '@stdlib/utils/try-require' ); var pkg = require( './../package.json' ).name; @@ -48,18 +49,15 @@ var opts = { * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; + var x = filledarrayBy( len, 'float64', clbk ); + return benchmark; - x = new Float64Array( len ); - for ( i = 0; i < x.length; i++ ) { - if ( randu() < 0.2 ) { - x[ i ] = NaN; - } else { - x[ i ] = ( randu()*10.0 ) - 20.0; + function clbk() { + if ( bernoulli( 0.7 ) > 0 ) { + return discreteUniform( -10, 10 ); } + return NaN; } - return benchmark; function benchmark( b ) { var v; diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnansum/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/dnansum/docs/repl.txt index 69eb7e0304e2..74ea39830edd 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnansum/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/dnansum/docs/repl.txt @@ -3,8 +3,8 @@ Computes the sum of double-precision floating-point strided array elements, ignoring `NaN` values. - The `N` and `stride` parameters determine which elements in `x` are accessed - at runtime. + The `N` and `stride` parameters determine which elements in the strided + array are accessed at runtime. Indexing is relative to the first index. To introduce an offset, use a typed array view. @@ -36,19 +36,16 @@ // Using `N` and `stride` parameters: > x = new {{alias:@stdlib/array/float64}}( [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0, NaN, NaN ] ); - > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); - > var stride = 2; - > {{alias}}( N, x, stride ) + > {{alias}}( 4, x, 2 ) 1.0 // Using view offsets: > var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0, NaN, NaN ] ); > var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); - > N = {{alias:@stdlib/math/base/special/floor}}( x0.length / 2 ); - > stride = 2; - > {{alias}}( N, x1, stride ) + > {{alias}}( 4, x1, 2 ) -1.0 + {{alias}}.ndarray( N, x, stride, offset ) Computes the sum of double-precision floating-point strided array elements, ignoring `NaN` values and using alternative indexing semantics. @@ -85,8 +82,7 @@ // Using offset parameter: > var x = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0, NaN, NaN ] ); - > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); - > {{alias}}.ndarray( N, x, 2, 1 ) + > {{alias}}.ndarray( 4, x, 2, 1 ) -1.0 See Also diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnansum/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/dnansum/examples/index.js index c933d5744061..246ae3a016e3 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnansum/examples/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dnansum/examples/index.js @@ -18,22 +18,19 @@ 'use strict'; -var randu = require( '@stdlib/random/base/randu' ); -var round = require( '@stdlib/math/base/special/round' ); -var Float64Array = require( '@stdlib/array/float64' ); +var bernoulli = require( '@stdlib/random/base/bernoulli' ); +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); var dnansum = require( './../lib' ); -var x; -var i; - -x = new Float64Array( 10 ); -for ( i = 0; i < x.length; i++ ) { - if ( randu() < 0.2 ) { - x[ i ] = NaN; - } else { - x[ i ] = round( randu()*100.0 ); +function clbk() { + if ( bernoulli( 0.7 ) > 0 ) { + return discreteUniform( 0, 100 ); } + return NaN; } + +var x = filledarrayBy( 10, 'float64', clbk ); console.log( x ); var v = dnansum( x.length, x, 1 ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnansum/include.gypi b/lib/node_modules/@stdlib/blas/ext/base/dnansum/include.gypi index 868c5c12e852..26476a8c2655 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnansum/include.gypi +++ b/lib/node_modules/@stdlib/blas/ext/base/dnansum/include.gypi @@ -36,7 +36,7 @@ # Source files: 'src_files': [ - '<(src_dir)/addon.cpp', + '<(src_dir)/addon.c', ' +#include + +/** +* Receives JavaScript callback invocation data. +* +* @private +* @param env environment under which the function is invoked +* @param info callback data +* @return Node-API value +*/ +static napi_value addon( napi_env env, napi_callback_info info ) { + STDLIB_NAPI_ARGV( env, info, argv, argc, 3 ); + STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); + STDLIB_NAPI_ARGV_INT64( env, stride, argv, 2 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, stride, argv, 1 ); + + napi_value v; + status = napi_create_double( env, stdlib_strided_dnansum( N, (double *)X, stride ), &v ); + assert( status == napi_ok ); + return v; +} + +STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnansum/src/addon.cpp b/lib/node_modules/@stdlib/blas/ext/base/dnansum/src/addon.cpp deleted file mode 100644 index f940e5b56233..000000000000 --- a/lib/node_modules/@stdlib/blas/ext/base/dnansum/src/addon.cpp +++ /dev/null @@ -1,117 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/blas/ext/base/dnansum.h" -#include -#include -#include -#include -#include - -/** -* Add-on namespace. -*/ -namespace stdlib_blas_ext_base_dnansum { - - /** - * Computes the sum of double-precision floating-point strided array elements, ignoring `NaN` values. - * - * ## Notes - * - * - When called from JavaScript, the function expects three arguments: - * - * - `N`: number of indexed elements - * - `X`: input array - * - `stride`: stride length - */ - napi_value node_dnansum( napi_env env, napi_callback_info info ) { - napi_status status; - - size_t argc = 3; - napi_value argv[ 3 ]; - status = napi_get_cb_info( env, info, &argc, argv, nullptr, nullptr ); - assert( status == napi_ok ); - - if ( argc < 3 ) { - napi_throw_error( env, nullptr, "invalid invocation. Must provide 3 arguments." ); - return nullptr; - } - - napi_valuetype vtype0; - status = napi_typeof( env, argv[ 0 ], &vtype0 ); - assert( status == napi_ok ); - if ( vtype0 != napi_number ) { - napi_throw_type_error( env, nullptr, "invalid argument. First argument must be a number." ); - return nullptr; - } - - bool res; - status = napi_is_typedarray( env, argv[ 1 ], &res ); - assert( status == napi_ok ); - if ( res == false ) { - napi_throw_type_error( env, nullptr, "invalid argument. Second argument must be a Float64Array." ); - return nullptr; - } - - napi_valuetype vtype2; - status = napi_typeof( env, argv[ 2 ], &vtype2 ); - assert( status == napi_ok ); - if ( vtype2 != napi_number ) { - napi_throw_type_error( env, nullptr, "invalid argument. Third argument must be a number." ); - return nullptr; - } - - int64_t N; - status = napi_get_value_int64( env, argv[ 0 ], &N ); - assert( status == napi_ok ); - - int64_t stride; - status = napi_get_value_int64( env, argv[ 2 ], &stride ); - assert( status == napi_ok ); - - napi_typedarray_type vtype1; - size_t xlen; - void *X; - status = napi_get_typedarray_info( env, argv[ 1 ], &vtype1, &xlen, &X, nullptr, nullptr ); - assert( status == napi_ok ); - if ( vtype1 != napi_float64_array ) { - napi_throw_type_error( env, nullptr, "invalid argument. Second argument must be a Float64Array." ); - return nullptr; - } - if ( (N-1)*llabs(stride) >= (int64_t)xlen ) { - napi_throw_range_error( env, nullptr, "invalid argument. Second argument has insufficient elements based on the associated stride and the number of indexed elements." ); - return nullptr; - } - - napi_value v; - status = napi_create_double( env, stdlib_strided_dnansum( N, (double *)X, stride ), &v ); - assert( status == napi_ok ); - - return v; - } - - napi_value Init( napi_env env, napi_value exports ) { - napi_status status; - napi_value fcn; - status = napi_create_function( env, "exports", NAPI_AUTO_LENGTH, node_dnansum, NULL, &fcn ); - assert( status == napi_ok ); - return fcn; - } - - NAPI_MODULE( NODE_GYP_MODULE_NAME, Init ) -} // end namespace stdlib_blas_ext_base_dnansum diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnansum/test/test.dnansum.js b/lib/node_modules/@stdlib/blas/ext/base/dnansum/test/test.dnansum.js index 05f6926805e8..e25debdc7b48 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnansum/test/test.dnansum.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dnansum/test/test.dnansum.js @@ -21,7 +21,6 @@ // MODULES // var tape = require( 'tape' ); -var floor = require( '@stdlib/math/base/special/floor' ); var Float64Array = require( '@stdlib/array/float64' ); var dnansum = require( './../lib/dnansum.js' ); @@ -35,7 +34,7 @@ tape( 'main export is a function', function test( t ) { }); tape( 'the function has an arity of 3', function test( t ) { - t.strictEqual( dnansum.length, 3, 'has expected arity' ); + t.strictEqual( dnansum.length, 3, 'returns expected value' ); t.end(); }); @@ -106,7 +105,6 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first }); tape( 'the function supports a `stride` parameter', function test( t ) { - var N; var x; var v; @@ -123,15 +121,13 @@ tape( 'the function supports a `stride` parameter', function test( t ) { NaN ]); - N = floor( x.length / 2 ); - v = dnansum( N, x, 2 ); + v = dnansum( 5, x, 2 ); t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', function test( t ) { - var N; var x; var v; @@ -148,8 +144,7 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) 2.0 ]); - N = floor( x.length / 2 ); - v = dnansum( N, x, -2 ); + v = dnansum( 5, x, -2 ); t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); @@ -170,7 +165,6 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f tape( 'the function supports view offsets', function test( t ) { var x0; var x1; - var N; var v; x0 = new Float64Array([ @@ -188,9 +182,8 @@ tape( 'the function supports view offsets', function test( t ) { ]); x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element - N = floor(x1.length / 2); - v = dnansum( N, x1, 2 ); + v = dnansum( 5, x1, 2 ); t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnansum/test/test.dnansum.native.js b/lib/node_modules/@stdlib/blas/ext/base/dnansum/test/test.dnansum.native.js index e093e1e4761f..03cda2e6e3c5 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnansum/test/test.dnansum.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dnansum/test/test.dnansum.native.js @@ -22,7 +22,6 @@ var resolve = require( 'path' ).resolve; var tape = require( 'tape' ); -var floor = require( '@stdlib/math/base/special/floor' ); var Float64Array = require( '@stdlib/array/float64' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -44,7 +43,7 @@ tape( 'main export is a function', opts, function test( t ) { }); tape( 'the function has an arity of 3', opts, function test( t ) { - t.strictEqual( dnansum.length, 3, 'has expected arity' ); + t.strictEqual( dnansum.length, 3, 'returns expected value' ); t.end(); }); @@ -197,7 +196,6 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first }); tape( 'the function supports a `stride` parameter', opts, function test( t ) { - var N; var x; var v; @@ -214,15 +212,13 @@ tape( 'the function supports a `stride` parameter', opts, function test( t ) { NaN ]); - N = floor( x.length / 2 ); - v = dnansum( N, x, 2 ); + v = dnansum( 5, x, 2 ); t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', opts, function test( t ) { - var N; var x; var v; @@ -239,8 +235,7 @@ tape( 'the function supports a negative `stride` parameter', opts, function test 2.0 ]); - N = floor( x.length / 2 ); - v = dnansum( N, x, -2 ); + v = dnansum( 5, x, -2 ); t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); @@ -261,7 +256,6 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f tape( 'the function supports view offsets', opts, function test( t ) { var x0; var x1; - var N; var v; x0 = new Float64Array([ @@ -279,9 +273,8 @@ tape( 'the function supports view offsets', opts, function test( t ) { ]); x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element - N = floor(x1.length / 2); - v = dnansum( N, x1, 2 ); + v = dnansum( 5, x1, 2 ); t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnansum/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/dnansum/test/test.ndarray.js index 361ac6999269..48ca7508619b 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnansum/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dnansum/test/test.ndarray.js @@ -21,7 +21,6 @@ // MODULES // var tape = require( 'tape' ); -var floor = require( '@stdlib/math/base/special/floor' ); var Float64Array = require( '@stdlib/array/float64' ); var dnansum = require( './../lib/ndarray.js' ); @@ -35,7 +34,7 @@ tape( 'main export is a function', function test( t ) { }); tape( 'the function has an arity of 4', function test( t ) { - t.strictEqual( dnansum.length, 4, 'has expected arity' ); + t.strictEqual( dnansum.length, 4, 'returns expected value' ); t.end(); }); @@ -106,7 +105,6 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first }); tape( 'the function supports a `stride` parameter', function test( t ) { - var N; var x; var v; @@ -123,15 +121,13 @@ tape( 'the function supports a `stride` parameter', function test( t ) { NaN ]); - N = floor( x.length / 2 ); - v = dnansum( N, x, 2, 0 ); + v = dnansum( 5, x, 2, 0 ); t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', function test( t ) { - var N; var x; var v; @@ -148,8 +144,7 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) 2.0 ]); - N = floor( x.length / 2 ); - v = dnansum( N, x, -2, 8 ); + v = dnansum( 5, x, -2, 8 ); t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); @@ -168,7 +163,6 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f }); tape( 'the function supports an `offset` parameter', function test( t ) { - var N; var x; var v; @@ -184,9 +178,8 @@ tape( 'the function supports an `offset` parameter', function test( t ) { NaN, NaN // 4 ]); - N = floor( x.length / 2 ); - v = dnansum( N, x, 2, 1 ); + v = dnansum( 5, x, 2, 1 ); t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnansum/test/test.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/dnansum/test/test.ndarray.native.js index a951545d2fca..b8dfd12b141a 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnansum/test/test.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dnansum/test/test.ndarray.native.js @@ -22,7 +22,6 @@ var resolve = require( 'path' ).resolve; var tape = require( 'tape' ); -var floor = require( '@stdlib/math/base/special/floor' ); var Float64Array = require( '@stdlib/array/float64' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -44,7 +43,7 @@ tape( 'main export is a function', opts, function test( t ) { }); tape( 'the function has an arity of 4', opts, function test( t ) { - t.strictEqual( dnansum.length, 4, 'has expected arity' ); + t.strictEqual( dnansum.length, 4, 'returns expected value' ); t.end(); }); @@ -115,7 +114,6 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first }); tape( 'the function supports a `stride` parameter', opts, function test( t ) { - var N; var x; var v; @@ -132,15 +130,13 @@ tape( 'the function supports a `stride` parameter', opts, function test( t ) { NaN ]); - N = floor( x.length / 2 ); - v = dnansum( N, x, 2, 0 ); + v = dnansum( 5, x, 2, 0 ); t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', opts, function test( t ) { - var N; var x; var v; @@ -157,8 +153,7 @@ tape( 'the function supports a negative `stride` parameter', opts, function test 2.0 ]); - N = floor( x.length / 2 ); - v = dnansum( N, x, -2, 8 ); + v = dnansum( 5, x, -2, 8 ); t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); @@ -177,7 +172,6 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f }); tape( 'the function supports an `offset` parameter', opts, function test( t ) { - var N; var x; var v; @@ -193,9 +187,8 @@ tape( 'the function supports an `offset` parameter', opts, function test( t ) { NaN, NaN // 4 ]); - N = floor( x.length / 2 ); - v = dnansum( N, x, 2, 1 ); + v = dnansum( 5, x, 2, 1 ); t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/drev/README.md b/lib/node_modules/@stdlib/blas/ext/base/drev/README.md index cd96b556c811..303719c37d5d 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/drev/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/drev/README.md @@ -49,16 +49,14 @@ The function has the following parameters: - **x**: input [`Float64Array`][@stdlib/array/float64]. - **stride**: index increment. -The `N` and `stride` parameters determine which elements in `x` are accessed at runtime. For example, to reverse every other element +The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to reverse every other element ```javascript var Float64Array = require( '@stdlib/array/float64' ); -var floor = require( '@stdlib/math/base/special/floor' ); var x = new Float64Array( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ] ); -var N = floor( x.length / 2 ); -drev( N, x, 2 ); +drev( 4, x, 2 ); // x => [ -1.0, 1.0, 4.0, -5.0, 3.0, 0.0, -2.0, -3.0 ] ``` @@ -66,17 +64,15 @@ Note that indexing is relative to the first index. To introduce an offset, use [ ```javascript var Float64Array = require( '@stdlib/array/float64' ); -var floor = require( '@stdlib/math/base/special/floor' ); // Initial array... var x0 = new Float64Array( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] ); // Create an offset view... var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element -var N = floor( x0.length/2 ); // Reverse every other element... -drev( N, x1, 2 ); +drev( 3, x1, 2 ); // x0 => [ 1.0, -6.0, 3.0, -4.0, 5.0, -2.0 ] ``` @@ -97,7 +93,7 @@ The function has the following additional parameters: - **offset**: starting index. -While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, the `offset` parameter supports indexing semantics based on a starting index. For example, to access only the last three elements of `x` +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, the `offset` parameter supports indexing semantics based on a starting index. For example, to access only the last three elements of the strided array ```javascript var Float64Array = require( '@stdlib/array/float64' ); @@ -116,7 +112,7 @@ drev.ndarray( 3, x, 1, x.length-3 ); ## Notes -- If `N <= 0`, both functions return `x` unchanged. +- If `N <= 0`, both functions return the strided array unchanged. - Where possible, one should "reverse" a strided array by negating its stride, which is an `O(1)` operation, in contrast to performing an in-place reversal, which is `O(N)`. However, in certain circumstances, this is not tenable, particularly when interfacing with libraries which assume and/or expect a specific memory layout (e.g., strided array elements arranged in memory in ascending order). In general, when working with strided arrays, only perform an in-place reversal when strictly necessary. @@ -130,27 +126,11 @@ drev.ndarray( 3, x, 1, x.length-3 ); ```javascript -var round = require( '@stdlib/math/base/special/round' ); -var randu = require( '@stdlib/random/base/randu' ); -var Float64Array = require( '@stdlib/array/float64' ); +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory; +var filledarrayBy = require( '@stdlib/array/filled-by' ); var drev = require( '@stdlib/blas/ext/base/drev' ); -var rand; -var sign; -var x; -var i; - -x = new Float64Array( 10 ); -for ( i = 0; i < x.length; i++ ) { - rand = round( randu()*100.0 ); - sign = randu(); - if ( sign < 0.5 ) { - sign = -1.0; - } else { - sign = 1.0; - } - x[ i ] = sign * rand; -} +var x = filledarrayBy( 10, 'float64', discreteUniform( -100.0, 100.0 ) ); console.log( x ); drev( x.length, x, 1 ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/drev/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/drev/benchmark/benchmark.js index ef6d4c5a25fa..208e82c3fcd1 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/drev/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/ext/base/drev/benchmark/benchmark.js @@ -21,14 +21,19 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/base/uniform' ).factory; +var filledarrayBy = require( '@stdlib/array/filled-by' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); -var Float64Array = require( '@stdlib/array/float64' ); var pkg = require( './../package.json' ).name; var drev = require( './../lib/drev.js' ); +// VARIABLES // + +var rand = uniform( -10.0, 10.0 ); + + // FUNCTIONS // /** @@ -39,13 +44,7 @@ var drev = require( './../lib/drev.js' ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; - - x = new Float64Array( len ); - for ( i = 0; i < len; i++ ) { - x[ i ] = ( randu()*20.0 ) - 10.0; - } + var x = filledarrayBy( len, 'float64', rand ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/drev/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/blas/ext/base/drev/benchmark/benchmark.native.js index c4f94980dac4..645e5a8efc0b 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/drev/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/drev/benchmark/benchmark.native.js @@ -22,10 +22,10 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/base/uniform' ).factory; +var filledarrayBy = require( '@stdlib/array/filled-by' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); -var Float64Array = require( '@stdlib/array/float64' ); var tryRequire = require( '@stdlib/utils/try-require' ); var pkg = require( './../package.json' ).name; @@ -36,6 +36,7 @@ var drev = tryRequire( resolve( __dirname, './../lib/drev.native.js' ) ); var opts = { 'skip': ( drev instanceof Error ) }; +var rand = uniform( -10.0, 10.0 ); // FUNCTIONS // @@ -48,13 +49,7 @@ var opts = { * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; - - x = new Float64Array( len ); - for ( i = 0; i < len; i++ ) { - x[ i ] = ( randu()*20.0 ) - 10.0; - } + var x = filledarrayBy( len, 'float64', rand ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/drev/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/drev/benchmark/benchmark.ndarray.js index bf79f3c4820e..12e2b5d4ee8a 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/drev/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/drev/benchmark/benchmark.ndarray.js @@ -21,14 +21,19 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/base/uniform' ).factory; +var filledarrayBy = require( '@stdlib/array/filled-by' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); -var Float64Array = require( '@stdlib/array/float64' ); var pkg = require( './../package.json' ).name; var drev = require( './../lib/ndarray.js' ); +// VARIABLES // + +var rand = uniform( -10.0, 10.0 ); + + // FUNCTIONS // /** @@ -39,13 +44,7 @@ var drev = require( './../lib/ndarray.js' ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; - - x = new Float64Array( len ); - for ( i = 0; i < len; i++ ) { - x[ i ] = ( randu()*20.0 ) - 10.0; - } + var x = filledarrayBy( len, 'float64', rand ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/drev/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/drev/benchmark/benchmark.ndarray.native.js index 390183940e34..20fa4384274b 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/drev/benchmark/benchmark.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/drev/benchmark/benchmark.ndarray.native.js @@ -22,10 +22,10 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/base/uniform' ).factory; +var filledarrayBy = require( '@stdlib/array/filled-by' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); -var Float64Array = require( '@stdlib/array/float64' ); var tryRequire = require( '@stdlib/utils/try-require' ); var pkg = require( './../package.json' ).name; @@ -36,6 +36,7 @@ var drev = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ); var opts = { 'skip': ( drev instanceof Error ) }; +var rand = uniform( -10.0, 10.0 ); // FUNCTIONS // @@ -48,13 +49,7 @@ var opts = { * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; - - x = new Float64Array( len ); - for ( i = 0; i < len; i++ ) { - x[ i ] = ( randu()*20.0 ) - 10.0; - } + var x = filledarrayBy( len, 'float64', rand ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/drev/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/drev/docs/repl.txt index d2dd4b869b41..c5e6d177e560 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/drev/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/drev/docs/repl.txt @@ -2,8 +2,8 @@ {{alias}}( N, x, stride ) Reverses a double-precision floating-point strided array in-place. - The `N` and `stride` parameters determine which elements in `x` are accessed - at runtime. + The `N` and stride parameters determine which elements in the strided array + are accessed at runtime. Indexing is relative to the first index. To introduce an offset, use typed array views. @@ -24,7 +24,7 @@ Returns ------- x: Float64Array - Input array `x`. + Input array. Examples -------- @@ -33,21 +33,20 @@ > {{alias}}( x.length, x, 1 ) [ -3.0, -1.0, 4.0, -5.0, 3.0, 1.0, -2.0 ] - // Using `N` and `stride` parameters: + // Using `N` and stride parameters: > x = new {{alias:@stdlib/array/float64}}( [ -2.0, 1.0, 3.0, -5.0, 4.0, -1.0, -3.0 ] ); - > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); - > {{alias}}( N, x, 2 ) + > {{alias}}( 3, x, 2 ) [ 4.0, 1.0, 3.0, -5.0, -2.0, -1.0, -3.0 ] // Using view offsets: > var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] ); > var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); - > N = {{alias:@stdlib/math/base/special/floor}}( x0.length / 2 ); - > {{alias}}( N, x1, 2 ) + > {{alias}}( 3, x1, 2 ) [ -6.0, 3.0, -4.0, 5.0, -2.0 ] > x0 [ 1.0, -6.0, 3.0, -4.0, 5.0, -2.0 ] + {{alias}}.ndarray( N, x, stride, offset ) Reverses a double-precision floating-point strided array in-place using alternative indexing semantics. @@ -73,7 +72,7 @@ Returns ------- x: Float64Array - Input array `x`. + Input array. Examples -------- @@ -84,8 +83,7 @@ // Using an index offset: > x = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] ); - > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); - > {{alias}}.ndarray( N, x, 2, 1 ) + > {{alias}}.ndarray( 3, x, 2, 1 ) [ 1.0, -6.0, 3.0, -4.0, 5.0, -2.0 ] See Also diff --git a/lib/node_modules/@stdlib/blas/ext/base/drev/examples/c/example.c b/lib/node_modules/@stdlib/blas/ext/base/drev/examples/c/example.c index 0f2392129f0c..4eaf0f085dc5 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/drev/examples/c/example.c +++ b/lib/node_modules/@stdlib/blas/ext/base/drev/examples/c/example.c @@ -24,13 +24,13 @@ int main( void ) { double x[] = { 1.0, -2.0, 3.0, -4.0, 5.0, -6.0, 7.0, -8.0 }; // Specify the number of elements: - int N = 8; + const int N = 8; // Specify a stride: - int strideX = 1; + const int stride = 1; // Reverse the array: - c_drev( N, x, strideX ); + c_drev( N, x, stride ); // Print the result: for ( int i = 0; i < 8; i++ ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/drev/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/drev/examples/index.js index 36b7a5a10a76..3b35c07cb4a2 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/drev/examples/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/drev/examples/index.js @@ -18,27 +18,11 @@ 'use strict'; -var round = require( '@stdlib/math/base/special/round' ); -var randu = require( '@stdlib/random/base/randu' ); -var Float64Array = require( '@stdlib/array/float64' ); +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory; +var filledarrayBy = require( '@stdlib/array/filled-by' ); var drev = require( './../lib' ); -var rand; -var sign; -var x; -var i; - -x = new Float64Array( 10 ); -for ( i = 0; i < x.length; i++ ) { - rand = round( randu()*100.0 ); - sign = randu(); - if ( sign < 0.5 ) { - sign = -1.0; - } else { - sign = 1.0; - } - x[ i ] = sign * rand; -} +var x = filledarrayBy( 10, 'float64', discreteUniform( -100.0, 100.0 ) ); console.log( x ); drev( x.length, x, 1 ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/drev/include.gypi b/lib/node_modules/@stdlib/blas/ext/base/drev/include.gypi index 868c5c12e852..26476a8c2655 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/drev/include.gypi +++ b/lib/node_modules/@stdlib/blas/ext/base/drev/include.gypi @@ -36,7 +36,7 @@ # Source files: 'src_files': [ - '<(src_dir)/addon.cpp', + '<(src_dir)/addon.c', ' + +/** +* Receives JavaScript callback invocation data. +* +* @private +* @param env environment under which the function is invoked +* @param info callback data +* @return Node-API value +*/ +static napi_value addon( napi_env env, napi_callback_info info ) { + STDLIB_NAPI_ARGV( env, info, argv, argc, 3 ); + STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); + STDLIB_NAPI_ARGV_INT64( env, stride, argv, 2 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, stride, argv, 1 ); + c_drev( N, (double *)X, stride ); + return NULL; +} + +STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) diff --git a/lib/node_modules/@stdlib/blas/ext/base/drev/src/addon.cpp b/lib/node_modules/@stdlib/blas/ext/base/drev/src/addon.cpp deleted file mode 100644 index 14b65e979918..000000000000 --- a/lib/node_modules/@stdlib/blas/ext/base/drev/src/addon.cpp +++ /dev/null @@ -1,115 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/blas/ext/base/drev.h" -#include -#include -#include -#include -#include - -/** -* Add-on namespace. -*/ -namespace stdlib_blas_ext_base_drev { - - /** - * Reverses a double-precision floating-point strided array in-place. - * - * ## Notes - * - * - When called from JavaScript, the function expects three arguments: - * - * - `N`: number of indexed elements - * - `X`: input array - * - `strideX`: `X` stride length - */ - napi_value node_drev( napi_env env, napi_callback_info info ) { - napi_status status; - - size_t argc = 3; - napi_value argv[ 3 ]; - status = napi_get_cb_info( env, info, &argc, argv, nullptr, nullptr ); - assert( status == napi_ok ); - - if ( argc < 3 ) { - napi_throw_error( env, nullptr, "invalid invocation. Must provide 3 arguments." ); - return nullptr; - } - - napi_valuetype vtype0; - status = napi_typeof( env, argv[ 0 ], &vtype0 ); - assert( status == napi_ok ); - if ( vtype0 != napi_number ) { - napi_throw_type_error( env, nullptr, "invalid argument. First argument must be a number." ); - return nullptr; - } - - bool res1; - status = napi_is_typedarray( env, argv[ 1 ], &res1 ); - assert( status == napi_ok ); - if ( res1 == false ) { - napi_throw_type_error( env, nullptr, "invalid argument. Second argument must be a Float64Array." ); - return nullptr; - } - - napi_valuetype vtype2; - status = napi_typeof( env, argv[ 2 ], &vtype2 ); - assert( status == napi_ok ); - if ( vtype2 != napi_number ) { - napi_throw_type_error( env, nullptr, "invalid argument. Third argument must be a number." ); - return nullptr; - } - - int64_t N; - status = napi_get_value_int64( env, argv[ 0 ], &N ); - assert( status == napi_ok ); - - int64_t strideX; - status = napi_get_value_int64( env, argv[ 2 ], &strideX ); - assert( status == napi_ok ); - - napi_typedarray_type vtype1; - size_t xlen; - void *X; - status = napi_get_typedarray_info( env, argv[ 1 ], &vtype1, &xlen, &X, nullptr, nullptr ); - assert( status == napi_ok ); - if ( vtype1 != napi_float64_array ) { - napi_throw_type_error( env, nullptr, "invalid argument. Second argument must be a Float64Array." ); - return nullptr; - } - if ( (N-1)*llabs(strideX) >= (int64_t)xlen ) { - napi_throw_range_error( env, nullptr, "invalid argument. Second argument has insufficient elements based on the associated stride and the number of indexed elements." ); - return nullptr; - } - - c_drev( N, (double *)X, strideX ); - - return nullptr; - } - - napi_value Init( napi_env env, napi_value exports ) { - napi_status status; - napi_value fcn; - status = napi_create_function( env, "exports", NAPI_AUTO_LENGTH, node_drev, NULL, &fcn ); - assert( status == napi_ok ); - return fcn; - } - - NAPI_MODULE( NODE_GYP_MODULE_NAME, Init ) -} // end namespace stdlib_blas_ext_base_drev diff --git a/lib/node_modules/@stdlib/blas/ext/base/drev/test/test.drev.js b/lib/node_modules/@stdlib/blas/ext/base/drev/test/test.drev.js index a2a1dba3809c..430aebd82bdf 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/drev/test/test.drev.js +++ b/lib/node_modules/@stdlib/blas/ext/base/drev/test/test.drev.js @@ -34,7 +34,7 @@ tape( 'main export is a function', function test( t ) { }); tape( 'the function has an arity of 3', function test( t ) { - t.strictEqual( drev.length, 3, 'has expected arity' ); + t.strictEqual( drev.length, 3, 'returns expected value' ); t.end(); }); @@ -92,7 +92,7 @@ tape( 'the function returns a reference to the input array', function test( t ) t.end(); }); -tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `x` unchanged', function test( t ) { +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns the input array unchanged', function test( t ) { var expected; var x; diff --git a/lib/node_modules/@stdlib/blas/ext/base/drev/test/test.drev.native.js b/lib/node_modules/@stdlib/blas/ext/base/drev/test/test.drev.native.js index 922d7b9c4e8c..a9aa8127a2d9 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/drev/test/test.drev.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/drev/test/test.drev.native.js @@ -43,7 +43,7 @@ tape( 'main export is a function', opts, function test( t ) { }); tape( 'the function has an arity of 3', opts, function test( t ) { - t.strictEqual( drev.length, 3, 'has expected arity' ); + t.strictEqual( drev.length, 3, 'returns expected value' ); t.end(); }); @@ -101,7 +101,7 @@ tape( 'the function returns a reference to the input array', opts, function test t.end(); }); -tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `x` unchanged', opts, function test( t ) { +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns the input array unchanged', opts, function test( t ) { var expected; var x; diff --git a/lib/node_modules/@stdlib/blas/ext/base/drev/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/drev/test/test.js index 2e874f0d606e..0cac7202ec2c 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/drev/test/test.js +++ b/lib/node_modules/@stdlib/blas/ext/base/drev/test/test.js @@ -51,7 +51,7 @@ tape( 'if a native implementation is available, the main export is the native im '@stdlib/utils/try-require': tryRequire }); - t.strictEqual( drev, mock, 'returns native implementation' ); + t.strictEqual( drev, mock, 'returns expected value' ); t.end(); function tryRequire() { @@ -73,7 +73,7 @@ tape( 'if a native implementation is not available, the main export is a JavaScr '@stdlib/utils/try-require': tryRequire }); - t.strictEqual( drev, main, 'returns JavaScript implementation' ); + t.strictEqual( drev, main, 'returns expected value' ); t.end(); function tryRequire() { diff --git a/lib/node_modules/@stdlib/blas/ext/base/drev/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/drev/test/test.ndarray.js index 50ad9f9d2083..9b7300bb8c66 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/drev/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/drev/test/test.ndarray.js @@ -34,7 +34,7 @@ tape( 'main export is a function', function test( t ) { }); tape( 'the function has an arity of 4', function test( t ) { - t.strictEqual( drev.length, 4, 'has expected arity' ); + t.strictEqual( drev.length, 4, 'returns expected value' ); t.end(); }); @@ -92,7 +92,7 @@ tape( 'the function returns a reference to the input array', function test( t ) t.end(); }); -tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `x` unchanged', function test( t ) { +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns the input array unchanged', function test( t ) { var expected; var x; diff --git a/lib/node_modules/@stdlib/blas/ext/base/drev/test/test.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/drev/test/test.ndarray.native.js index efe913a750f0..bac1a2c1ac4f 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/drev/test/test.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/drev/test/test.ndarray.native.js @@ -43,7 +43,7 @@ tape( 'main export is a function', opts, function test( t ) { }); tape( 'the function has an arity of 4', opts, function test( t ) { - t.strictEqual( drev.length, 4, 'has expected arity' ); + t.strictEqual( drev.length, 4, 'returns expected value' ); t.end(); }); @@ -101,7 +101,7 @@ tape( 'the function returns a reference to the input array', opts, function test t.end(); }); -tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `x` unchanged', opts, function test( t ) { +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns the input array unchanged', opts, function test( t ) { var expected; var x; diff --git a/lib/node_modules/@stdlib/blas/ext/base/dssum/README.md b/lib/node_modules/@stdlib/blas/ext/base/dssum/README.md index bd69d901a0a3..7444c74e3662 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dssum/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/dssum/README.md @@ -56,16 +56,14 @@ The function has the following parameters: - **x**: input [`Float32Array`][@stdlib/array/float32]. - **stride**: index increment for `x`. -The `N` and `stride` parameters determine which elements in `x` are accessed at runtime. For example, to compute the sum of every other element in `x`, +The `N` and `stride` parameters determine which elements in the strided array are accessed at runtime. For example, to compute the sum of every other element in the strided array, ```javascript var Float32Array = require( '@stdlib/array/float32' ); -var floor = require( '@stdlib/math/base/special/floor' ); var x = new Float32Array( [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0 ] ); -var N = floor( x.length / 2 ); -var v = dssum( N, x, 2 ); +var v = dssum( 4, x, 2 ); // returns 5.0 ``` @@ -75,14 +73,11 @@ Note that indexing is relative to the first index. To introduce an offset, use [ ```javascript var Float32Array = require( '@stdlib/array/float32' ); -var floor = require( '@stdlib/math/base/special/floor' ); var x0 = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); var x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element -var N = floor( x0.length / 2 ); - -var v = dssum( N, x1, 2 ); +var v = dssum( 4, x1, 2 ); // returns 5.0 ``` @@ -94,9 +89,8 @@ Computes the sum of single-precision floating-point strided array elements using var Float32Array = require( '@stdlib/array/float32' ); var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); -var N = x.length; -var v = dssum.ndarray( N, x, 1, 0 ); +var v = dssum.ndarray( 3, x, 1, 0 ); // returns 1.0 ``` @@ -104,16 +98,14 @@ The function has the following additional parameters: - **offset**: starting index for `x`. -While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, the `offset` parameter supports indexing semantics based on a starting index. For example, to calculate the sum of every other value in `x` starting from the second value +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, the offset parameter supports indexing semantics based on a starting index. For example, to calculate the sum of every other value in the strided array starting from the second value ```javascript var Float32Array = require( '@stdlib/array/float32' ); -var floor = require( '@stdlib/math/base/special/floor' ); var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); -var N = floor( x.length / 2 ); -var v = dssum.ndarray( N, x, 2, 1 ); +var v = dssum.ndarray( 4, x, 2, 1 ); // returns 5.0 ``` @@ -139,18 +131,11 @@ var v = dssum.ndarray( N, x, 2, 1 ); ```javascript -var randu = require( '@stdlib/random/base/randu' ); -var round = require( '@stdlib/math/base/special/round' ); -var Float32Array = require( '@stdlib/array/float32' ); +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory; +var filledarrayBy = require( '@stdlib/array/filled-by' ); var dssum = require( '@stdlib/blas/ext/base/dssum' ); -var x; -var i; - -x = new Float32Array( 10 ); -for ( i = 0; i < x.length; i++ ) { - x[ i ] = round( randu()*100.0 ); -} +var x = filledarrayBy( 10, 'float32', discreteUniform( 0, 100 ) ); console.log( x ); var v = dssum( x.length, x, 1 ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dssum/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/dssum/benchmark/benchmark.js index 01a51ec1cc98..1f22551b10f7 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dssum/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dssum/benchmark/benchmark.js @@ -21,14 +21,19 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/base/uniform' ).factory; +var filledarrayBy = require( '@stdlib/array/filled-by' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); -var Float32Array = require( '@stdlib/array/float32' ); var pkg = require( './../package.json' ).name; var dssum = require( './../lib/dssum.js' ); +// VARIABLES // + +var rand = uniform( -10.0, 10.0 ); + + // FUNCTIONS // /** @@ -39,13 +44,7 @@ var dssum = require( './../lib/dssum.js' ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; - - x = new Float32Array( len ); - for ( i = 0; i < x.length; i++ ) { - x[ i ] = ( randu()*10.0 ) - 20.0; - } + var x = filledarrayBy( len, 'float32', rand ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/dssum/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/blas/ext/base/dssum/benchmark/benchmark.native.js index 9fe5ab4c911e..a7366cf7acb1 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dssum/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dssum/benchmark/benchmark.native.js @@ -22,10 +22,10 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/base/uniform' ).factory; +var filledarrayBy = require( '@stdlib/array/filled-by' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); -var Float32Array = require( '@stdlib/array/float32' ); var tryRequire = require( '@stdlib/utils/try-require' ); var pkg = require( './../package.json' ).name; @@ -36,6 +36,7 @@ var dssum = tryRequire( resolve( __dirname, './../lib/dssum.native.js' ) ); var opts = { 'skip': ( dssum instanceof Error ) }; +var rand = uniform( -10.0, 10.0 ); // FUNCTIONS // @@ -48,13 +49,7 @@ var opts = { * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; - - x = new Float32Array( len ); - for ( i = 0; i < x.length; i++ ) { - x[ i ] = ( randu()*10.0 ) - 20.0; - } + var x = filledarrayBy( len, 'float32', rand ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/dssum/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/dssum/benchmark/benchmark.ndarray.js index a68c3c6f36a8..c9c692c44908 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dssum/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dssum/benchmark/benchmark.ndarray.js @@ -21,14 +21,19 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/base/uniform' ).factory; +var filledarrayBy = require( '@stdlib/array/filled-by' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); -var Float32Array = require( '@stdlib/array/float32' ); var pkg = require( './../package.json' ).name; var dssum = require( './../lib/ndarray.js' ); +// VARIABLES // + +var rand = uniform( -10.0, 10.0 ); + + // FUNCTIONS // /** @@ -39,13 +44,7 @@ var dssum = require( './../lib/ndarray.js' ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; - - x = new Float32Array( len ); - for ( i = 0; i < x.length; i++ ) { - x[ i ] = ( randu()*10.0 ) - 20.0; - } + var x = filledarrayBy( len, 'float32', rand ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/dssum/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/dssum/benchmark/benchmark.ndarray.native.js index 2985a8c77b45..c7f00340e402 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dssum/benchmark/benchmark.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dssum/benchmark/benchmark.ndarray.native.js @@ -22,10 +22,10 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/base/uniform' ).factory; +var filledarrayBy = require( '@stdlib/array/filled-by' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); -var Float32Array = require( '@stdlib/array/float32' ); var tryRequire = require( '@stdlib/utils/try-require' ); var pkg = require( './../package.json' ).name; @@ -36,6 +36,7 @@ var dssum = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ); var opts = { 'skip': ( dssum instanceof Error ) }; +var rand = uniform( -10.0, 10.0 ); // FUNCTIONS // @@ -48,13 +49,7 @@ var opts = { * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; - - x = new Float32Array( len ); - for ( i = 0; i < x.length; i++ ) { - x[ i ] = ( randu()*10.0 ) - 20.0; - } + var x = filledarrayBy( len, 'float32', rand ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/dssum/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/dssum/docs/repl.txt index 63e7aaf05459..6bb151d10588 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dssum/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/dssum/docs/repl.txt @@ -3,8 +3,8 @@ Computes the sum of single-precision floating-point strided array elements using extended accumulation and returning an extended precision result. - The `N` and `stride` parameters determine which elements in `x` are accessed - at runtime. + The `N` and `stride` parameters determine which elements in the strided + array are accessed at runtime. Indexing is relative to the first index. To introduce an offset, use a typed array view. @@ -36,19 +36,16 @@ // Using `N` and `stride` parameters: > x = new {{alias:@stdlib/array/float32}}( [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0 ] ); - > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); - > var stride = 2; - > {{alias}}( N, x, stride ) + > {{alias}}( 3, x, 2 ) 1.0 // Using view offsets: > var x0 = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); > var x1 = new {{alias:@stdlib/array/float32}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); - > N = {{alias:@stdlib/math/base/special/floor}}( x0.length / 2 ); - > stride = 2; - > {{alias}}( N, x1, stride ) + > {{alias}}( 3, x1, 2 ) -1.0 + {{alias}}.ndarray( N, x, stride, offset ) Computes the sum of single-precision floating-point strided array elements using extended accumulation and alternative indexing semantics and returning @@ -86,8 +83,7 @@ // Using offset parameter: > var x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); - > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); - > {{alias}}.ndarray( N, x, 2, 1 ) + > {{alias}}.ndarray(3, x, 2, 1 ) -1.0 See Also diff --git a/lib/node_modules/@stdlib/blas/ext/base/dssum/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/dssum/examples/index.js index 3f7a4030829f..ef3795ebec46 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dssum/examples/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dssum/examples/index.js @@ -18,18 +18,11 @@ 'use strict'; -var randu = require( '@stdlib/random/base/randu' ); -var round = require( '@stdlib/math/base/special/round' ); -var Float32Array = require( '@stdlib/array/float32' ); +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory; +var filledarrayBy = require( '@stdlib/array/filled-by' ); var dssum = require( './../lib' ); -var x; -var i; - -x = new Float32Array( 10 ); -for ( i = 0; i < x.length; i++ ) { - x[ i ] = round( randu()*100.0 ); -} +var x = filledarrayBy( 10, 'float32', discreteUniform( 0, 100 )); console.log( x ); var v = dssum( x.length, x, 1 ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dssum/include.gypi b/lib/node_modules/@stdlib/blas/ext/base/dssum/include.gypi index 868c5c12e852..26476a8c2655 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dssum/include.gypi +++ b/lib/node_modules/@stdlib/blas/ext/base/dssum/include.gypi @@ -36,7 +36,7 @@ # Source files: 'src_files': [ - '<(src_dir)/addon.cpp', + '<(src_dir)/addon.c', ' +#include + +/** +* Receives JavaScript callback invocation data. +* +* @private +* @param env environment under which the function is invoked +* @param info callback data +* @return Node-API value +*/ +static napi_value addon( napi_env env, napi_callback_info info ) { + STDLIB_NAPI_ARGV( env, info, argv, argc, 3 ); + STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 2 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 1 ); + + napi_value v; + status = napi_create_double( env, stdlib_strided_dssum( N, (float *)X, stride ), &v ); + assert( status == napi_ok ); + return v; +} + +STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) diff --git a/lib/node_modules/@stdlib/blas/ext/base/dssum/src/addon.cpp b/lib/node_modules/@stdlib/blas/ext/base/dssum/src/addon.cpp deleted file mode 100644 index e706c6f86984..000000000000 --- a/lib/node_modules/@stdlib/blas/ext/base/dssum/src/addon.cpp +++ /dev/null @@ -1,117 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/blas/ext/base/dssum.h" -#include -#include -#include -#include -#include - -/** -* Add-on namespace. -*/ -namespace stdlib_blas_ext_base_dssum { - - /** - * Computes the sum of single-precision floating-point strided array elements using extended accumulation and returning an extended precision result. - * - * ## Notes - * - * - When called from JavaScript, the function expects three arguments: - * - * - `N`: number of indexed elements - * - `X`: input array - * - `stride`: stride length - */ - napi_value node_dssum( napi_env env, napi_callback_info info ) { - napi_status status; - - size_t argc = 3; - napi_value argv[ 3 ]; - status = napi_get_cb_info( env, info, &argc, argv, nullptr, nullptr ); - assert( status == napi_ok ); - - if ( argc < 3 ) { - napi_throw_error( env, nullptr, "invalid invocation. Must provide 3 arguments." ); - return nullptr; - } - - napi_valuetype vtype0; - status = napi_typeof( env, argv[ 0 ], &vtype0 ); - assert( status == napi_ok ); - if ( vtype0 != napi_number ) { - napi_throw_type_error( env, nullptr, "invalid argument. First argument must be a number." ); - return nullptr; - } - - bool res; - status = napi_is_typedarray( env, argv[ 1 ], &res ); - assert( status == napi_ok ); - if ( res == false ) { - napi_throw_type_error( env, nullptr, "invalid argument. Second argument must be a Float32Array." ); - return nullptr; - } - - napi_valuetype vtype2; - status = napi_typeof( env, argv[ 2 ], &vtype2 ); - assert( status == napi_ok ); - if ( vtype2 != napi_number ) { - napi_throw_type_error( env, nullptr, "invalid argument. Third argument must be a number." ); - return nullptr; - } - - int64_t N; - status = napi_get_value_int64( env, argv[ 0 ], &N ); - assert( status == napi_ok ); - - int64_t stride; - status = napi_get_value_int64( env, argv[ 2 ], &stride ); - assert( status == napi_ok ); - - napi_typedarray_type vtype1; - size_t xlen; - void *X; - status = napi_get_typedarray_info( env, argv[ 1 ], &vtype1, &xlen, &X, nullptr, nullptr ); - assert( status == napi_ok ); - if ( vtype1 != napi_float32_array ) { - napi_throw_type_error( env, nullptr, "invalid argument. Second argument must be a Float32Array." ); - return nullptr; - } - if ( (N-1)*llabs(stride) >= (int64_t)xlen ) { - napi_throw_range_error( env, nullptr, "invalid argument. Second argument has insufficient elements based on the associated stride and the number of indexed elements." ); - return nullptr; - } - - napi_value v; - status = napi_create_double( env, stdlib_strided_dssum( N, (float *)X, stride ), &v ); - assert( status == napi_ok ); - - return v; - } - - napi_value Init( napi_env env, napi_value exports ) { - napi_status status; - napi_value fcn; - status = napi_create_function( env, "exports", NAPI_AUTO_LENGTH, node_dssum, NULL, &fcn ); - assert( status == napi_ok ); - return fcn; - } - - NAPI_MODULE( NODE_GYP_MODULE_NAME, Init ) -} // end namespace stdlib_blas_ext_base_dssum diff --git a/lib/node_modules/@stdlib/blas/ext/base/dssum/test/test.dssum.js b/lib/node_modules/@stdlib/blas/ext/base/dssum/test/test.dssum.js index babb935a3977..3801b93734ac 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dssum/test/test.dssum.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dssum/test/test.dssum.js @@ -21,7 +21,6 @@ // MODULES // var tape = require( 'tape' ); -var floor = require( '@stdlib/math/base/special/floor' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var Float32Array = require( '@stdlib/array/float32' ); var dssum = require( './../lib/dssum.js' ); @@ -36,7 +35,7 @@ tape( 'main export is a function', function test( t ) { }); tape( 'the function has an arity of 3', function test( t ) { - t.strictEqual( dssum.length, 3, 'has expected arity' ); + t.strictEqual( dssum.length, 3, 'returns expected value' ); t.end(); }); @@ -103,7 +102,6 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first }); tape( 'the function supports a `stride` parameter', function test( t ) { - var N; var x; var v; @@ -118,15 +116,13 @@ tape( 'the function supports a `stride` parameter', function test( t ) { 2.0 ]); - N = floor( x.length / 2 ); - v = dssum( N, x, 2 ); + v = dssum( 4, x, 2 ); t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', function test( t ) { - var N; var x; var v; var i; @@ -142,8 +138,7 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) 2.0 ]); - N = floor( x.length / 2 ); - v = dssum( N, x, -2 ); + v = dssum( 4, x, -2 ); t.strictEqual( v, 5.0, 'returns expected value' ); @@ -172,7 +167,6 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f tape( 'the function supports view offsets', function test( t ) { var x0; var x1; - var N; var v; x0 = new Float32Array([ @@ -188,9 +182,8 @@ tape( 'the function supports view offsets', function test( t ) { ]); x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element - N = floor(x1.length / 2); - v = dssum( N, x1, 2 ); + v = dssum( 4, x1, 2 ); t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dssum/test/test.dssum.native.js b/lib/node_modules/@stdlib/blas/ext/base/dssum/test/test.dssum.native.js index ce37b77801f8..20a983c9a6ac 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dssum/test/test.dssum.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dssum/test/test.dssum.native.js @@ -22,7 +22,6 @@ var resolve = require( 'path' ).resolve; var tape = require( 'tape' ); -var floor = require( '@stdlib/math/base/special/floor' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var Float32Array = require( '@stdlib/array/float32' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -45,7 +44,7 @@ tape( 'main export is a function', opts, function test( t ) { }); tape( 'the function has an arity of 3', opts, function test( t ) { - t.strictEqual( dssum.length, 3, 'has expected arity' ); + t.strictEqual( dssum.length, 3, 'returns expected value' ); t.end(); }); @@ -194,7 +193,6 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first }); tape( 'the function supports a `stride` parameter', opts, function test( t ) { - var N; var x; var v; @@ -209,15 +207,13 @@ tape( 'the function supports a `stride` parameter', opts, function test( t ) { 2.0 ]); - N = floor( x.length / 2 ); - v = dssum( N, x, 2 ); + v = dssum( 4, x, 2 ); t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', opts, function test( t ) { - var N; var x; var v; var i; @@ -233,8 +229,7 @@ tape( 'the function supports a negative `stride` parameter', opts, function test 2.0 ]); - N = floor( x.length / 2 ); - v = dssum( N, x, -2 ); + v = dssum( 4, x, -2 ); t.strictEqual( v, 5.0, 'returns expected value' ); @@ -263,7 +258,6 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f tape( 'the function supports view offsets', opts, function test( t ) { var x0; var x1; - var N; var v; x0 = new Float32Array([ @@ -279,9 +273,8 @@ tape( 'the function supports view offsets', opts, function test( t ) { ]); x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element - N = floor(x1.length / 2); - v = dssum( N, x1, 2 ); + v = dssum( 4, x1, 2 ); t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dssum/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/dssum/test/test.ndarray.js index e19dbafec746..90d5b391eef5 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dssum/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dssum/test/test.ndarray.js @@ -21,7 +21,6 @@ // MODULES // var tape = require( 'tape' ); -var floor = require( '@stdlib/math/base/special/floor' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var Float32Array = require( '@stdlib/array/float32' ); var dssum = require( './../lib/ndarray.js' ); @@ -36,7 +35,7 @@ tape( 'main export is a function', function test( t ) { }); tape( 'the function has an arity of 4', function test( t ) { - t.strictEqual( dssum.length, 4, 'has expected arity' ); + t.strictEqual( dssum.length, 4, 'returns expected value' ); t.end(); }); @@ -103,7 +102,6 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first }); tape( 'the function supports a `stride` parameter', function test( t ) { - var N; var x; var v; @@ -118,15 +116,13 @@ tape( 'the function supports a `stride` parameter', function test( t ) { 2.0 ]); - N = floor( x.length / 2 ); - v = dssum( N, x, 2, 0 ); + v = dssum( 4, x, 2, 0 ); t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', function test( t ) { - var N; var x; var v; var i; @@ -142,8 +138,7 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) 2.0 ]); - N = floor( x.length / 2 ); - v = dssum( N, x, -2, 6 ); + v = dssum( 4, x, -2, 6 ); t.strictEqual( v, 5.0, 'returns expected value' ); @@ -170,7 +165,6 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f }); tape( 'the function supports an `offset` parameter', function test( t ) { - var N; var x; var v; @@ -184,9 +178,8 @@ tape( 'the function supports an `offset` parameter', function test( t ) { 3.0, 4.0 // 3 ]); - N = floor( x.length / 2 ); - v = dssum( N, x, 2, 1 ); + v = dssum( 4, x, 2, 1 ); t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dssum/test/test.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/dssum/test/test.ndarray.native.js index 9f9ce44b57de..a6ad5ae5da3e 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dssum/test/test.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dssum/test/test.ndarray.native.js @@ -22,7 +22,6 @@ var resolve = require( 'path' ).resolve; var tape = require( 'tape' ); -var floor = require( '@stdlib/math/base/special/floor' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var Float32Array = require( '@stdlib/array/float32' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -45,7 +44,7 @@ tape( 'main export is a function', opts, function test( t ) { }); tape( 'the function has an arity of 4', opts, function test( t ) { - t.strictEqual( dssum.length, 4, 'has expected arity' ); + t.strictEqual( dssum.length, 4, 'returns expected value' ); t.end(); }); @@ -112,7 +111,6 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first }); tape( 'the function supports a `stride` parameter', opts, function test( t ) { - var N; var x; var v; @@ -127,15 +125,13 @@ tape( 'the function supports a `stride` parameter', opts, function test( t ) { 2.0 ]); - N = floor( x.length / 2 ); - v = dssum( N, x, 2, 0 ); + v = dssum( 4, x, 2, 0 ); t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', opts, function test( t ) { - var N; var x; var v; var i; @@ -151,8 +147,7 @@ tape( 'the function supports a negative `stride` parameter', opts, function test 2.0 ]); - N = floor( x.length / 2 ); - v = dssum( N, x, -2, 6 ); + v = dssum( 4, x, -2, 6 ); t.strictEqual( v, 5.0, 'returns expected value' ); @@ -179,7 +174,6 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f }); tape( 'the function supports an `offset` parameter', opts, function test( t ) { - var N; var x; var v; @@ -193,9 +187,8 @@ tape( 'the function supports an `offset` parameter', opts, function test( t ) { 3.0, 4.0 // 3 ]); - N = floor( x.length / 2 ); - v = dssum( N, x, 2, 1 ); + v = dssum( 4, x, 2, 1 ); t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/srev/manifest.json b/lib/node_modules/@stdlib/blas/ext/base/srev/manifest.json index 44daf08b843f..8d202bab4299 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/srev/manifest.json +++ b/lib/node_modules/@stdlib/blas/ext/base/srev/manifest.json @@ -1,5 +1,7 @@ { - "options": {}, + "options": { + "task": "build" + }, "fields": [ { "field": "src", @@ -24,6 +26,7 @@ ], "confs": [ { + "task": "build", "src": [ "./src/srev.c" ], @@ -40,6 +43,34 @@ "@stdlib/napi/argv-int64", "@stdlib/napi/argv-strided-float32array" ] + }, + { + "task": "benchmark", + "src": [ + "./src/srev.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lm" + ], + "libpath": [], + "dependencies": [] + }, + { + "task": "examples", + "src": [ + "./src/srev.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lm" + ], + "libpath": [], + "dependencies": [] } ] } diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssumkbn/manifest.json b/lib/node_modules/@stdlib/blas/ext/base/ssumkbn/manifest.json index 80ed912160b1..64bee9f734e5 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssumkbn/manifest.json +++ b/lib/node_modules/@stdlib/blas/ext/base/ssumkbn/manifest.json @@ -1,5 +1,7 @@ { - "options": {}, + "options": { + "task": "build" + }, "fields": [ { "field": "src", @@ -24,6 +26,7 @@ ], "confs": [ { + "task": "build", "src": [ "./src/ssumkbn.c" ], @@ -40,6 +43,34 @@ "@stdlib/napi/argv-int64", "@stdlib/napi/argv-strided-float32array" ] + }, + { + "task": "benchmark", + "src": [ + "./src/ssumkbn.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lm" + ], + "libpath": [], + "dependencies": [] + }, + { + "task": "examples", + "src": [ + "./src/ssumkbn.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lm" + ], + "libpath": [], + "dependencies": [] } ] } diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssumors/manifest.json b/lib/node_modules/@stdlib/blas/ext/base/ssumors/manifest.json index 3b8d23a2712c..bac5eaeb4351 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssumors/manifest.json +++ b/lib/node_modules/@stdlib/blas/ext/base/ssumors/manifest.json @@ -1,5 +1,7 @@ { - "options": {}, + "options": { + "task": "build" + }, "fields": [ { "field": "src", @@ -24,6 +26,7 @@ ], "confs": [ { + "task": "build", "src": [ "./src/ssumors.c" ], @@ -35,11 +38,39 @@ ], "libpath": [], "dependencies": [ - "stdlib/napi/export.h", - "stdlib/napi/argv.h", - "stdlib/napi/argv_int64.h", - "stdlib/napi/argv_strided_float32array.h" + "@stdlib/napi/export", + "@stdlib/napi/argv", + "@stdlib/napi/argv-int64", + "@stdlib/napi/argv-strided-float32array" ] + }, + { + "task": "benchmark", + "src": [ + "./src/ssumors.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lm" + ], + "libpath": [], + "dependencies": [] + }, + { + "task": "examples", + "src": [ + "./src/ssumors.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lm" + ], + "libpath": [], + "dependencies": [] } ] } diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssumors/src/addon.c b/lib/node_modules/@stdlib/blas/ext/base/ssumors/src/addon.c index 5555e3ea73e1..a5ada7b08c1e 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssumors/src/addon.c +++ b/lib/node_modules/@stdlib/blas/ext/base/ssumors/src/addon.c @@ -16,7 +16,7 @@ * limitations under the License. */ -#include "stdlib/blas/base/ssumors.h" +#include "stdlib/blas/ext/base/ssumors.h" #include "stdlib/napi/export.h" #include "stdlib/napi/argv.h" #include "stdlib/napi/argv_int64.h" diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssumpw/manifest.json b/lib/node_modules/@stdlib/blas/ext/base/ssumpw/manifest.json index 0291c43d5b4e..92cb2fbd64fb 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssumpw/manifest.json +++ b/lib/node_modules/@stdlib/blas/ext/base/ssumpw/manifest.json @@ -1,45 +1,76 @@ { - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/ssumpw.c" - ], - "include": [ - "./include" - ], - "libraries": [ - "-lm" - ], - "libpath": [], - "dependencies": [ - "stdlib/napi/export.h", - "stdlib/napi/argv.h", - "stdlib/napi/argv_int64.h", - "stdlib/napi/argv_strided_float32array.h" - ] - } - ] + "options": { + "task": "build" + }, + "fields": [ + { + "field": "src", + "resolve": true, + "relative": true + }, + { + "field": "include", + "resolve": true, + "relative": true + }, + { + "field": "libraries", + "resolve": false, + "relative": false + }, + { + "field": "libpath", + "resolve": true, + "relative": false + } + ], + "confs": [ + { + "task": "build", + "src": [ + "./src/ssumpw.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lm" + ], + "libpath": [], + "dependencies": [ + "@stdlib/napi/export", + "@stdlib/napi/argv", + "@stdlib/napi/argv-int64", + "@stdlib/napi/argv-strided-float32array" + ] + }, + { + "task": "benchmark", + "src": [ + "./src/ssumpw.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lm" + ], + "libpath": [], + "dependencies": [] + }, + { + "task": "examples", + "src": [ + "./src/ssumpw.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lm" + ], + "libpath": [], + "dependencies": [] + } + ] } diff --git a/lib/node_modules/@stdlib/iter/do-until-each/README.md b/lib/node_modules/@stdlib/iter/do-until-each/README.md new file mode 100644 index 000000000000..fad705536b94 --- /dev/null +++ b/lib/node_modules/@stdlib/iter/do-until-each/README.md @@ -0,0 +1,236 @@ + + +# iterDoUntilEach + +> Create an iterator which, while a test condition is false, invokes a function for each iterated value before returning the iterated value. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var iterDoUntilEach = require( '@stdlib/iter/do-until-each' ); +``` + +#### iterDoUntilEach( iterator, predicate, fcn\[, thisArg] ) + +Returns an iterator which invokes a function for each iterated value **before** returning the iterated value until either a `predicate` function returns `true` or the iterator has iterated over all values. Note that the condition is evaluated **after** executing `fcn`; thus, `fcn` **always** executes at least once. + +```javascript +var array2iterator = require( '@stdlib/array/to-iterator' ); + +function predicate( v ) { + return v > 2; +} + +function assert( v ) { + if ( v !== v ) { + throw new Error( 'should not be NaN' ); + } +} + +var it = iterDoUntilEach( array2iterator( [ 1, 2, 3, 4 ] ), predicate, assert ); +// returns {} + +var r = it.next().value; +// returns 1 + +r = it.next().value; +// returns 2 + +r = it.next().value; +// undefined + +// ... +``` + +The returned iterator protocol-compliant object has the following properties: + +- **next**: function which returns an iterator protocol-compliant object containing the next iterated value (if one exists) assigned to a `value` property and a `done` property having a boolean value indicating whether the iterator is finished. +- **return**: function which closes an iterator and returns a single (optional) argument in an iterator protocol-compliant object. + +Both the `predicate` function and the function to invoke for each iterated value are provided two arguments: + +- **value**: iterated value +- **index**: iteration index (zero-based) + +```javascript +var array2iterator = require( '@stdlib/array/to-iterator' ); + +function predicate( v ) { + return v > 2; +} + +function assert( v, i ) { + if ( i > 2 ) { + throw new Error( 'unexpected error' ); + } +} + +var it = iterDoUntilEach( array2iterator( [ 1, 2, 3, 4 ] ), predicate, assert ); +// returns + +var r = it.next().value; +// returns 1 + +r = it.next().value; +// returns 2 + +r = it.next().value; +// undefined + +// ... +``` + +To set the execution context for `fcn`, provide a `thisArg`. + + + +```javascript +var array2iterator = require( '@stdlib/array/to-iterator' ); + +function assert( v ) { + this.count += 1; + if ( v !== v ) { + throw new Error( 'should not be NaN' ); + } +} + +function predicate( v ) { + return v > 2; +} + +var c = { + 'count': 0 +}; + +var it = iterDoUntilEach( array2iterator( [ 1, 2, 3 ] ), predicate, assert, c ); +// returns + +var r = it.next().value; +// returns 1 + +r = it.next().value; +// returns 2 + +r = it.next().value; +// returns undefined + +var count = c.count; +// returns 3 +``` + + + + + + + +
+ +## Notes + +- If an environment supports `Symbol.iterator` **and** a provided iterator is iterable, the returned iterator is iterable. + +
+ + + + + +
+ +## Examples + + + +```javascript +var randu = require( '@stdlib/random/iter/randu' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var iterDoUntilEach = require( '@stdlib/iter/do-until-each' ); + +function assert( v ) { + if ( isnan( v ) ) { + throw new Error( 'should not be NaN' ); + } +} + +function predicate( v ) { + return v <= 0.75; +} + +// Create a seeded iterator for generating pseudorandom numbers: +var rand = randu({ + 'seed': 1234, + 'iter': 10 +}); + +// Create an iterator which validates generated numbers: +var it = iterDoUntilEach( rand, predicate, assert ); + +// Perform manual iteration... +var r; +while ( true ) { + r = it.next(); + if ( r.done ) { + break; + } + console.log( r.value ); +} +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/iter/do-until-each/benchmark/benchmark.js b/lib/node_modules/@stdlib/iter/do-until-each/benchmark/benchmark.js new file mode 100644 index 000000000000..4cd9c9827fa6 --- /dev/null +++ b/lib/node_modules/@stdlib/iter/do-until-each/benchmark/benchmark.js @@ -0,0 +1,97 @@ +/** +* @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' ); +var randu = require( '@stdlib/random/iter/randu' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var isIteratorLike = require( '@stdlib/assert/is-iterator-like' ); +var pkg = require( './../package.json' ).name; +var iterator = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var rand; + var iter; + var i; + + rand = randu(); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + iter = iterator( rand, predicate, fcn ); + if ( typeof iter !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isIteratorLike( iter ) ) { + b.fail( 'should return an iterator protocol-compliant object' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function fcn( v ) { + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + } + + function predicate( v ) { + return ( v < 0.5 ); + } +}); + +bench( pkg+'::iteration', function benchmark( b ) { + var rand; + var iter; + var z; + var i; + + rand = randu(); + iter = iterator( rand, predicate, fcn ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + z = iter.next().value; + if ( isnan( z ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( z ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function fcn( v ) { + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + } + + function predicate( v ) { + return ( v < 0.5 ); + } +}); diff --git a/lib/node_modules/@stdlib/iter/do-until-each/docs/repl.txt b/lib/node_modules/@stdlib/iter/do-until-each/docs/repl.txt new file mode 100644 index 000000000000..74dcde16eeb2 --- /dev/null +++ b/lib/node_modules/@stdlib/iter/do-until-each/docs/repl.txt @@ -0,0 +1,57 @@ + +{{alias}}( iterator, predicate, fcn[, thisArg] ) + Returns an iterator which invokes a function for each iterated value before + returning the iterated value until either a predicate function returns true + or the iterator has iterated over all values. + + The condition is evaluated *after* executing the provided function; thus, + `fcn` *always* executes at least once. + + When invoked, both input functions are provided two arguments: + + - value: iterated value + - index: iteration index (zero-based) + + If an environment supports Symbol.iterator, the returned iterator is + iterable. + + Parameters + ---------- + iterator: Object + Input iterator. + + predicate: Function + Function which indicates whether to continue iterating. + + fcn: Function + Function to invoke for each iterated value. + + thisArg: any (optional) + Execution context. + + Returns + ------- + iterator: Object + Iterator. + + iterator.next(): Function + Returns an iterator protocol-compliant object containing the next + iterated value (if one exists) and a boolean flag indicating whether the + iterator is finished. + + iterator.return( [value] ): Function + Finishes an iterator and returns a provided value. + + Examples + -------- + > function predicate( v ) { return v !== v }; + > function f( v ) { if ( v !== v ) { throw new Error( 'beep' ); } }; + > var it = {{alias}}( {{alias:@stdlib/random/iter/randu}}(), predicate, f ); + > var r = it.next().value + + > r = it.next().value + + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/iter/do-until-each/docs/types/index.d.ts b/lib/node_modules/@stdlib/iter/do-until-each/docs/types/index.d.ts new file mode 100644 index 000000000000..778c0121373b --- /dev/null +++ b/lib/node_modules/@stdlib/iter/do-until-each/docs/types/index.d.ts @@ -0,0 +1,144 @@ +/* +* @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 + +/// + +import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; + +// Define a union type representing both iterable and non-iterable iterators: +type Iterator = Iter | IterableIterator; + +/** +* Callback function invoked for each iterated value. +* +* @returns callback result +*/ +type nullaryCallback = () => unknown; + +/** +* Callback function invoked for each iterated value. +* +* @param value - iterated value +* @returns callback result +*/ +type unaryCallback = ( value: unknown ) => unknown; + +/** +* Callback function invoked for each iterated value. +* +* @param value - iterated value +* @param i - iteration index +* @returns callback result +*/ +type binaryCallback = ( value: unknown, i: number ) => unknown; + +/** +* Callback function invoked for each iterated value. +* +* @param value - iterated value +* @param i - iteration index +* @returns callback result +*/ +type Callback = nullaryCallback | unaryCallback | binaryCallback; + +/** +* Predicate function invoked for each iterated value. +* +* @returns a boolean indicating whether to continue iterating or not +*/ +type nullaryPredicate = () => boolean; + +/** +* Predicate function invoked for each iterated value. +* +* @param value - iterated value +* @returns a boolean indicating whether to continue iterating or not +*/ +type unaryPredicate = ( value: unknown ) => boolean; + +/** +* Predicate function invoked for each iterated value. +* +* @param value - iterated value +* @param i - iteration index +* @returns a boolean indicating whether to continue iterating or not +*/ +type binaryPredicate = ( value: unknown, i: number ) => boolean; + +/** +* Predicate function invoked for each iterated value. +* +* @param value - iterated value +* @param i - iteration index +* @returns a boolean indicating whether to continue iterating or not +*/ +type Predicate = nullaryPredicate | unaryPredicate | binaryPredicate; + +/** +* Returns an iterator which invokes a function for each iterated value **before** returning the iterated value until either a predicate function returns `true` or the iterator has iterated over all values. +* +* ## Notes +* +* - When invoked, both the `predicate` and callback functions are provided two arguments: +* +* - **value**: iterated value +* - **index**: iteration index (zero-based) +* +* - If an environment supports `Symbol.iterator` **and** a provided iterator is iterable, the returned iterator is iterable. +* +* @param iterator - input iterator +* @param predicate - function which indicates whether to continue iterating +* @param fcn - callback function to invoke for each iterated value +* @param thisArg - execution context +* @returns iterator +* +* @example +* var array2iterator = require( '@stdlib/array/to-iterator' ); +* +* function predicate( v ) { +* return v > 2; +* } +* +* function assert( v, i ) { +* if ( i > 1 ) { +* throw new Error( 'unexpected error' ); +* } +* } +* +* var it = iterDoUntilEach( array2iterator( [ 1, 2, 3, 4 ] ), predicate, assert ); +* // returns {} +* +* var r = it.next().value; +* // returns 1 +* +* r = it.next().value; +* // returns 2 +* +* r = it.next().value; +* // undefined +* +* // ... +*/ +declare function iterDoUntilEach( iterator: Iterator, predicate: Predicate, fcn: Callback, thisArg?: unknown ): Iterator; + + +// EXPORTS // + +export = iterDoUntilEach; diff --git a/lib/node_modules/@stdlib/iter/do-until-each/docs/types/test.ts b/lib/node_modules/@stdlib/iter/do-until-each/docs/types/test.ts new file mode 100644 index 000000000000..973607f58318 --- /dev/null +++ b/lib/node_modules/@stdlib/iter/do-until-each/docs/types/test.ts @@ -0,0 +1,120 @@ +/* +* @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 iterDoUntilEach = require( './index' ); + +/** +* Returns an iterator protocol-compliant object. +* +* @returns iterator protocol-compliant object +*/ +function iterator(): unknown { + /** + * Implements the iterator protocol `next` method. + * + * @returns iterator protocol-compliant object + */ + function next(): unknown { + return { + 'value': true, + 'done': false + }; + } + + return { + 'next': next + }; +} + +/** +* Conditional predicate function. +* +* @param v - iterated value +* @param i - iteration index +* @returns a boolean indicating whether to continue iterating or not +*/ +function predicate( v: unknown, i: number ): boolean { + return v === v && i === i; +} + +/** +* Callback function. +* +* @param v - iterated value +* @param i - iteration index +* @returns callback result +*/ +function fcn( v: unknown, i: number ): void { + if ( v !== v || i !== i ) { + throw new Error( 'something went wrong' ); + } +} + + +// TESTS // + +// The function returns an iterator... +{ + iterDoUntilEach( iterator(), predicate, fcn ); // $ExpectType Iterator + iterDoUntilEach( iterator(), predicate, fcn, {} ); // $ExpectType Iterator + iterDoUntilEach( iterator(), predicate, fcn, null ); // $ExpectType Iterator +} + +// The compiler throws an error if the function is provided a first argument which is not an iterator protocol-compliant object... +{ + iterDoUntilEach( '5', predicate, fcn ); // $ExpectError + iterDoUntilEach( 5, predicate, fcn ); // $ExpectError + iterDoUntilEach( true, predicate, fcn ); // $ExpectError + iterDoUntilEach( false, predicate, fcn ); // $ExpectError + iterDoUntilEach( null, predicate, fcn ); // $ExpectError + iterDoUntilEach( undefined, predicate, fcn ); // $ExpectError + iterDoUntilEach( [], predicate, fcn ); // $ExpectError + iterDoUntilEach( {}, predicate, fcn ); // $ExpectError + iterDoUntilEach( ( x: number ): number => x, predicate, fcn ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a valid predicate function... +{ + iterDoUntilEach( iterator(), '5', fcn ); // $ExpectError + iterDoUntilEach( iterator(), 5, fcn ); // $ExpectError + iterDoUntilEach( iterator(), true, fcn ); // $ExpectError + iterDoUntilEach( iterator(), false, fcn ); // $ExpectError + iterDoUntilEach( iterator(), null, fcn ); // $ExpectError + iterDoUntilEach( iterator(), undefined, fcn ); // $ExpectError + iterDoUntilEach( iterator(), [], fcn ); // $ExpectError + iterDoUntilEach( iterator(), {}, fcn ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a valid callback function... +{ + iterDoUntilEach( iterator(), predicate, '5' ); // $ExpectError + iterDoUntilEach( iterator(), predicate, 5 ); // $ExpectError + iterDoUntilEach( iterator(), predicate, true ); // $ExpectError + iterDoUntilEach( iterator(), predicate, false ); // $ExpectError + iterDoUntilEach( iterator(), predicate, null ); // $ExpectError + iterDoUntilEach( iterator(), predicate, undefined ); // $ExpectError + iterDoUntilEach( iterator(), predicate, [] ); // $ExpectError + iterDoUntilEach( iterator(), predicate, {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided insufficient arguments... +{ + iterDoUntilEach(); // $ExpectError + iterDoUntilEach( iterator() ); // $ExpectError + iterDoUntilEach( iterator(), predicate ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/iter/do-until-each/examples/index.js b/lib/node_modules/@stdlib/iter/do-until-each/examples/index.js new file mode 100644 index 000000000000..5c9ab0b2a6e2 --- /dev/null +++ b/lib/node_modules/@stdlib/iter/do-until-each/examples/index.js @@ -0,0 +1,52 @@ +/** +* @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 randu = require( '@stdlib/random/iter/randu' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var iterDoUntilEach = require( './../lib' ); + +function assert( v ) { + if ( isnan( v ) ) { + throw new Error( 'should not be NaN' ); + } +} + +function predicate( v ) { + return ( v <= 0.75 ); +} + +// Create a seeded iterator for generating pseudorandom numbers: +var rand = randu({ + 'seed': 1234, + 'iter': 10 +}); + +// Create an iterator which validates generated numbers: +var it = iterDoUntilEach( rand, predicate, assert ); + +// Perform manual iteration... +var r; +while ( true ) { + r = it.next(); + if ( r.done ) { + break; + } + console.log( r.value ); +} diff --git a/lib/node_modules/@stdlib/iter/do-until-each/lib/index.js b/lib/node_modules/@stdlib/iter/do-until-each/lib/index.js new file mode 100644 index 000000000000..72e297ef4c75 --- /dev/null +++ b/lib/node_modules/@stdlib/iter/do-until-each/lib/index.js @@ -0,0 +1,62 @@ +/** +* @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'; + +/** +* Create an iterator which, while a test condition is false, invokes a function for each iterated value before returning the iterated value. +* +* @module @stdlib/iter/do-until-each +* +* @example +* var array2iterator = require( '@stdlib/array/to-iterator' ); +* var iterDoUntilEach = require( '@stdlib/iter/do-until-each' ); +* +* function predicate( v ) { +* return v > 2; +* } +* +* function assert( v ) { +* if ( v !== v ) { +* throw new Error( 'should not be NaN' ); +* } +* } +* +* var it = iterDoUntilEach( array2iterator( [ 1, 2, 3, 4 ] ), predicate, assert ); +* // returns {} +* +* var r = it.next().value; +* // returns 1 +* +* r = it.next().value; +* // returns 2 +* +* r = it.next().value; +* // undefined +* +* // ... +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/iter/do-until-each/lib/main.js b/lib/node_modules/@stdlib/iter/do-until-each/lib/main.js new file mode 100644 index 000000000000..ba7b86cedfb0 --- /dev/null +++ b/lib/node_modules/@stdlib/iter/do-until-each/lib/main.js @@ -0,0 +1,165 @@ +/** +* @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 setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var isIteratorLike = require( '@stdlib/assert/is-iterator-like' ); +var iteratorSymbol = require( '@stdlib/symbol/iterator' ); +var format = require( '@stdlib/string/format' ); + + +// MAIN // + +/** +* Returns an iterator which invokes a function for each iterated value before returning the iterated value until either a predicate function returns `true` or the iterator has iterated over all values. +* +* @param {Iterator} iterator - input iterator +* @param {Function} predicate - function which indicates whether to continue iterating +* @param {Function} fcn - function to invoke +* @param {*} [thisArg] - execution context +* @throws {TypeError} first argument must be an iterator protocol-compliant object +* @throws {TypeError} second argument must be a function +* @throws {TypeError} third argument must be a function +* @returns {Iterator} iterator +* +* @example +* var array2iterator = require( '@stdlib/array/to-iterator' ); +* var iterDoUntilEach = require( '@stdlib/iter/do-until-each' ); +* +* function predicate( v ) { +* return v > 2; +* } +* +* function assert( v ) { +* if ( v !== v ) { +* throw new Error( 'should not be NaN' ); +* } +* } +* +* var it = iterDoUntilEach( array2iterator( [ 1, 2, 3, 4 ] ), predicate, assert ); +* // returns {} +* +* var r = it.next().value; +* // returns 1 +* +* r = it.next().value; +* // returns 2 +* +* r = it.next().value; +* // undefined +* +* // ... +*/ +function iterDoUntilEach( iterator, predicate, fcn, thisArg ) { + var iter; + var FLG; + var i; + if ( !isIteratorLike( iterator ) ) { + throw new TypeError( format( 'invalid argument. First argument must be an iterator protocol-compliant object. Value: `%s`.', iterator ) ); + } + if ( !isFunction( predicate ) ) { + throw new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', predicate ) ); + } + if ( !isFunction( fcn ) ) { + throw new TypeError( format( 'invalid argument. Third argument must be a function. Value: `%s`.', fcn ) ); + } + i = -1; + + // Create an iterator protocol-compliant object: + iter = {}; + setReadOnly( iter, 'next', next ); + setReadOnly( iter, 'return', end ); + + // If an environment supports `Symbol.iterator`, make the iterator iterable: + if ( iteratorSymbol && isFunction( iterator[ iteratorSymbol ] ) ) { + setReadOnly( iter, iteratorSymbol, factory ); + } + return iter; + + /** + * Returns an iterator protocol-compliant object containing the next iterated value. + * + * @private + * @returns {Object} iterator protocol-compliant object + */ + function next() { + var v; + i += 1; + if ( FLG ) { + return { + 'done': true + }; + } + v = iterator.next(); + if ( v.done ) { + FLG = true; + return v; + } + v = v.value; + fcn.call( thisArg, v, i ); + if ( predicate( v, i ) === true ) { + FLG = true; + return { + 'done': true + }; + } + return { + 'value': v, + 'done': false + }; + } + + /** + * Finishes an iterator. + * + * @private + * @param {*} [value] - value to return + * @returns {Object} iterator protocol-compliant object + */ + function end( value ) { + FLG = true; + if ( arguments.length ) { + return { + 'value': value, + 'done': true + }; + } + return { + 'done': true + }; + } + + /** + * Returns a new iterator. + * + * @private + * @returns {Iterator} iterator + */ + function factory() { + return iterDoUntilEach( iterator[ iteratorSymbol ](), predicate, fcn, thisArg ); // eslint-disable-line max-len + } +} + + +// EXPORTS // + +module.exports = iterDoUntilEach; diff --git a/lib/node_modules/@stdlib/iter/do-until-each/package.json b/lib/node_modules/@stdlib/iter/do-until-each/package.json new file mode 100644 index 000000000000..85db59837c85 --- /dev/null +++ b/lib/node_modules/@stdlib/iter/do-until-each/package.json @@ -0,0 +1,67 @@ +{ + "name": "@stdlib/iter/until-each", + "version": "0.0.0", + "description": "Create an iterator which, while a test condition is false, invokes a function for each iterated value before returning the iterated value.", + "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": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdutils", + "stdutil", + "utilities", + "utility", + "utils", + "util", + "do-until-each", + "dountileach", + "until", + "each", + "iterator", + "iterable", + "iterate" + ] +} diff --git a/lib/node_modules/@stdlib/iter/do-until-each/test/test.js b/lib/node_modules/@stdlib/iter/do-until-each/test/test.js new file mode 100644 index 000000000000..e9d25466688c --- /dev/null +++ b/lib/node_modules/@stdlib/iter/do-until-each/test/test.js @@ -0,0 +1,368 @@ +/** +* @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 proxyquire = require( 'proxyquire' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var randu = require( '@stdlib/random/iter/randu' ); +var iteratorSymbol = require( '@stdlib/symbol/iterator' ); +var array2iterator = require( '@stdlib/array/to-iterator' ); +var noop = require( '@stdlib/utils/noop' ); +var iterDoUntilEach = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof iterDoUntilEach, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if provided an iterator argument which is not an iterator protocol-compliant object', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + iterDoUntilEach( value, noop, noop ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is not a function', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + iterDoUntilEach( randu(), value, noop ); + }; + } +}); + +tape( 'the function throws an error if provided a third argument which is not a function', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + iterDoUntilEach( randu(), noop, value ); + }; + } +}); + +tape( 'the function returns an iterator protocol-compliant object', function test( t ) { + var count; + var it; + var r; + var i; + + it = iterDoUntilEach( randu(), predicate, assert ); + t.equal( it.next.length, 0, 'has zero arity' ); + + count = -1; + i = 0; + do { + r = it.next(); + if ( typeof r.value !== 'undefined' ) { + t.equal( typeof r.value, 'number', 'returns a number' ); + } + t.equal( typeof r.done, 'boolean', 'returns a boolean' ); + if ( r.done ) { + count += 1; + } + i += 1; + } while ( r.done === false ); + t.equal( count, i, 'returns expected value' ); + t.end(); + + function assert( v, i ) { + count += 1; + t.equal( isnan( v ), false, 'is not NaN' ); + t.equal( isnan( i ), false, 'is not NaN' ); + } + + function predicate( v, i ) { + return ( v <= 0.5 && i >= 0 ); + } +}); + +tape( 'the function returns an iterator protocol-compliant object which invokes a function for each iterated value before returning the iterated value until either a `predicate` function returns `true` or the iterator has iterated over all values.', function test( t ) { + var expected; + var opts; + var rand; + var it; + var r; + var i; + + opts = { + 'iter': 10 + }; + rand = randu( opts ); + it = iterDoUntilEach( rand, predicate, assert ); + t.equal( it.next.length, 0, 'has zero arity' ); + + expected = []; + i = 0; + do { + r = it.next(); + if ( typeof r.value !== 'undefined' ) { + t.equal( i, expected[ i ][ 1 ], 'provides expected value' ); + t.equal( r.value, expected[ i ][ 0 ], 'returns expected value' ); + } + t.equal( typeof r.done, 'boolean', 'returns a boolean' ); + i += 1; + } while ( r.done === false ); + t.equal( expected.length, i, 'has expected length' ); + + r = it.next(); + t.equal( r.value, void 0, 'returns expected value' ); + t.equal( r.done, true, 'returns expected value' ); + + t.end(); + + function assert( v, i ) { + expected.push( [ v, i ] ); + t.equal( isnan( v ), false, 'is not NaN' ); + t.equal( isnan( i ), false, 'is not NaN' ); + } + + function predicate( v, i ) { + return ( v <= 0.75 && i >= 0 ); + } +}); + +tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { + var it; + var r; + + it = iterDoUntilEach( array2iterator( [ 1, 2, 3, 4 ] ), predicate, assert ); + + r = it.next(); + t.equal( typeof r.value, 'number', 'returns a number' ); + t.equal( r.done, false, 'returns expected value' ); + + r = it.next(); + t.equal( typeof r.value, 'number', 'returns a number' ); + t.equal( r.done, false, 'returns expected value' ); + + r = it.return(); + t.equal( r.value, void 0, 'returns expected value' ); + t.equal( r.done, true, 'returns expected value' ); + + r = it.next(); + t.equal( r.value, void 0, 'returns expected value' ); + t.equal( r.done, true, 'returns expected value' ); + + t.end(); + + function assert( v, i ) { + t.equal( isnan( v ), false, 'is not NaN' ); + t.equal( isnan( i ), false, 'is not NaN' ); + } + + function predicate( v, i ) { + return ( v > 4 && i >= 0 ); + } +}); + +tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { + var it; + var r; + + it = iterDoUntilEach( array2iterator( [ 1, 2, 3, 4 ] ), predicate, assert ); + + r = it.next(); + t.equal( typeof r.value, 'number', 'returns a number' ); + t.equal( r.done, false, 'returns expected value' ); + + r = it.next(); + t.equal( typeof r.value, 'number', 'returns a number' ); + t.equal( r.done, false, 'returns expected value' ); + + r = it.return( 'finished' ); + t.equal( r.value, 'finished', 'returns expected value' ); + t.equal( r.done, true, 'returns expected value' ); + + r = it.next(); + t.equal( r.value, void 0, 'returns expected value' ); + t.equal( r.done, true, 'returns expected value' ); + + t.end(); + + function assert( v, i ) { + t.equal( isnan( v ), false, 'is not NaN' ); + t.equal( isnan( i ), false, 'is not NaN' ); + } + + function predicate( v, i ) { + return ( v > 4 && i >= 0 ); + } +}); + +tape( 'if an environment supports `Symbol.iterator` and the provided iterator is iterable, the returned iterator is iterable', function test( t ) { + var iterDoUntilEach; + var opts; + var rand; + var it1; + var it2; + var i; + + iterDoUntilEach = proxyquire( './../lib/main.js', { + '@stdlib/symbol/iterator': '__ITERATOR_SYMBOL__' + }); + + opts = { + 'seed': 12345 + }; + rand = randu( opts ); + rand[ '__ITERATOR_SYMBOL__' ] = factory; + + it1 = iterDoUntilEach( rand, predicate, assert ); + t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); + t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); + + it2 = it1[ '__ITERATOR_SYMBOL__' ](); + t.equal( typeof it2, 'object', 'returns an object' ); + t.equal( typeof it2.next, 'function', 'has method' ); + t.equal( typeof it2.return, 'function', 'has method' ); + + for ( i = 0; i < 100; i++ ) { + t.equal( it2.next().value, it1.next().value, 'returns expected value' ); + } + t.end(); + + function factory() { + return randu( opts ); + } + + function assert( v, i ) { + t.equal( isnan( v ), false, 'is not NaN' ); + t.equal( isnan( i ), false, 'is not NaN' ); + } + + function predicate( v, i ) { + return ( !( isnan( v ) || isnan( i ) ) ); + } +}); + +tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { + var iterDoUntilEach; + var it; + + iterDoUntilEach = proxyquire( './../lib/main.js', { + '@stdlib/symbol/iterator': false + }); + + it = iterDoUntilEach( randu(), predicate, assert ); + t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); + + t.end(); + + function assert( v, i ) { + t.equal( isnan( v ), false, 'is not NaN' ); + t.equal( isnan( i ), false, 'is not NaN' ); + } + + function predicate( v, i ) { + return ( !( isnan( v ) || isnan( i ) ) ); + } +}); + +tape( 'if a provided iterator is not iterable, the returned iterator is not iterable', function test( t ) { + var iterDoUntilEach; + var rand; + var it; + + iterDoUntilEach = proxyquire( './../lib/main.js', { + '@stdlib/symbol/iterator': '__ITERATOR_SYMBOL__' + }); + + rand = randu(); + rand[ '__ITERATOR_SYMBOL__' ] = null; + + it = iterDoUntilEach( rand, predicate, assert ); + t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); + t.end(); + + function assert( v, i ) { + t.equal( isnan( v ), false, 'is not NaN' ); + t.equal( isnan( i ), false, 'is not NaN' ); + } + + function predicate( v, i ) { + return ( !( isnan( v ) || isnan( i ) ) ); + } +}); diff --git a/lib/node_modules/@stdlib/math/base/assert/int32-is-odd/README.md b/lib/node_modules/@stdlib/math/base/assert/int32-is-odd/README.md index 0e0a7140be7a..2f4f79387df4 100644 --- a/lib/node_modules/@stdlib/math/base/assert/int32-is-odd/README.md +++ b/lib/node_modules/@stdlib/math/base/assert/int32-is-odd/README.md @@ -81,6 +81,98 @@ for ( i = 0; i < 100; i++ ) { + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/math/base/assert/int32_is_odd.h" +``` + +#### stdlib_base_int32_is_odd( x ) + +Tests if a 32-bit integer is odd. + +```c +#include + +bool out = stdlib_base_int32_is_odd( 5 ); +// returns true + +out = stdlib_base_int32_is_odd( -2 ); +// returns false +``` + +The function accepts the following arguments: + +- **x**: `[in] int32_t` input value. + +```c +bool stdlib_base_int32_is_odd( const int32_t x ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/math/base/assert/int32_is_odd.h" +#include +#include +#include + +int main( void ) { + const int32_t x[] = { 5, -5, 3, -3, 0, 2 }; + + bool b; + int i; + for ( i = 0; i < 5; i++ ) { + b = stdlib_base_int32_is_odd( x[ i ] ); + printf( "Value: %d. int32 Is Odd? %s.\n", x[ i ], ( b ) ? "True" : "False" ); + } +} +``` + +
+ + + +
+ + +