diff --git a/.github/workflows/autoclose.yml b/.github/workflows/autoclose.yml index 78850dea28a..4d6df813918 100644 --- a/.github/workflows/autoclose.yml +++ b/.github/workflows/autoclose.yml @@ -179,3 +179,35 @@ jobs: GH_TOKEN: ${{ secrets.STDLIB_BOT_GITHUB_TOKEN }} GH_REPO: ${{ github.repository }} NUMBER: ${{ github.event.pull_request.number }} + + # Define a job which closes a pull request if a pull request is considered stale: + stale: + + # Define job name: + name: 'Check for stale label' + + # Only run this job if the pull request has a specific label: + if: "${{ github.event.label.name == 'autoclose: Stale' }}" + + # Define job permissions: + permissions: + contents: read + issues: write + pull-requests: write + + # Define the type of virtual host machine: + runs-on: ubuntu-latest + + # Define the sequence of job steps: + steps: + # Close the pull request: + - name: 'Close pull request' + run: gh pr close "$NUMBER" --comment "$BODY" + env: + GH_TOKEN: ${{ secrets.STDLIB_BOT_GITHUB_TOKEN }} + GH_REPO: ${{ github.repository }} + NUMBER: ${{ github.event.pull_request.number }} + BODY: | + This pull request has been automatically closed because it has been inactive for an extended period after changes were requested. If you still wish to pursue this contribution, feel free to reopen the pull request or submit a new one. + + We appreciate your interest in contributing to stdlib! diff --git a/.github/workflows/generate_pr_commit_message.yml b/.github/workflows/generate_pr_commit_message.yml index 859fa86b267..181b95814d5 100644 --- a/.github/workflows/generate_pr_commit_message.yml +++ b/.github/workflows/generate_pr_commit_message.yml @@ -21,14 +21,19 @@ name: generate_pr_commit_message # Workflow triggers: on: - pull_request: + pull_request_target: types: - labeled # Global permissions: permissions: + # Allow read-only access to the repository contents: contents: read + + # Allow write access to issues, assignees, labels, and milestones: issues: write + + # Allow write access to pull requests: pull-requests: write # Workflow jobs: diff --git a/.github/workflows/scripts/generate_pr_commit_message b/.github/workflows/scripts/generate_pr_commit_message index a20615549b3..8d2b99726b9 100755 --- a/.github/workflows/scripts/generate_pr_commit_message +++ b/.github/workflows/scripts/generate_pr_commit_message @@ -56,7 +56,24 @@ on_error() { exit "$1" } -# Function to resolve GitHub handle to name and email using .mailmap +# Resolves a name and email using .mailmap via git check-mailmap, falling back to the provided values if no match is found. +# +# $1 - name +# $2 - email +resolve_name_email() { + local name="$1" + local email="$2" + local resolved + + resolved=$(git check-mailmap "$name <$email>" 2>/dev/null) + if [ -n "$resolved" ]; then + echo "$resolved" + else + echo "$name <$email>" + fi +} + +# Resolves GitHub handle to name and email using .mailmap. # # $1 - GitHub handle resolve_user() { @@ -76,24 +93,47 @@ resolve_user() { fi } -# Function to make authenticated GitHub API requests +# Makes GitHub API requests. # # $1 - HTTP method (GET or POST) # $2 - API endpoint -# $3 - Data for POST requests +# $3 - data for POST requests github_api() { local method="$1" local endpoint="$2" local data="$3" - if [ "$method" == "GET" ]; then - curl -s -H "Authorization: token $GITHUB_TOKEN" "$GITHUB_API_URL$endpoint" - elif [ "$method" == "POST" ]; then - curl -s -X POST -H "Authorization: token $GITHUB_TOKEN" -H "Content-Type: application/json" -d "$data" "$GITHUB_API_URL$endpoint" - else - echo "Invalid HTTP method: $method" - on_error 1 + # Initialize an array to hold curl headers: + local headers=() + + # If GITHUB_TOKEN is set, add the Authorization header: + if [ -n "$GITHUB_TOKEN" ]; then + headers+=("-H" "Authorization: token $GITHUB_TOKEN") fi + + # Determine the HTTP method and construct the curl command accordingly... + case "$method" in + GET) + curl -s "${headers[@]}" "$GITHUB_API_URL$endpoint" + ;; + POST) + # For POST requests, always set the Content-Type header> + headers+=("-H" "Content-Type: application/json") + + # If data is provided, include it in the request: + if [ -n "$data" ]; then + curl -s -X POST "${headers[@]}" -d "$data" "$GITHUB_API_URL$endpoint" + else + # Handle cases where POST data is required but not provided: + echo "POST request requires data." + on_error 1 + fi + ;; + *) + echo "Invalid HTTP method: $method" + on_error 1 + ;; + esac } # Main execution sequence. @@ -103,6 +143,10 @@ main() { pr_title=$(echo "$pr_details" | jq -r '.title') pr_body=$(echo "$pr_details" | jq -r '.body // ""') pr_url=$(echo "$pr_details" | jq -r '.html_url') + pr_author_login=$(echo "$pr_details" | jq -r '.user.login') + + # Resolve the PR author's name and email using .mailmap: + pr_author_resolved=$(resolve_user "$pr_author_login") # Extract reviewers: pr_reviews=$(github_api "GET" "/repos/$REPO_OWNER/$REPO_NAME/pulls/$pr_number/reviews") @@ -111,15 +155,68 @@ main() { # Fetch commits in the PR: pr_commits=$(github_api "GET" "/repos/$REPO_OWNER/$REPO_NAME/pulls/$pr_number/commits") - # Extract co-authors from commits: - co_authors=$(echo "$pr_commits" | jq -r '.[].commit.message' | grep -i "Co-authored-by:" | awk -F': ' '{print $2}' | sort | uniq | paste -sd '\n' -) + # Extract co-authors from commit messages: + processed_co_authors="" + while IFS= read -r co_author_line; do + name_email=$(echo "$co_author_line" | sed -E 's/Co-authored-by:[[:space:]]*(.*)/\1/') + name=$(echo "$name_email" | sed -E 's/^(.*)<.*>$/\1/' | xargs) + email=$(echo "$name_email" | sed -E 's/^.*<(.*)>$/\1/' | xargs) + resolved_author=$(resolve_name_email "$name" "$email") + + processed_co_authors+="Co-authored-by: $resolved_author"$'\n' + done <<< "$co_authors" + + # Extract commit authors: + authors_info=$(echo "$pr_commits" | jq -r '.[] | .commit.author | "\(.name) <\(.email)>"' | sort -u | sed '/^ *<.*>/d' | sed '/^$/d') + + # Process commit authors: + commit_authors="" + while IFS= read -r author_line; do + # Skip empty lines: + if [ -z "$author_line" ]; then + continue + fi + + # Extract name and email: + name=$(echo "$author_line" | sed -E 's/^(.*)<.*>$/\1/' | xargs) + email=$(echo "$author_line" | sed -E 's/^.*<(.*)>$/\1/' | xargs) + + # Resolve name and email using .mailmap: + resolved_author=$(resolve_name_email "$name" "$email") + + # Skip if the resolved author matches the resolved PR author: + if [ "$resolved_author" == "$pr_author_resolved" ]; then + continue + fi + + commit_authors+="$resolved_author"$'\n' + done <<< "$authors_info" + + # Remove any empty lines and duplicates: + commit_authors=$(echo "$commit_authors" | sort -u | sed '/^$/d') - # Extract linked issues from PR body (e.g., #123) + # Prefix with 'Co-authored-by: ': + commit_authors_formatted=$(echo "$commit_authors" | sed 's/^/Co-authored-by: /' | sort -u) + + # Combine co-authors and commit authors: + all_co_authors=$(echo -e "$co_authors\n$commit_authors_formatted" | sort -u | sed '/^$/d') + + # Extract 'Signed-off-by' lines from commits: + signed_off_bys=$(echo "$pr_commits" | jq -r '.[].commit.message' | grep -Eio 'Signed-off-by:.*' | sort -u) + + # Extract linked issues from PR body (e.g., #123): issue_numbers=$(echo "$pr_body" | grep -oE '#[0-9]+' | grep -oE '[0-9]+' | sort | uniq) closes_issues="" ref_issues="" + + # GitHub-supported closing keywords: + closing_keywords=("close" "closes" "closed" "fix" "fixes" "fixed" "resolve" "resolves" "resolved") + + # Create a regex pattern from the keywords: + keywords_pattern=$(IFS='|'; echo "${closing_keywords[*]}") + for issue in $issue_numbers; do - if echo "$pr_body" | grep -qi "closes.*#$issue"; then + if echo "$pr_body" | grep -Eiq "(${keywords_pattern})([[:space:]]+|:)[[:space:]]*#${issue}\b"; then closes_issues+="Closes: https://github.com/$REPO_OWNER/$REPO_NAME/issues/$issue\n" else ref_issues+="Ref: https://github.com/$REPO_OWNER/$REPO_NAME/issues/$issue\n" @@ -138,18 +235,19 @@ main() { if [ -n "$ref_issues" ]; then commit_body+="\n$ref_issues" fi - if [ -n "$co_authors" ]; then - commit_body+="\n$co_authors" + commit_body+="\n" + if [ -n "$all_co_authors" ]; then + commit_body+="\n$all_co_authors" fi for reviewer in $reviewers; do resolved_reviewer=$(resolve_user "$reviewer") commit_body+="\nReviewed-by: $resolved_reviewer" done - # Add Signed-off-by line: - pr_author=$(echo "$pr_details" | jq -r '.user.login') - signed_off_by=$(resolve_user "$pr_author") - commit_body+="\nSigned-off-by: $signed_off_by" + # Include Signed-off-by lines if present in the commits: + if [ -n "$signed_off_bys" ]; then + commit_body+="\n$signed_off_bys" + fi # Combine subject and body: commit_message="$commit_subject\n\n$commit_body" diff --git a/.mailmap b/.mailmap index a864d636170..02e19f31034 100644 --- a/.mailmap +++ b/.mailmap @@ -36,6 +36,9 @@ Chinmay Joshi <86140365+JawHawk@users.noreply.github.com> Chinmay J # D +Debashis Maharana <145602692+DevMhrn@users.noreply.github.com> +Debashis Maharana DebashisMaharana + Dorrin Sotoudeh <59933477+dorrin-sot@users.noreply.github.com> Dorrin Sotoudeh dorrin-sot diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 147a89effda..e7469a9e835 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -21,6 +21,7 @@ Christopher Dambamuromo Dan Rose Daniel Killenberger Daniel Yu <40680511+Daniel777y@users.noreply.github.com> +Debashis Maharana Dominik Moritz Dorrin Sotoudeh EuniceSim142 <77243938+EuniceSim142@users.noreply.github.com> @@ -99,6 +100,7 @@ Xiaochuan Ye Yernar Yergaziyev naveen nishant-s7 <97207366+nishant-s7@users.noreply.github.com> +olenkabilonizhka <62379231+olenkabilonizhka@users.noreply.github.com> orimiles5 <97595296+orimiles5@users.noreply.github.com> rainn <88160429+AmCodesLame@users.noreply.github.com> rei2hu diff --git a/lib/node_modules/@stdlib/_tools/changelog/generate/lib/format_contributors.js b/lib/node_modules/@stdlib/_tools/changelog/generate/lib/format_contributors.js index efb75decb36..a261c3d710d 100644 --- a/lib/node_modules/@stdlib/_tools/changelog/generate/lib/format_contributors.js +++ b/lib/node_modules/@stdlib/_tools/changelog/generate/lib/format_contributors.js @@ -20,6 +20,9 @@ // MODULES // +var join = require( 'path' ).join; +var spawn = require( 'child_process' ).spawnSync; // eslint-disable-line node/no-sync +var logger = require( 'debug' ); var contains = require( '@stdlib/assert/contains' ); var replace = require( '@stdlib/string/replace' ); var map = require( '@stdlib/utils/map' ); @@ -31,11 +34,32 @@ var EXCLUDED_CONTRIBUTORS = require( './excluded_contributors.json' ); // VARIABLES // +var debug = logger( 'changelog:generate:format-contributors' ); var RE_CO_AUTHORED_BY = /co-authored-by/i; +var RESOLVE_NAME_EMAIL_CMD = join( __dirname, '..', 'scripts', 'resolve_name_email.sh' ); // FUNCTIONS // +/** +* Resolves a Git user name and email address according to the .mailmap file. +* +* @private +* @param {string} pair - name and email pair +* @returns {string} canonical name and email address if found, otherwise the original input +*/ +function resolveNameEmailPair( pair ) { + try { + debug( 'Attempting to resolve name and email: %s.', pair ); + return spawn( RESOLVE_NAME_EMAIL_CMD, [ pair ], { + 'stdio': [ 'pipe', 'pipe', 'ignore' ] // stdin, stdout, stderr + }).stdout.toString(); + } catch ( err ) { + debug( 'Encountered an error resolving name and email: %s.', err.message ); + return pair; + } +} + /** * Extracts a list of contributors from a list of commits. * @@ -66,7 +90,8 @@ function extractContributors( commits ) { if ( RE_CO_AUTHORED_BY.test( mention.action ) ) { - author = replace( mention.ref, /\s*<[^>]+>\s*/, '' ); + author = resolveNameEmailPair( mention.ref ); + author = replace( author, /\s*<[^>]+>\s*/, '' ); if ( !contains( out, author ) && !contains( EXCLUDED_CONTRIBUTORS, author ) diff --git a/lib/node_modules/@stdlib/_tools/changelog/generate/scripts/resolve_name_email.sh b/lib/node_modules/@stdlib/_tools/changelog/generate/scripts/resolve_name_email.sh new file mode 100755 index 00000000000..2beb4848709 --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/changelog/generate/scripts/resolve_name_email.sh @@ -0,0 +1,40 @@ +#!/usr/bin/env bash +# +# @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. + +# Script for resolving a name and email using .mailmap via `git check-mailmap`. +# +# Usage: resolve-mailmap.sh "name " +# +# Arguments: +# +# name_email The name and email pair in the format "name " +# + +if [ -z "$1" ]; then + echo "Error: must provide a name and email in the format \"name \"." >&2 + exit 1 +fi + +name_email="$1" + +resolved=$(git check-mailmap "$name_email" 2>/dev/null) +if [ -n "$resolved" ]; then + echo "$resolved" +else + echo "$name_email" +fi diff --git a/lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-typedef-typos/lib/defaults.json b/lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-typedef-typos/lib/defaults.json index 054004098f7..1346811ef50 100644 --- a/lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-typedef-typos/lib/defaults.json +++ b/lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-typedef-typos/lib/defaults.json @@ -1,86 +1,123 @@ { "types": [ - "boolean", - "number", - "string", - "Boolean", - "Number", - "String", "Array", - "ndarray", - "Error", - "EvalError", - "RangeError", - "ReferenceError", - "SyntaxError", - "TypeError", - "Function", - "Object", - "PlainObject", - "ObjectLike", - "Options", + "ArrayArray", "ArrayLike", "ArrayLikeObject", - "Namespace", + "boolean", + "Boolean", + "BooleanArray", "Buffer", + "Callback", "Collection", + "Complex", + "Complex64", + "Complex64Array", + "Complex64ArrayFE", + "Complex64ArrayBE", + "Complex64ArrayLE", + "Complex128", + "Complex128Array", + "Complex128ArrayFE", + "Complex128ArrayBE", + "Complex128ArrayLE", + "ComplexLike", "Date", - "RegExp", - "void", + "EmptyArray", + "Error", + "EvalError", + "FiniteNumber", + "Float32Array", + "Float32ArrayFE", + "Float32ArrayBE", + "Float32ArrayLE", + "Float64Array", + "Float64ArrayFE", + "Float64ArrayBE", + "Float64ArrayLE", + "Function", + "FunctionArray", + "Gumbel", "Int8Array", + "Int8ArrayFE", + "Int8ArrayBE", + "Int8ArrayLE", "Int16Array", + "Int16ArrayFE", + "Int16ArrayBE", + "Int16ArrayLE", "Int32Array", - "Uint8Array", - "Uint8ClampedArray", - "Uint16Array", - "Uint32Array", - "Float32Array", - "Float64Array", - "TypedArray", + "Int32ArrayFE", + "Int32ArrayBE", + "Int32ArrayLE", + "integer", + "integer8", + "integer16", + "integer32", + "IntegerArray", "IntegerTypedArray", - "NumericArray", - "NumberArray", - "PositiveNumericArray", + "Namespace", + "ndarray", + "ndarrayLike", + "NegativeInteger", + "NegativeIntegerArray", + "NegativeNumber", "NegativeNumericArray", - "NonPositiveNumericArray", + "NonNegativeInteger", + "NonNegativeIntegerArray", + "NonNegativeNumber", "NonNegativeNumericArray", - "IntegerArray", - "PositiveIntegerArray", - "NegativeIntegerArray", + "NonPositiveInteger", "NonPositiveIntegerArray", - "NonNegativeIntegerArray", - "StringArray", - "BooleanArray", + "NonPositiveNumber", + "NonPositiveNumericArray", + "number", + "Number", + "NumberArray", + "NumericArray", + "Object", "ObjectArray", - "FunctionArray", - "ArrayArray", - "EmptyArray", + "ObjectLike", + "Options", + "Path", + "PlainObject", + "PositiveInteger", + "PositiveIntegerArray", + "PositiveNumber", + "PositiveNumericArray", + "primitive", + "Probability", "ProbabilityArray", + "RangeError", + "ReferenceError", + "RegExp", "Stream", - "Callback", - "primitive", - "integer", + "string", + "String", + "StringArray", + "SyntaxError", + "TypedArray", + "TypeError", + "Uint8Array", + "Uint8ArrayFE", + "Uint8ArrayBE", + "Uint8ArrayLE", + "Uint8ClampedArray", + "Uint8ClampedArrayFE", + "Uint8ClampedArrayBE", + "Uint8ClampedArrayLE", + "Uint16Array", + "Uint16ArrayFE", + "Uint16ArrayBE", + "Uint16ArrayLE", + "Uint32Array", + "Uint32ArrayFE", + "Uint32ArrayBE", + "Uint32ArrayLE", "uinteger", - "integer32", - "uinteger32", - "integer16", - "uinteger16", - "integer8", "uinteger8", - "NonNegativeInteger", - "PositiveInteger", - "NonPositiveInteger", - "NegativeInteger", - "NonNegativeNumber", - "PositiveNumber", - "NonPositiveNumber", - "NegativeNumber", - "FiniteNumber", - "Probability", - "Complex64", - "Complex128", - "Complex", - "Gumbel", - "Path" + "uinteger16", + "uinteger32", + "void" ] } diff --git a/lib/node_modules/@stdlib/array/base/accessor-getter/docs/repl.txt b/lib/node_modules/@stdlib/array/base/accessor-getter/docs/repl.txt index e92c83dac91..68ead221c90 100644 --- a/lib/node_modules/@stdlib/array/base/accessor-getter/docs/repl.txt +++ b/lib/node_modules/@stdlib/array/base/accessor-getter/docs/repl.txt @@ -5,8 +5,8 @@ An accessor function accepts the following arguments: - - arr: input array - - idx: element index + - arr: input array. + - idx: element index. If provided an unsupported `dtype`, the function returns a default accessor function for accessing elements from any indexed array-like object diff --git a/lib/node_modules/@stdlib/array/base/accessor-setter/docs/repl.txt b/lib/node_modules/@stdlib/array/base/accessor-setter/docs/repl.txt index 3a69e0eb8a2..f0fee097384 100644 --- a/lib/node_modules/@stdlib/array/base/accessor-setter/docs/repl.txt +++ b/lib/node_modules/@stdlib/array/base/accessor-setter/docs/repl.txt @@ -5,9 +5,9 @@ An accessor function accepts the following arguments: - - arr: input array - - idx: element index - - value: value to set + - arr: input array. + - idx: element index. + - value: value to set. If provided an unsupported `dtype`, the function returns a default accessor function for accessing elements in any indexed array-like object supporting diff --git a/lib/node_modules/@stdlib/array/base/assert/is-byte-order/README.md b/lib/node_modules/@stdlib/array/base/assert/is-byte-order/README.md new file mode 100644 index 00000000000..e7f2bfe1430 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/assert/is-byte-order/README.md @@ -0,0 +1,117 @@ + + +# isByteOrder + +> Test if an input value is a supported array byte order. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var isByteOrder = require( '@stdlib/array/base/assert/is-byte-order' ); +``` + +#### isByteOrder( value ) + +Tests if an input `value` is a supported array byte order. + +```javascript +var bool = isByteOrder( 'little-endian' ); +// returns true + +bool = isByteOrder( 'big-endian' ); +// returns true +``` + +
+ + + + + +
+ +
+ + + + + +
+ +## Examples + + + +```javascript +var isByteOrder = require( '@stdlib/array/base/assert/is-byte-order' ); + +var bool = isByteOrder( 'little-endian' ); +// returns true + +bool = isByteOrder( 'big-endian' ); +// returns true + +bool = isByteOrder( '' ); +// returns false + +bool = isByteOrder( 'foo' ); +// returns false +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/array/base/assert/is-byte-order/benchmark/benchmark.js b/lib/node_modules/@stdlib/array/base/assert/is-byte-order/benchmark/benchmark.js new file mode 100644 index 00000000000..56ac0a39b90 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/assert/is-byte-order/benchmark/benchmark.js @@ -0,0 +1,61 @@ +/** +* @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 isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; +var pkg = require( './../package.json' ).name; +var isByteOrder = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var values; + var out; + var v; + var i; + + values = [ + 'little-endian', + 'big-endian', + 'foo', + 'bar', + '', + 'beep', + 'boop' + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = values[ i%values.length ]; + out = isByteOrder( v ); + if ( typeof out !== 'boolean' ) { + b.fail( 'should return a boolean' ); + } + } + b.toc(); + if ( !isBoolean( out ) ) { + b.fail( 'should return a boolean' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/base/assert/is-byte-order/docs/repl.txt b/lib/node_modules/@stdlib/array/base/assert/is-byte-order/docs/repl.txt new file mode 100644 index 00000000000..99bfd0ec5f5 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/assert/is-byte-order/docs/repl.txt @@ -0,0 +1,28 @@ + +{{alias}}( value ) + Tests if an input value is a supported array byte order. + + Parameters + ---------- + value: any + Value to test. + + Returns + ------- + bool: boolean + Boolean indicating if an input value is a supported array byte order. + + Examples + -------- + > var bool = {{alias}}( 'little-endian' ) + true + > bool = {{alias}}( 'big-endian' ) + true + > bool = {{alias}}( '' ) + false + > bool = {{alias}}( 'beep' ) + false + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/array/base/assert/is-byte-order/docs/types/index.d.ts b/lib/node_modules/@stdlib/array/base/assert/is-byte-order/docs/types/index.d.ts new file mode 100644 index 00000000000..8f4648b2921 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/assert/is-byte-order/docs/types/index.d.ts @@ -0,0 +1,42 @@ +/* +* @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 + +/** +* Tests whether an input value is a supported array byte order. +* +* @param v - value to test +* @returns boolean indicating whether an input value is a supported array byte order +* +* @example +* var bool = isByteOrder( 'little-endian' ); +* // returns true +* +* bool = isByteOrder( 'big-endian' ); +* // returns true +* +* bool = isByteOrder( 'foo' ); +* // returns false +*/ +declare function isByteOrder( v: any ): boolean; + + +// EXPORTS // + +export = isByteOrder; diff --git a/lib/node_modules/@stdlib/array/base/assert/is-byte-order/docs/types/test.ts b/lib/node_modules/@stdlib/array/base/assert/is-byte-order/docs/types/test.ts new file mode 100644 index 00000000000..791513a0359 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/assert/is-byte-order/docs/types/test.ts @@ -0,0 +1,34 @@ +/* +* @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 isByteOrder = require( './index' ); + + +// TESTS // + +// The function returns a boolean... +{ + isByteOrder( 'little-endian' ); // $ExpectType boolean + isByteOrder( 'foo' ); // $ExpectType boolean +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + isByteOrder(); // $ExpectError + isByteOrder( undefined, 123 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/array/base/assert/is-byte-order/examples/index.js b/lib/node_modules/@stdlib/array/base/assert/is-byte-order/examples/index.js new file mode 100644 index 00000000000..c752f4d549a --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/assert/is-byte-order/examples/index.js @@ -0,0 +1,37 @@ +/** +* @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 isByteOrder = require( './../lib' ); + +var bool = isByteOrder( 'little-endian' ); +console.log( bool ); +// => true + +bool = isByteOrder( 'big-endian' ); +console.log( bool ); +// => true + +bool = isByteOrder( '' ); +console.log( bool ); +// => false + +bool = isByteOrder( 'foo' ); +console.log( bool ); +// => false diff --git a/lib/node_modules/@stdlib/array/base/assert/is-byte-order/lib/index.js b/lib/node_modules/@stdlib/array/base/assert/is-byte-order/lib/index.js new file mode 100644 index 00000000000..43381c3930c --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/assert/is-byte-order/lib/index.js @@ -0,0 +1,46 @@ +/** +* @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'; + +/** +* Test whether an input value is a supported array byte order. +* +* @module @stdlib/array/base/assert/is-byte-order +* +* @example +* var isByteOrder = require( '@stdlib/array/base/assert/is-byte-order' ); +* +* var bool = isByteOrder( 'little-endian' ); +* // returns true +* +* bool = isByteOrder( 'big-endian' ); +* // returns true +* +* bool = isByteOrder( 'foo' ); +* // returns false +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/array/base/assert/is-byte-order/lib/main.js b/lib/node_modules/@stdlib/array/base/assert/is-byte-order/lib/main.js new file mode 100644 index 00000000000..bac8f2b5565 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/assert/is-byte-order/lib/main.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'; + +// MODULES // + +var contains = require( '@stdlib/array/base/assert/contains' ).factory; +var byteOrders = require( '@stdlib/array/byte-orders' ); + + +// MAIN // + +/** +* Tests whether an input value is a supported array byte order. +* +* @name isByteOrder +* @type {Function} +* @param {*} v - value to test +* @returns {boolean} boolean indicating whether an input value is a supported array byte order +* +* @example +* var bool = isByteOrder( 'little-endian' ); +* // returns true +* +* bool = isByteOrder( 'big-endian' ); +* // returns true +* +* bool = isByteOrder( 'foo' ); +* // returns false +*/ +var isByteOrder = contains( byteOrders() ); + + +// EXPORTS // + +module.exports = isByteOrder; diff --git a/lib/node_modules/@stdlib/array/base/assert/is-byte-order/package.json b/lib/node_modules/@stdlib/array/base/assert/is-byte-order/package.json new file mode 100644 index 00000000000..b9e76faf703 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/assert/is-byte-order/package.json @@ -0,0 +1,75 @@ +{ + "name": "@stdlib/array/base/assert/is-byte-order", + "version": "0.0.0", + "description": "Test if an input value is a supported array byte order.", + "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", + "stdtypes", + "types", + "base", + "array", + "order", + "memory", + "endianness", + "endian", + "utilities", + "utility", + "utils", + "util", + "assert", + "test", + "check", + "is", + "valid", + "validate", + "validation", + "isvalid" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/array/base/assert/is-byte-order/test/test.js b/lib/node_modules/@stdlib/array/base/assert/is-byte-order/test/test.js new file mode 100644 index 00000000000..e2aff33237c --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/assert/is-byte-order/test/test.js @@ -0,0 +1,77 @@ +/** +* @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 isByteOrder = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof isByteOrder, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns `true` if provided a supported array byte order', function test( t ) { + var values; + var bool; + var i; + + values = [ + 'little-endian', + 'big-endian' + ]; + for ( i = 0; i < values.length; i++ ) { + bool = isByteOrder( values[ i ] ); + t.strictEqual( bool, true, 'returns expected value when provided '+values[ i ] ); + } + t.end(); +}); + +tape( 'the function returns `false` if not provided a supported array byte order', function test( t ) { + var values; + var bool; + var i; + + values = [ + '', + 'beep', + 'boop', + 'foo', + 'bar', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + bool = isByteOrder( values[ i ] ); + t.strictEqual( bool, false, 'returns expected value when provided '+values[ i ] ); + } + t.end(); +}); diff --git a/lib/node_modules/@stdlib/array/base/assert/lib/index.js b/lib/node_modules/@stdlib/array/base/assert/lib/index.js index 1af980f35c0..149c00d7cb1 100644 --- a/lib/node_modules/@stdlib/array/base/assert/lib/index.js +++ b/lib/node_modules/@stdlib/array/base/assert/lib/index.js @@ -99,6 +99,15 @@ setReadOnly( ns, 'isBooleanDataType', require( '@stdlib/array/base/assert/is-boo */ setReadOnly( ns, 'isBooleanArray', require( '@stdlib/array/base/assert/is-booleanarray' ) ); +/** +* @name isByteOrder +* @memberof ns +* @readonly +* @type {Function} +* @see {@link module:@stdlib/array/base/assert/is-byte-order} +*/ +setReadOnly( ns, 'isByteOrder', require( '@stdlib/array/base/assert/is-byte-order' ) ); + /** * @name isComplexFloatingPointDataType * @memberof ns diff --git a/lib/node_modules/@stdlib/array/base/cuany-by-right/README.md b/lib/node_modules/@stdlib/array/base/cuany-by-right/README.md new file mode 100644 index 00000000000..e17d5b78c49 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cuany-by-right/README.md @@ -0,0 +1,152 @@ + + +# cuanyByRight + +> Cumulatively test whether at least one element in a provided array passes a test implemented by a predicate function, while iterating from right-to-left. + +
+ +## Usage + +```javascript +var cuanyByRight = require( '@stdlib/array/base/cuany-by-right' ); +``` + +#### cuanyByRight( x, predicate\[, thisArg] ) + +Cumulatively tests whether at least one element in a provided array passes a test implemented by a `predicate` function, while iterating from right-to-left. + +```javascript +function isPositive( value ) { + return ( value > 0 ); +} + +var x = [ 0, 0, 0, 1, 0 ]; + +var y = cuanyByRight( x, isPositive ); +// returns [ false, true, true, true, true ] +``` + +The `predicate` function is provided three arguments: + +- **value**: current array element. +- **index**: current array element index. +- **arr**: input array. + +To set the `predicate` function execution context, provide a `thisArg`. + +```javascript +function isPositive( value ) { + this.count += 1; + return ( value > 0 ); +} + +var x = [ 0, 1, 0, 0, 0 ]; + +var context = { + 'count': 0 +}; + +var out = cuanyByRight( x, isPositive, context ); +// returns [ false, false, false, true, true ] + +var cnt = context.count; +// returns 4 +``` + +#### cuanyByRight.assign( x, out, stride, offset, predicate\[, thisArg] ) + +Cumulatively tests whether at least one element in a provided array passes a test implemented by a `predicate` function, while iterating from right-to-left, and assigns results to a provided output array. + +```javascript +function isPositive( value ) { + return ( value > 0 ); +} + +var x = [ 0, 1, 0, 0, 0 ]; +var y = [ false, null, false, null, false, null, false, null, false, null ]; + +var out = cuanyByRight.assign( x, y, 2, 0, isPositive ); +// returns [ false, null, false, null, false, null, true, null, true, null ] + +var bool = ( out === y ); +// returns true +``` + +The function supports the following parameters: + +- **x**: input array. +- **out**: output array. +- **stride**: output array stride. +- **offset**: output array offset. +- **predicate**: test function. + +
+ + + +
+ +
+ + + +
+ +## Examples + + + +```javascript +var bernoulli = require( '@stdlib/random/array/bernoulli' ); +var cuanyByRight = require( '@stdlib/array/base/cuany-by-right' ); + +function isPositive( value ) { + return ( value > 0 ); +} + +// Create an array of random values: +var x = bernoulli( 10, 0.1 ); +console.log( x ); + +var out = cuanyByRight( x, isPositive ); +console.log( out ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/array/base/cuany-by-right/benchmark/benchmark.assign.length.js b/lib/node_modules/@stdlib/array/base/cuany-by-right/benchmark/benchmark.assign.length.js new file mode 100644 index 00000000000..7116da4d52c --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cuany-by-right/benchmark/benchmark.assign.length.js @@ -0,0 +1,99 @@ +/** +* @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 pow = require( '@stdlib/math/base/special/pow' ); +var isArray = require( '@stdlib/assert/is-array' ); +var isPositiveInteger = require( '@stdlib/assert/is-positive-integer' ).isPrimitive; +var filled = require( '@stdlib/array/base/filled' ); +var pkg = require( './../package.json' ).name; +var cuanyByRight = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = filled( 1.5, len ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var y; + var v; + var i; + + y = filled( false, len ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = cuanyByRight.assign( x, y, 1, 0, isPositiveInteger ); + if ( typeof v !== 'object' ) { + b.fail( 'should return an array' ); + } + } + b.toc(); + if ( !isArray( v ) ) { + b.fail( 'should return an array' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':assign:len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/base/cuany-by-right/benchmark/benchmark.js b/lib/node_modules/@stdlib/array/base/cuany-by-right/benchmark/benchmark.js new file mode 100644 index 00000000000..e6515d804b0 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cuany-by-right/benchmark/benchmark.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'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isArray = require( '@stdlib/assert/is-array' ); +var isPositiveInteger = require( '@stdlib/assert/is-positive-integer' ).isPrimitive; +var pkg = require( './../package.json' ).name; +var cuanyByRight = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var x; + var i; + var v; + + x = [ 1, 1, 0, 0, 0 ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = cuanyByRight( x, isPositiveInteger ); + if ( typeof v !== 'object' ) { + b.fail( 'should return an array' ); + } + } + b.toc(); + if ( !isArray( v ) ) { + b.fail( 'should return an array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/base/cuany-by-right/benchmark/benchmark.length.js b/lib/node_modules/@stdlib/array/base/cuany-by-right/benchmark/benchmark.length.js new file mode 100644 index 00000000000..a3fe131c396 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cuany-by-right/benchmark/benchmark.length.js @@ -0,0 +1,96 @@ +/** +* @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 pow = require( '@stdlib/math/base/special/pow' ); +var isArray = require( '@stdlib/assert/is-array' ); +var isPositiveInteger = require( '@stdlib/assert/is-positive-integer' ).isPrimitive; +var filled = require( '@stdlib/array/base/filled' ); +var pkg = require( './../package.json' ).name; +var cuanyByRight = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = filled( 0, len ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = cuanyByRight( x, isPositiveInteger ); + if ( typeof v !== 'object' ) { + b.fail( 'should return an array' ); + } + } + b.toc(); + if ( !isArray( v ) ) { + b.fail( 'should return an array' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/base/cuany-by-right/docs/repl.txt b/lib/node_modules/@stdlib/array/base/cuany-by-right/docs/repl.txt new file mode 100644 index 00000000000..d22386ea1fa --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cuany-by-right/docs/repl.txt @@ -0,0 +1,83 @@ +{{alias}}( x, predicate[, thisArg] ) + Cumulatively tests whether at least one array element in a provided array + passes a test implemented by a predicate function, while iterating from + right-to-left. + + The predicate function is provided three arguments: + + - value: current array element. + - index: current array element index. + - arr: the input array. + + Parameters + ---------- + x: ArrayLikeObject + Input array. + + predicate: Function + Predicate function. + + thisArg: any (optional) + Execution context. + + Returns + ------- + out: Array + Output array. + + Examples + -------- + > function isPositive( v ) { return ( v > 0 ); }; + > var x = [ 1, 1, 0, 0, 0 ]; + > var y = {{alias}}( x, isPositive ) + [ false, false, false, true, true ] + + +{{alias}}.assign( x, out, stride, offset, predicate[, thisArg] ) + Cumulatively tests whether at least one array element in a provided array + passes a test implemented by a predicate function, while iterating from + right-to-left, and assigns the results to the provided output array. + + The predicate function is provided three arguments: + + - value: current array element. + - index: current array element index. + - arr: the input array. + + Parameters + ---------- + x: ArrayLikeObject + Input array. + + out: ArrayLikeObject + Output array. + + stride: integer + Output array stride. + + offset: integer + Output array offset. + + predicate: Function + Predicate function. + + thisArg: any (optional) + Execution context. + + Returns + ------- + out: ArrayLikeObject + Output array. + + Examples + -------- + > function isPositive( v ) { return ( v > 0 ); }; + > var x = [ 1, 1, 0, 0 ]; + > var out = [ false, null, false, null, false, null, false, null ]; + > var arr = {{alias}}.assign( x, out, 2, 0, isPositive ) + [ false, null, ..., true, null ] + > var bool = ( arr === out ) + true + + See Also + -------- diff --git a/lib/node_modules/@stdlib/array/base/cuany-by-right/docs/types/index.d.ts b/lib/node_modules/@stdlib/array/base/cuany-by-right/docs/types/index.d.ts new file mode 100644 index 00000000000..33524ad8710 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cuany-by-right/docs/types/index.d.ts @@ -0,0 +1,197 @@ +/* +* @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 { Collection, AccessorArrayLike, TypedArray, BooleanArray } from '@stdlib/types/array'; + +/** +* Checks whether an element in a collection passes a test. +* +* @returns boolean indicating whether an element in a collection passes a test +*/ +type Nullary = ( this: U ) => boolean; + +/** +* Checks whether an element in a collection passes a test. +* +* @param value - collection value +* @returns boolean indicating whether an element in a collection passes a test +*/ +type Unary = ( this: U, value: T ) => boolean; + +/** +* Checks whether an element in a collection passes a test. +* +* @param value - collection value +* @param index - collection index +* @returns boolean indicating whether an element in a collection passes a test +*/ +type Binary = ( this: U, value: T, index: number ) => boolean; + +/** +* Checks whether an element in a collection passes a test. +* +* @param value - collection value +* @param index - collection index +* @param collection - input collection +* @returns boolean indicating whether an element in a collection passes a test +*/ +type Ternary = ( this: U, value: T, index: number, collection: Collection ) => boolean; + +/** +* Checks whether an element in a collection passes a test. +* +* @param value - collection value +* @param index - collection index +* @param collection - input collection +* @returns boolean indicating whether an element in a collection passes a test +*/ +type Predicate = Nullary | Unary | Binary | Ternary; + +/** +* Interface describing `cuanyByRight`. +*/ +interface CuanyByRight { + /** + * Cumulatively tests whether at least one array element in a provided array passes a test implemented by a predicate function, while iterating from right-to-left. + * + * @param x - input array + * @param predicate - test function + * @param thisArg - execution context + * @returns output array + * + * @example + * function isPositive( v ) { + * return v > 0; + * } + * var x = [ 0, 1, 1, 0, 0 ]; + * + * var y = cuanyByRight( x, isPositive ); + * // returns [ false, false, true, true, true ] + */ + ( x: Collection | AccessorArrayLike, predicate: Predicate, thisArg?: ThisParameterType> ): Array; + + /** + * Cumulatively tests whether at least one array element in a provided array passes a test implemented by a predicate function, while iterating from right-to-left, and assigns the results to the provided output array. + * + * @param x - input array + * @param y - output array + * @param stride - output array stride + * @param offset - output array offset + * @param predicate - test function + * @param thisArg - execution context + * @returns output array + * + * @example + * function isPositive( v ) { + * return v > 0; + * } + * var x = [ 1, 1, 0, 0, 0 ]; + * var y = [ false, null, false, null, false, null, false, null, false, null ]; + * + * var arr = cuanyByRight.assign( x, y, 2, 0, isPositive ); + * // returns [ false, null, false, null, false, null, true, null, true, null ] + */ + assign( x: Collection | AccessorArrayLike, out: Array, stride: number, offset: number, predicate: Predicate, thisArg?: ThisParameterType> ): Array; + + /** + * Cumulatively tests whether at least one array element in a provided array passes a test implemented by a predicate function, while iterating from right-to-left, and assigns the results to the provided output array. + * + * @param x - input array + * @param out - output array + * @param stride - output array stride + * @param offset - output array offset + * @param predicate - test function + * @param thisArg - execution context + * @returns output array + * + * @example + * var BooleanArray = require( '@stdlib/array/bool' ); + * + * function isPositive( v ) { + * return ( v > 0 ); + * } + * var x = [ 0, 0, 0, 1, 0 ]; + * var y = new BooleanArray( [ false, false, false, false, false, false, false, false, false, false ] ); + * + * var arr = cuanyByRight.assign( x, y, 2, 0, isPositive ); + * // returns + * + * var v = arr.get( 6 ); + * // returns true + */ + assign( x: Collection | AccessorArrayLike, out: U, stride: number, offset: number, predicate: Predicate, thisArg?: ThisParameterType> ): U; + + /** + * Cumulatively tests whether at least one array element in a provided array passes a test implemented by a predicate function, while iterating from right-to-left, and assigns the results to the provided output array. + * + * @param x - input array + * @param out - output array + * @param stride - output array stride + * @param offset - output array offset + * @param predicate - test function + * @param thisArg - execution context + * @returns output array + * + * @example + * function isPositive( v ) { + * return ( v > 0 ); + * } + * var x = [ 0, 0, 0, 1, 0 ]; + * var y = [ false, null, false, null, false, null, false, null, false, null ]; + * + * var arr = cuanyByRight.assign( x, y, 2, 0, isPositive ); + * // returns [ false, null, false, null, false, null, true, null, true, null ] + */ + assign( x: Collection | AccessorArrayLike, out: Collection | AccessorArrayLike, stride: number, offset: number, predicate: Predicate, thisArg?: ThisParameterType> ): Collection | AccessorArrayLike; +} + +/** +* Cumulatively tests whether at least one array element in a provided array passes a test implemented by a predicate function, while iterating from right-to-left. +* +* @param x - input array +* @param predicate - test function +* @param thisArg - execution context +* @returns output array +* +* @example +* function isPositive( v ) { +* return v > 0; +* } +* var x = [ 1, 1, 0, 0, 0 ]; +* +* var result = cuanyByRight( x, isPositive ); +* // returns [ false, false, false, true, true ] +* +* @example +* function isPositive( v ) { +* return v > 0; +* } +* var x = [ 0, 1, 1, 0, 0 ]; +* var y = [ false, null, false, null, false, null, false, null, false, null ]; +* +* var arr = cuanyByRight.assign( x, y, 2, 0, isPositive ); +* // returns [ false, null, false, null, false, null, true, null, true, null ] +*/ +declare var cuanyByRight: CuanyByRight; + + +// EXPORTS // + +export = cuanyByRight; diff --git a/lib/node_modules/@stdlib/array/base/cuany-by-right/docs/types/test.ts b/lib/node_modules/@stdlib/array/base/cuany-by-right/docs/types/test.ts new file mode 100644 index 00000000000..8a012f9a9f6 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cuany-by-right/docs/types/test.ts @@ -0,0 +1,220 @@ +/* +* @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 cuanyByRight = require( './index' ); + +/** +* Tests whether a value is positive. +* +* @param value - input value +* @returns boolean indicating whether an element is positive +*/ +function isPositive( value: number ): boolean { + return ( value > 0 ); +} + + +// TESTS // + +// The function returns an array... +{ + cuanyByRight( [ 1, 2, 3 ], isPositive ); // $ExpectType boolean[] + cuanyByRight( new Float64Array( [ 1, 2, 3 ] ), isPositive ); // $ExpectType boolean[] + cuanyByRight( new Float32Array( [ 1, 2, 3 ] ), isPositive ); // $ExpectType boolean[] + cuanyByRight( new Int32Array( [ 1, 2, 3 ] ), isPositive ); // $ExpectType boolean[] + cuanyByRight( new Int16Array( [ 1, 2, 3 ] ), isPositive ); // $ExpectType boolean[] + cuanyByRight( new Int8Array( [ 1, 2, 3 ] ), isPositive ); // $ExpectType boolean[] + cuanyByRight( new Uint32Array( [ 1, 2, 3 ] ), isPositive ); // $ExpectType boolean[] + cuanyByRight( new Uint16Array( [ 1, 2, 3 ] ), isPositive ); // $ExpectType boolean[] + cuanyByRight( new Uint8Array( [ 1, 2, 3 ] ), isPositive ); // $ExpectType boolean[] + cuanyByRight( new Uint8ClampedArray( [ 1, 2, 3 ] ), isPositive ); // $ExpectType boolean[] + + cuanyByRight( [ 1, 2, 3 ], isPositive, {} ); // $ExpectType boolean[] + cuanyByRight( new Float64Array( [ 1, 2, 3 ] ), isPositive, {} ); // $ExpectType boolean[] + cuanyByRight( new Float32Array( [ 1, 2, 3 ] ), isPositive, {} ); // $ExpectType boolean[] + cuanyByRight( new Int32Array( [ 1, 2, 3 ] ), isPositive, {} ); // $ExpectType boolean[] + cuanyByRight( new Int16Array( [ 1, 2, 3 ] ), isPositive, {} ); // $ExpectType boolean[] + cuanyByRight( new Int8Array( [ 1, 2, 3 ] ), isPositive, {} ); // $ExpectType boolean[] + cuanyByRight( new Uint32Array( [ 1, 2, 3 ] ), isPositive, {} ); // $ExpectType boolean[] + cuanyByRight( new Uint16Array( [ 1, 2, 3 ] ), isPositive, {} ); // $ExpectType boolean[] + cuanyByRight( new Uint8Array( [ 1, 2, 3 ] ), isPositive, {} ); // $ExpectType boolean[] + cuanyByRight( new Uint8ClampedArray( [ 1, 2, 3 ] ), isPositive, {} ); // $ExpectType boolean[] +} + +// The compiler throws an error if the function is provided a first argument which is not like a function.. +{ + const x = [ 1, 2, 3, 4 ]; + + cuanyByRight( x, null ); // $ExpectError + cuanyByRight( x, {} ); // $ExpectError + cuanyByRight( x, [] ); // $ExpectError + cuanyByRight( x, '' ); // $ExpectError + cuanyByRight( x, undefined ); // $ExpectError + + cuanyByRight( x, null, {} ); // $ExpectError + cuanyByRight( x, {}, {} ); // $ExpectError + cuanyByRight( x, [], {} ); // $ExpectError + cuanyByRight( x, '', {} ); // $ExpectError + cuanyByRight( x, undefined, {} ); // $ExpectError + +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + cuanyByRight(); // $ExpectError + cuanyByRight( [] ); // $ExpectError + cuanyByRight( [ 1, 2 ], isPositive, {}, '' ); // $ExpectError +} + +// Attached to the main export is an `assign` method which returns a collection... +{ + const x = [ 0, 0, 0, 1, 0 ]; + const y = [ false, null, false, null, false, null, false, null, false, null ]; + + cuanyByRight.assign( x, y, 2, 0, isPositive ); // $ExpectType (boolean | null)[] + cuanyByRight.assign( x, y, 2, 0, isPositive, {} ); // $ExpectType (boolean | null)[] + cuanyByRight.assign( x, new Float64Array( 4 ), 1, 0, isPositive ); // $ExpectType Float64Array + cuanyByRight.assign( x, new Float32Array( 4 ), 1, 0, isPositive ); // $ExpectType Float32Array + cuanyByRight.assign( x, new Int32Array( 4 ), 1, 0, isPositive ); // $ExpectType Int32Array + cuanyByRight.assign( x, new Int16Array( 4 ), 1, 0, isPositive ); // $ExpectType Int16Array + cuanyByRight.assign( x, new Int8Array( 4 ), 1, 0, isPositive ); // $ExpectType Int8Array + cuanyByRight.assign( x, new Uint32Array( 4 ), 1, 0, isPositive ); // $ExpectType Uint32Array + cuanyByRight.assign( x, new Uint16Array( 4 ), 1, 0, isPositive ); // $ExpectType Uint16Array + cuanyByRight.assign( x, new Uint8Array( 4 ), 1, 0, isPositive ); // $ExpectType Uint8Array + cuanyByRight.assign( x, new Uint8ClampedArray( 4 ), 1, 0, isPositive ); // $ExpectType Uint8ClampedArray + + cuanyByRight.assign( x, [ 0, 0, 0, 0 ], 1, 0, isPositive, {} ); // $ExpectType (number | boolean)[] + cuanyByRight.assign( x, new Float64Array( 4 ), 1, 0, isPositive, {} ); // $ExpectType Float64Array + cuanyByRight.assign( x, new Float32Array( 4 ), 1, 0, isPositive, {} ); // $ExpectType Float32Array + cuanyByRight.assign( x, new Int32Array( 4 ), 1, 0, isPositive, {} ); // $ExpectType Int32Array + cuanyByRight.assign( x, new Int16Array( 4 ), 1, 0, isPositive, {} ); // $ExpectType Int16Array + cuanyByRight.assign( x, new Int8Array( 4 ), 1, 0, isPositive, {} ); // $ExpectType Int8Array + cuanyByRight.assign( x, new Uint32Array( 4 ), 1, 0, isPositive, {} ); // $ExpectType Uint32Array + cuanyByRight.assign( x, new Uint16Array( 4 ), 1, 0, isPositive, {} ); // $ExpectType Uint16Array + cuanyByRight.assign( x, new Uint8Array( 4 ), 1, 0, isPositive, {} ); // $ExpectType Uint8Array + cuanyByRight.assign( x, new Uint8ClampedArray( 4 ), 1, 0, isPositive, {} ); // $ExpectType Uint8ClampedArray +} + +// The compiler throws an error if the `assign` method is provided a first argument which is not an array-like object... +{ + const x = [ false, false, true, false, false ]; + + cuanyByRight.assign( 1, x, 2, 0, isPositive ); // $ExpectError + cuanyByRight.assign( true, x, 2, 0, isPositive ); // $ExpectError + cuanyByRight.assign( false, x, 2, 0, isPositive ); // $ExpectError + cuanyByRight.assign( null, x, 2, 0, isPositive ); // $ExpectError + cuanyByRight.assign( void 0, x, 2, 0, isPositive ); // $ExpectError + cuanyByRight.assign( {}, x, 2, 0, isPositive ); // $ExpectError + + cuanyByRight.assign( 1, x, 2, 0, isPositive, {} ); // $ExpectError + cuanyByRight.assign( true, x, 2, 0, isPositive, {} ); // $ExpectError + cuanyByRight.assign( false, x, 2, 0, isPositive, {} ); // $ExpectError + cuanyByRight.assign( null, x, 2, 0, isPositive, {} ); // $ExpectError + cuanyByRight.assign( void 0, x, 2, 0, isPositive, {} ); // $ExpectError + cuanyByRight.assign( {}, x, 2, 0, isPositive, {} ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a second argument which is not an array-like object... +{ + const x = [ false, false, true, false, false ]; + + cuanyByRight.assign( x, 1, 2, 0, isPositive ); // $ExpectError + cuanyByRight.assign( x, true, 2, 0, isPositive ); // $ExpectError + cuanyByRight.assign( x, false, 2, 0, isPositive ); // $ExpectError + cuanyByRight.assign( x, null, 2, 0, isPositive ); // $ExpectError + cuanyByRight.assign( x, void 0, 2, 0, isPositive ); // $ExpectError + cuanyByRight.assign( x, {}, 2, 0, isPositive ); // $ExpectError + + cuanyByRight.assign( x, 1, 2, 0, isPositive, {} ); // $ExpectError + cuanyByRight.assign( x, true, 2, 0, isPositive, {} ); // $ExpectError + cuanyByRight.assign( x, false, 2, 0, isPositive, {} ); // $ExpectError + cuanyByRight.assign( x, null, 2, 0, isPositive, {} ); // $ExpectError + cuanyByRight.assign( x, void 0, 2, 0, isPositive, {} ); // $ExpectError + cuanyByRight.assign( x, {}, 2, 0, isPositive, {} ); // $ExpectError +} + + +// The compiler throws an error if the `assign` method is provided a third argument which is not a number... +{ + const x = [ false, false, true, false, false ]; + const y = [ false, null, false, null, false, null, false, null, false, null ]; + + cuanyByRight.assign( x, y , '1', 0, isPositive ); // $ExpectError + cuanyByRight.assign( x, y , true, 0, isPositive ); // $ExpectError + cuanyByRight.assign( x, y , false, 0, isPositive ); // $ExpectError + cuanyByRight.assign( x, y , null, 0, isPositive ); // $ExpectError + cuanyByRight.assign( x, y , void 0, isPositive ); // $ExpectError + cuanyByRight.assign( x, y , {}, 0, isPositive ); // $ExpectError + cuanyByRight.assign( x, y , [], 0, isPositive ); // $ExpectError + + cuanyByRight.assign( x, y , '1', 0, isPositive, {} ); // $ExpectError + cuanyByRight.assign( x, y , true, 0, isPositive, {} ); // $ExpectError + cuanyByRight.assign( x, y , false, 0, isPositive, {} ); // $ExpectError + cuanyByRight.assign( x, y , null, 0, isPositive, {} ); // $ExpectError + cuanyByRight.assign( x, y , void 0, isPositive, {} ); // $ExpectError + cuanyByRight.assign( x, y , {}, 0, isPositive, {} ); // $ExpectError + cuanyByRight.assign( x, y , [], 0, isPositive, {} ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a fourth argument which is not a number... +{ + const x = [ false, false, true, false, false ]; + const y = [ false, null, false, null, false, null, false, null, false, null ]; + + cuanyByRight.assign( x, y, 1, '1', isPositive ); // $ExpectError + cuanyByRight.assign( x, y, 1, true, isPositive ); // $ExpectError + cuanyByRight.assign( x, y, 1, false, isPositive ); // $ExpectError + cuanyByRight.assign( x, y, 1, null, isPositive ); // $ExpectError + cuanyByRight.assign( x, y, 1, void 0, isPositive ); // $ExpectError + cuanyByRight.assign( x, y, 1, {}, isPositive ); // $ExpectError + cuanyByRight.assign( x, y, 1, [], isPositive ); // $ExpectError + + cuanyByRight.assign( x, y, 1, '1', isPositive, {} ); // $ExpectError + cuanyByRight.assign( x, y, 1, true, isPositive, {} ); // $ExpectError + cuanyByRight.assign( x, y, 1, false, isPositive, {} ); // $ExpectError + cuanyByRight.assign( x, y, 1, null, isPositive, {} ); // $ExpectError + cuanyByRight.assign( x, y, 1, void 0, isPositive, {} ); // $ExpectError + cuanyByRight.assign( x, y, 1, {}, isPositive, {} ); // $ExpectError + cuanyByRight.assign( x, y, 1, [], isPositive, {} ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a fourth argument which is not like a function... +{ + const x = [ false, false, true, false, false ]; + const y = [ false, null, false, null, false, null, false, null, false, null ]; + + cuanyByRight.assign( x, y, 1, 2, {} ); // $ExpectError + cuanyByRight.assign( x, y, 1, 2, void 0 ); // $ExpectError + cuanyByRight.assign( x, y, 1, 1, [] ); // $ExpectError + cuanyByRight.assign( x, y, 1, 1, '' ); // $ExpectError + + cuanyByRight.assign( x, y, 1, 2, {}, {} ); // $ExpectError + cuanyByRight.assign( x, y, 1, 2, void 0, {} ); // $ExpectError + cuanyByRight.assign( x, y, 1, 1, [], {} ); // $ExpectError + cuanyByRight.assign( x, y, 1, 1, '', {} ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... +{ + cuanyByRight.assign(); // $ExpectError + cuanyByRight.assign( [] ); // $ExpectError + cuanyByRight.assign( [], [] ); // $ExpectError + cuanyByRight.assign( [], [], 2 ); // $ExpectError + cuanyByRight.assign( [], [], 1, 1, isPositive, [], {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/array/base/cuany-by-right/examples/index.js b/lib/node_modules/@stdlib/array/base/cuany-by-right/examples/index.js new file mode 100644 index 00000000000..07c56c9cd10 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cuany-by-right/examples/index.js @@ -0,0 +1,34 @@ +/** +* @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 bernoulli = require( '@stdlib/random/array/bernoulli' ); +var cuanyByRight = require( './../lib' ); + +function isPositive( value ) { + return ( value > 0 ); +} + +// Create an array of random values: +var x = bernoulli( 10, 0.1 ); +console.log( x ); + +// Cumulatively test whether at least one array element passes a test, while iterating from right-to-left: +var out = cuanyByRight( x, isPositive ); +console.log( out ); diff --git a/lib/node_modules/@stdlib/array/base/cuany-by-right/lib/assign.js b/lib/node_modules/@stdlib/array/base/cuany-by-right/lib/assign.js new file mode 100644 index 00000000000..3dcab01c4a3 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cuany-by-right/lib/assign.js @@ -0,0 +1,171 @@ +/** +* @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 arraylike2object = require( '@stdlib/array/base/arraylike2object' ); + + +// FUNCTIONS // + +/** +* Cumulatively tests whether at least one array element in a provided array passes a test implemented by a predicate function, while iterating from right-to-left, and assigns the results to elements in the provided output array. +* +* @private +* @param {Collection} x - input array +* @param {Collection} y - output array +* @param {integer} stride - output array stride +* @param {NonNegativeInteger} offset - output array offset +* @param {Function} predicate - test function +* @param {*} thisArg - execution context +* @returns {Collection} output array +* +* @example +* function isPositive( value ) { +* return ( value > 0 ); +* } +* +* var x = [ 0, 1, 0, 0, 0 ]; +* +* var out = [ false, false, false, false, false ]; +* var y = indexed( x, out, 1, 0, isPositive ); +* // returns [ false, false, false, true, true ] +*/ +function indexed( x, y, stride, offset, predicate, thisArg ) { + var flg; + var io; + var i; + + flg = false; + io = offset; + for ( i = x.length - 1; i >= 0; i-- ) { + if ( !flg && predicate.call( thisArg, x[ i ], i, x ) ) { + flg = true; + } + y[ io ] = flg; + io += stride; + } + return y; +} + +/** +* Cumulatively tests whether at least one array element in a provided array passes a test implemented by a predicate function, while iterating from right-to-left, and assigns the results to elements in the accessor output array. +* +* @private +* @param {Object} x - input array object +* @param {Object} y - output array object +* @param {integer} stride - output array stride +* @param {NonNegativeInteger} offset - output array offset +* @param {Function} predicate - test function +* @param {*} thisArg - execution context +* @returns {Collection} output array +* +* @example +* function isPositive( value ) { +* return ( value > 0 ); +* } +* +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +* +* var x = toAccessorArray( [ 0, 1, 0, 0, 0 ] ); +* +* var out = toAccessorArray( [ false, false, false, false, false ] ); +* var y = accessors( arraylike2object( x ), arraylike2object( out ), 1, 0, isPositive ); +* +* var v = out.get( 4 ); +* // returns true +*/ +function accessors( x, y, stride, offset, predicate, thisArg ) { + var xdata; + var ydata; + var xget; + var yset; + var flg; + var io; + var i; + + xdata = x.data; + ydata = y.data; + + xget = x.accessors[ 0 ]; + yset = y.accessors[ 1 ]; + + flg = false; + io = offset; + for ( i = xdata.length - 1; i >= 0; i-- ) { + if ( !flg && predicate.call( thisArg, xget( xdata, i ), i, x ) ) { + flg = true; + } + yset( ydata, io, flg ); + io += stride; + } + return ydata; +} + + +// MAIN // + +/** +* Cumulatively tests whether at least one array element in a provided array passes a test implemented by a predicate function, while iterating from right-to-left, and assigns the results to elements in the output array. +* +* @param {Collection} x - input array +* @param {Collection} out - output array +* @param {integer} stride - output array stride +* @param {NonNegativeInteger} offset - output array offset +* @param {Function} predicate - test function +* @param {*} [thisArg] - execution context +* @returns {Collection} output array +* +* @example +* function isPositive( value ) { +* return ( value > 0 ); +* } +* +* var x = [ 0, 1, 0, 0 ]; +* +* var y = [ false, null, false, null, false, null, false, null ]; +* var out = assign( x, y, 2, 0, isPositive ); +* // returns [ false, null, ..., true, null ] +* +* var bool = ( y === out ); +* // returns true +*/ +function assign( x, out, stride, offset, predicate, thisArg ) { + var xo; + var oo; + + xo = arraylike2object( x ); + oo = arraylike2object( out ); + if ( + xo.accessorProtocol || + oo.accessorProtocol + ) { + accessors( xo, oo, stride, offset, predicate, thisArg ); + return out; + } + indexed( x, out, stride, offset, predicate, thisArg ); + return out; +} + + +// EXPORTS // + +module.exports = assign; diff --git a/lib/node_modules/@stdlib/array/base/cuany-by-right/lib/index.js b/lib/node_modules/@stdlib/array/base/cuany-by-right/lib/index.js new file mode 100644 index 00000000000..e7108cf8493 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cuany-by-right/lib/index.js @@ -0,0 +1,72 @@ +/** +* @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'; + +/** +* Cumulatively test whether at least one array element in a provided array passes a test implemented by a predicate function, while iterating from right-to-left. +* +* @module @stdlib/array/base/cuany-by-right +* +* @example +* var cuanyByRight = require( '@stdlib/array/base/cuany-by-right' ); +* +* function isPositive( value ) { +* return ( value > 0 ); +* } +* +* var x = [ 0, 1, 0, 0, 0 ]; +* +* var y = cuanyByRight( x, isPositive ); +* // returns [ false, false, false, true, true ] +* +* @example +* var cuanyByRight = require( '@stdlib/array/base/cuany-by-right' ); +* +* function isPositive( value ) { +* return ( value > 0 ); +* } +* +* var x = [ 0, 1, 0, 0, 0 ]; +* +* var y1 = cuanyByRight( x, isPositive ); +* // returns [ false, false, false, true, true ] +* +* var y2 = [ false, null, false, null, false, null, false, null, false, null ]; +* var out = cuanyByRight.assign( x, y2, 2, 0, isPositive ); +* // returns [ false, null, false, null, false, null, true, null, true, null ] +* +* var bool = ( out === y2 ); +* // returns true +*/ + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var main = require( './main.js' ); +var assign = require( './assign.js' ); + + +// MAIN // + +setReadOnly( main, 'assign', assign ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/array/base/cuany-by-right/lib/main.js b/lib/node_modules/@stdlib/array/base/cuany-by-right/lib/main.js new file mode 100644 index 00000000000..a4f7e4c87bb --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cuany-by-right/lib/main.js @@ -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. +*/ + +'use strict'; + +// MODULES // + +var filled = require( '@stdlib/array/base/filled' ); +var assign = require( './assign.js' ); + + +// MAIN // + +/** +* Cumulatively tests whether at least one array element in a provided array passes a test implemented by a predicate function, while iterating from right-to-left. +* +* @param {Collection} x - input array +* @param {Function} predicate - test function +* @param {*} [thisArg] - execution context +* @returns {Array} output array +* +* @example +* function isPositive( value ) { +* return ( value > 0 ); +* } +* +* var x = [ 0, 1, 0, 0, 0 ]; +* +* var y = cuanyByRight( x, isPositive ); +* // returns [ false, false, false, true, true ] +*/ +function cuanyByRight( x, predicate, thisArg ) { + var out = filled( false, x.length ); + return assign( x, out, 1, 0, predicate, thisArg ); +} + + +// EXPORTS // + +module.exports = cuanyByRight; diff --git a/lib/node_modules/@stdlib/array/base/cuany-by-right/package.json b/lib/node_modules/@stdlib/array/base/cuany-by-right/package.json new file mode 100644 index 00000000000..b9ae4cf3a6f --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cuany-by-right/package.json @@ -0,0 +1,68 @@ +{ + "name": "@stdlib/array/base/cuany-by-right", + "version": "0.0.0", + "description": "Cumulatively test whether at least one array element in a provided array passes a test implemented by a predicate function, while iterating from right-to-left.", + "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", + "stdtypes", + "utils", + "generic", + "array", + "cumulative", + "data", + "structure", + "test", + "predicate", + "any", + "some", + "array.some", + "array-like", + "validate" + ] +} diff --git a/lib/node_modules/@stdlib/array/base/cuany-by-right/test/test.assign.js b/lib/node_modules/@stdlib/array/base/cuany-by-right/test/test.assign.js new file mode 100644 index 00000000000..664af9ce086 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cuany-by-right/test/test.assign.js @@ -0,0 +1,247 @@ +/** +* @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 Float64Array = require( '@stdlib/array/float64' ); +var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var cuanyByRight = require( './../lib/assign.js' ); + + +// FUNCTIONS // + +function isPositive( v ) { + return v > 0; +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof cuanyByRight, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function cumulatively tests whether at least one array element in a provided array passes a test implemented by a predicate function, while iterating from right-to-left, and assigns the results to a provided output array (generic)', function test( t ) { + var expected; + var actual; + var x; + var y; + + x = [ 0, 0, 1, 1, 0 ]; + y = [ false, true, false, true, false ]; + + actual = cuanyByRight( x, y, 1, 0, isPositive ); + expected = [ false, true, true, true, true ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = [ 1, 1, 0, 0 ]; + y = [ false, null, false, null, false, null, false, null ]; + + actual = cuanyByRight( x, y, 2, 0, isPositive ); + expected = [ false, null, false, null, true, null, true, null ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = [ 1, 1, 0, 0, 0 ]; + y = [ true, false, false, true, true, true ]; + + actual = cuanyByRight( x, y, 1, 1, isPositive ); + expected = [ true, false, false, false, true, true ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = []; + y = [ false, false, false, false, false ]; + + actual = cuanyByRight( x, y, 1, 0, isPositive ); + expected = [ false, false, false, false, false ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = [ 0 ]; + y = [ false, false ]; + + actual = cuanyByRight( x, y, 1, 1, isPositive ); + expected = [ false, false ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function cumulatively tests whether at least one array element in a provided array passes a test implemented by a predicate function, while iterating from right-to-left, and assigns the results to a provided output array (typed)', function test( t ) { + var expected; + var actual; + var x; + var y; + + x = new Float64Array( [ 1.0, 0.0, 1.0, 0.0, 0.0 ] ); + y = [ false, true, false, true, false ]; + + actual = cuanyByRight( x, y, 1, 0, isPositive ); + expected = [ false, false, true, true, true ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Float64Array( [ 1.0, 1.0, 0.0, 0.0 ] ); + y = [ false, null, false, null, false, null, false, null ]; + + actual = cuanyByRight( x, y, 2, 0, isPositive ); + expected = [ false, null, false, null, true, null, true, null ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Float64Array( [ 0.0, 1.0, 1.0, 0.0, 0.0 ] ); + y = [ true, false, false, true, true, true ]; + + actual = cuanyByRight( x, y, 1, 1, isPositive ); + expected = [ true, false, false, true, true, true ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Float64Array( [] ); + y = [ false, false, false, false, false ]; + + actual = cuanyByRight( x, y, 1, 0, isPositive ); + expected = [ false, false, false, false, false ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Float64Array( [ 0.0 ] ); + y = [ false, false ]; + + actual = cuanyByRight( x, y, 1, 1, isPositive ); + expected = [ false, false ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function cumulatively tests whether at least one array element in a provided array passes a test implemented by a predicate function, while iterating from right-to-left, and assigns the results to a provided output array (accessor)', function test( t ) { + var expected; + var actual; + var ybuf; + var x; + var y; + + x = toAccessorArray( [ 1, 0, 0, 0, 0 ] ); + ybuf = [ false, true, false, true, false ]; + y = toAccessorArray( ybuf ); + + actual = cuanyByRight( x, y, 1, 0, isPositive ); + expected = [ false, false, false, false, true ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ybuf, expected, 'returns expected value' ); + + x = toAccessorArray( [ 0, 1, 1, 0 ] ); + ybuf = [ false, null, false, null, false, null, false, null ]; + y = toAccessorArray( ybuf ); + + actual = cuanyByRight( x, y, 2, 0, isPositive ); + expected = [ false, null, true, null, true, null, true, null ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ybuf, expected, 'returns expected value' ); + + x = toAccessorArray( [ 0, 1, 1, 0, 0 ] ); + ybuf = [ true, false, false, false, false, false ]; + y = toAccessorArray( ybuf ); + + actual = cuanyByRight( x, y, 1, 1, isPositive ); + expected = [ true, false, false, true, true, true ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ybuf, expected, 'returns expected value' ); + + x = toAccessorArray( [ 0, 0, 0, 0, 1 ] ); + ybuf = [ true, true, true, true, true ]; + y = toAccessorArray( ybuf ); + + actual = cuanyByRight( x, y, 1, 0, isPositive ); + expected = [ true, true, true, true, true ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ybuf, expected, 'returns expected value' ); + + x = toAccessorArray( [] ); + ybuf = [ false, false, false, false, false ]; + y = toAccessorArray( ybuf ); + + actual = cuanyByRight( x, y, 1, 0, isPositive ); + expected = [ false, false, false, false, false ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ybuf, expected, 'returns expected value' ); + + x = toAccessorArray( [ 0 ] ); + ybuf = [ false, false ]; + y = toAccessorArray( ybuf ); + + actual = cuanyByRight( x, y, 1, 1, isPositive ); + expected = [ false, false ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ybuf, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing an execution context', function test( t ) { + var expected; + var actual; + var ctx; + var x; + var y; + + ctx = { + 'count': 0 + }; + + x = [ 0, 1, 0, 0, 0 ]; + y = [ false, null, false, null, false, null, false, null, false, null ]; + + actual = cuanyByRight( x, y, 2, 0, predicate, ctx ); + expected = [ false, null, false, null, false, null, true, null, true, null ]; + + t.deepEqual( actual, expected, 'returns expected value' ); + t.strictEqual( ctx.count, 4, 'returns expected value' ); + t.end(); + + function predicate( v ) { + this.count += 1; // eslint-disable-line no-invalid-this + return ( v > 0 ); + } +}); diff --git a/lib/node_modules/@stdlib/array/base/cuany-by-right/test/test.js b/lib/node_modules/@stdlib/array/base/cuany-by-right/test/test.js new file mode 100644 index 00000000000..6a65e1ab20c --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cuany-by-right/test/test.js @@ -0,0 +1,41 @@ +/** +* @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 hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var hasMethod = require( '@stdlib/assert/is-method' ); +var cuanyByRight = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof cuanyByRight, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is an `assign` method', function test( t ) { + t.strictEqual( hasOwnProp( cuanyByRight, 'assign' ), true, 'returns expected value' ); + t.strictEqual( hasMethod( cuanyByRight, 'assign' ), true, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/array/base/cuany-by-right/test/test.main.js b/lib/node_modules/@stdlib/array/base/cuany-by-right/test/test.main.js new file mode 100644 index 00000000000..8ee001ff5a2 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cuany-by-right/test/test.main.js @@ -0,0 +1,161 @@ +/** +* @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 Float64Array = require( '@stdlib/array/float64' ); +var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var cuanyByRight = require( './../lib' ); + + +// FUNCTIONS // + +function isPositive( v ) { + return v > 0; +} + +function isNotNull( v ) { + return v !== null; +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof cuanyByRight, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function cumulatively tests whether at least one array element in a provided array passes a test implemented by a predicate function, while iterating from right-to-left (generic)', function test( t ) { + var expected; + var actual; + var x; + + x = [ 1, 1, 0, 0, 0 ]; + + actual = cuanyByRight( x, isPositive ); + expected = [ false, false, false, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = [ 0.0, 0.0, 0.0, 1.0, 1.0 ]; + actual = cuanyByRight( x, isPositive ); + expected = [ true, true, true, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = [ {}, {}, null ]; + actual = cuanyByRight( x, isNotNull ); + expected = [ false, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function cumulatively tests whether at least one array element in a provided array passes a test implemented by a predicate function, while iterating from right-to-left (typed)', function test( t ) { + var expected; + var actual; + var x; + + x = new Float64Array( [ 0.0, 0.0, 1.0, 1.0, 0.0 ] ); + actual = cuanyByRight( x, isPositive ); + expected = [ false, true, true, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + actual = cuanyByRight( x, isPositive ); + expected = [ false, false, false, false, false ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ); + actual = cuanyByRight( x, isPositive ); + expected = [ true, true, true, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Float64Array( [ 0.0, 1.0, 0.0 ] ); + actual = cuanyByRight( x, isPositive ); + expected = [ false, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Float64Array( [ 0.0, 1.0, 0.0, 0.0, 0.0 ] ); + actual = cuanyByRight( x, isPositive ); + expected = [ false, false, false, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function cumulatively tests whether at least one array element in a provided array passes a test implemented by a predicate function, while iterating from right-to-left (accessor)', function test( t ) { + var expected; + var actual; + var x; + + x = toAccessorArray( [ 1, 1, 0, 0, 0 ] ); + + actual = cuanyByRight( x, isPositive ); + expected = [ false, false, false, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = toAccessorArray( [ 0, 0, 0, 0, 0 ] ); + actual = cuanyByRight( x, isPositive ); + expected = [ false, false, false, false, false ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = toAccessorArray( [ 1, 1, 1, 1, 1 ] ); + actual = cuanyByRight( x, isPositive ); + expected = [ true, true, true, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = toAccessorArray( [ 0, 0, 1 ] ); + actual = cuanyByRight( x, isPositive ); + expected = [ true, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = toAccessorArray( [ 1, 0, 0, 0, 0 ] ); + actual = cuanyByRight( x, isPositive ); + expected = [ false, false, false, false, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports providing an execution context', function test( t ) { + var expected; + var out; + var ctx; + var x; + + ctx = { + 'count': 0 + }; + + x = [ 1, -2, 0, -1 ]; + + out = cuanyByRight( x, predicate, ctx ); + expected = [ false, false, false, true ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.strictEqual( ctx.count, 4, 'returns expected value' ); + t.end(); + + function predicate( v ) { + this.count += 1; // eslint-disable-line no-invalid-this + return ( v > 0 ); + } +}); diff --git a/lib/node_modules/@stdlib/array/base/cuany-by/README.md b/lib/node_modules/@stdlib/array/base/cuany-by/README.md new file mode 100644 index 00000000000..ab16c9d682d --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cuany-by/README.md @@ -0,0 +1,153 @@ + + +# cuanyBy + +> Cumulatively test whether at least one element in a provided array passes a test implemented by a predicate function. + +
+ +## Usage + +```javascript +var cuanyBy = require( '@stdlib/array/base/cuany-by' ); +``` + +#### cuanyBy( x, predicate\[, thisArg] ) + +Cumulatively tests whether at least one element in a provided array passes a test implemented by a `predicate` function. + +```javascript +function isPositive( value ) { + return ( value > 0 ); +} + +var x = [ 0, 0, 0, 1, 0 ]; + +var y = cuanyBy( x, isPositive ); +// returns [ false, false, false, true, true ] +``` + +The `predicate` function is provided three arguments: + +- **value**: current array element. +- **index**: current array element index. +- **arr**: input array. + +To set the `predicate` function execution context, provide a `thisArg`. + +```javascript +function isPositive( value ) { + this.count += 1; + return ( value > 0 ); +} + +var x = [ 0, 0, 0, 1, 0 ]; + +var context = { + 'count': 0 +}; + +var out = cuanyBy( x, isPositive, context ); +// returns [ false, false, false, true, true ] + +var cnt = context.count; +// returns 4 +``` + +#### cuanyBy.assign( x, out, stride, offset, predicate\[, thisArg] ) + +Cumulatively tests whether at least one element in a provided array passes a test implemented by a `predicate` function and assigns results to a provided output array. + +```javascript +function isPositive( value ) { + return ( value > 0 ); +} + +var x = [ 0, 0, 0, 1, 0 ]; +var y = [ false, null, false, null, false, null, false, null, false, null ]; + +var out = cuanyBy.assign( x, y, 2, 0, isPositive ); +// returns [ false, null, false, null, false, null, true, null, true, null ] + +var bool = ( out === y ); +// returns true +``` + +The function supports the following parameters: + +- **x**: input array. +- **out**: output array. +- **stride**: output array stride. +- **offset**: output array offset. +- **predicate**: test function. + +
+ + + +
+ +
+ + + +
+ +## Examples + + + +```javascript +var bernoulli = require( '@stdlib/random/array/bernoulli' ); +var cuanyBy = require( '@stdlib/array/base/cuany-by' ); + +function isPositive( value ) { + return ( value > 0 ); +} + +// Create an array of random values: +var x = bernoulli( 10, 0.1 ); +console.log( x ); + +var out = cuanyBy( x, isPositive ); +console.log( out ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/array/base/cuany-by/benchmark/benchmark.assign.length.js b/lib/node_modules/@stdlib/array/base/cuany-by/benchmark/benchmark.assign.length.js new file mode 100644 index 00000000000..7b4212c0178 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cuany-by/benchmark/benchmark.assign.length.js @@ -0,0 +1,99 @@ +/** +* @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 pow = require( '@stdlib/math/base/special/pow' ); +var isArray = require( '@stdlib/assert/is-array' ); +var filled = require( '@stdlib/array/base/filled' ); +var isPositiveInteger = require( '@stdlib/assert/is-positive-integer' ).isPrimitive; +var pkg = require( './../package.json' ).name; +var cuanyBy = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = filled( 0, len ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var y; + var v; + var i; + + y = filled( false, len ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = cuanyBy.assign( x, y, 1, 0, isPositiveInteger ); + if ( typeof v !== 'object' ) { + b.fail( 'should return an array' ); + } + } + b.toc(); + if ( !isArray( v ) ) { + b.fail( 'should return an array' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':assign:len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/base/cuany-by/benchmark/benchmark.js b/lib/node_modules/@stdlib/array/base/cuany-by/benchmark/benchmark.js new file mode 100644 index 00000000000..424e55a3848 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cuany-by/benchmark/benchmark.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'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isArray = require( '@stdlib/assert/is-array' ); +var isPositiveInteger = require( '@stdlib/assert/is-positive-integer' ).isPrimitive; +var pkg = require( './../package.json' ).name; +var cuanyBy = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var x; + var i; + var v; + + x = [ 0, 0, 1, 0, 1 ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = cuanyBy( x, isPositiveInteger ); + if ( typeof v !== 'object' ) { + b.fail( 'should return an array' ); + } + } + b.toc(); + if ( !isArray( v ) ) { + b.fail( 'should return an array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/base/cuany-by/benchmark/benchmark.length.js b/lib/node_modules/@stdlib/array/base/cuany-by/benchmark/benchmark.length.js new file mode 100644 index 00000000000..309b829701c --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cuany-by/benchmark/benchmark.length.js @@ -0,0 +1,96 @@ +/** +* @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 pow = require( '@stdlib/math/base/special/pow' ); +var isArray = require( '@stdlib/assert/is-array' ); +var filled = require( '@stdlib/array/base/filled' ); +var isPositiveInteger = require( '@stdlib/assert/is-positive-integer' ).isPrimitive; +var pkg = require( '@stdlib/array/base/cuany-by/package.json' ).name; +var cuanyBy = require( '@stdlib/array/base/cuany-by/lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = filled( 1.5, len ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = cuanyBy( x, isPositiveInteger ); + if ( typeof v !== 'object' ) { + b.fail( 'should return an array' ); + } + } + b.toc(); + if ( !isArray( v ) ) { + b.fail( 'should return an array' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/base/cuany-by/docs/repl.txt b/lib/node_modules/@stdlib/array/base/cuany-by/docs/repl.txt new file mode 100644 index 00000000000..4b8a14267f0 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cuany-by/docs/repl.txt @@ -0,0 +1,73 @@ + +{{alias}}( x, predicate[, thisArg] ) + Cumulatively tests whether at least one element in a provided array + passes a test implemented by a predicate function. + + The predicate function is provided three arguments: + + - value: current array element. + - index: current array element index. + - arr: the input array. + + Parameters + ---------- + x: ArrayLikeObject + Input array. + + predicate: Function + Predicate function. + + thisArg: any (optional) + Execution context. + + Returns + ------- + out: Array + Output array. + + Examples + -------- + > function f( v ) { return ( v > 0 ); }; + > var x = [ 0, 0, 0, 1, 0 ]; + > var out = {{alias}}( x, f ) + [ false, false, false, true, true ] + + +{{alias}}.assign( x, y, stride, offset, predicate[, thisArg] ) + Cumulatively tests whether at least one element in a provided array + passes a test implemented by a predicate function and assigns results + to a provided output array. + + Parameters + ---------- + x: ArrayLikeObject + Input array. + + y: ArrayLikeObject + Output array. + + stride: integer + Output array stride. + + offset: integer + Output array offset. + + predicate: Function + Predicate function. + + Returns + ------- + y: ArrayLikeObject + Output array. + + Examples + -------- + > function f( v ) { return ( v > 0 ); }; + > var x = [ 0, 0, 0, 1, 0 ]; + > var y = [ false, null, false, null, false, null, false, null, false ]; + > var result = {{alias}}.assign( x, y, 2, 0, f ) + [ false, null, false, null, false, null, true, null, true ] + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/array/base/cuany-by/docs/types/index.d.ts b/lib/node_modules/@stdlib/array/base/cuany-by/docs/types/index.d.ts new file mode 100644 index 00000000000..f0125a1a0a2 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cuany-by/docs/types/index.d.ts @@ -0,0 +1,202 @@ +/* +* @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 { Collection, AccessorArrayLike, TypedArray, BooleanArray } from '@stdlib/types/array'; + +/** +* Returns a boolean indicating whether an element passes a test. +* +* @returns boolean indicating whether an element passes a test +*/ +type Nullary = ( this: U ) => boolean; + +/** +* Returns a boolean indicating whether an element passes a test. +* +* @param value - current array element +* @returns boolean indicating whether an element passes a test +*/ +type Unary = ( this: U, value: T ) => boolean; + +/** +* Returns a boolean indicating whether an element passes a test. +* +* @param value - current array element +* @param index - current array element index +* @returns boolean indicating whether an element passes a test +*/ +type Binary = ( this: U, value: T, index: number ) => boolean; + +/** +* Returns a boolean indicating whether an element passes a test. +* +* @param value - current array element +* @param index - current array element index +* @param arr - input array +* @returns boolean indicating whether an element passes a test +*/ +type Ternary = ( this: U, value: T, index: number, arr: Collection | AccessorArrayLike ) => boolean; + +/** +* Returns a boolean indicating whether an element passes a test. +* +* @param value - current array element +* @param index - current array element index +* @param arr - input array +* @returns boolean indicating whether an element passes a test +*/ +type Predicate = Nullary | Unary | Binary | Ternary; + +/** +* Interface describing `cunanyBy`. +*/ +interface CuAnyBy { + /** + * Cumulatively tests whether at least one element in a provided array passes a test implemented by a predicate function. + * + * @param x - input array + * @param predicate - predicate function + * @param thisArg - predicate function execution context + * @returns output array + * + * @example + * function isPositive( v ) { + * return v > 0; + * } + * + * var x = [ 0, 0, 0, 1, 0 ]; + * + * var y = cuanyBy( x, isPositive ); + * // returns [ false, false, false, true, true ]; + */ + ( x: Collection | AccessorArrayLike, predicate: Predicate, thisArg?: ThisParameterType> ): Array; + + /** + * Cumulatively tests whether at least one element in a provided array passes a test implemented by a predicate function and assigns the results to a provided output array. + * + * @param x - input array + * @param y - output array + * @param stride - output array stride + * @param offset - output array offset + * @param predicate - predicate function + * @param thisArg - predicate function execution context + * @returns output array + * + * @example + * function isPositive( v ) { + * return v > 0; + * } + * + * var x = [ 0, 0, 0, 1, 0 ]; + * var y = [ false, null, false, null, false, null, true, null, true, null ]; + * + * var arr = cuanyBy.assign( x, y, 2, 0, isPositive );, + * // returns [ false, null, false, null, false, null, true, null, true, null ]; + */ + assign( x: Collection | AccessorArrayLike, out: Array, stride: number, offset: number, predicate: Predicate, thisArg?: ThisParameterType> ): Array; + + /** + * Cumulatively tests whether at least one array element in a provided array passes a test implemented by a predicate function and assigns the results to the provided output array. + * + * @param x - input array + * @param out - output array + * @param stride - output array stride + * @param offset - output array offset + * @param predicate - test function + * @param thisArg - execution context + * @returns output array + * + * @example + * var BooleanArray = require( '@stdlib/array/bool' ); + * + * function isPositive( v ) { + * return ( v > 0 ); + * } + * var x = [ 0, 1, 0, 1, 0 ]; + * var y = new BooleanArray( [ false, false, false, false, false, false, false, false, false, false ] ); + * + * var arr = cuanyBy.assign( x, y, 2, 0, isPositive ); + * // returns + * + * var v = arr.get( 4 ); + * // returns true + */ + assign( x: Collection | AccessorArrayLike, out: U, stride: number, offset: number, predicate: Predicate, thisArg?: ThisParameterType> ): U; + + /** + * Cumulatively tests whether at least one element in a provided array passes a test implemented by a predicate function and assigns the results to a provided output array. + * + * @param x - input array + * @param y - output array + * @param stride - output array stride + * @param offset - output array offset + * @param predicate - predicate function + * @param thisArg - predicate function execution context + * @returns output array + * + * @example + * function isPositive( v ) { + * return v > 0; + * } + * + * var x = [ 0, 0, 0, 1, 0 ]; + * var y = [ false, null, false, null, false, null, true, null, true, null ]; + * + * var arr = cuanyBy.assign( x, y, 2, 0, isPositive );, + * // returns [ false, null, false, null, false, null, true, null, true, null ]; + */ + assign( x: Collection | AccessorArrayLike, out: Collection | AccessorArrayLike, stride: number, offset: number, predicate: Predicate, thisArg?: ThisParameterType> ): Collection | AccessorArrayLike; +} + +/** +* Cumulatively tests whether at least one element in a provided array passes a test implemented by a predicate function. +* +* @param x - input array +* @returns output array +* +* @example +* function isPositive( value ) { +* return ( value > 0 ); +* } +* +* var x = [ 0, 0, 0, 1, 0 ]; +* +* var y = cuanyBy( x, isPositive ); +* // returns [ false, false, false, true, true ] +* +* @example +* function isPositive( value ) { +* return ( value > 0 ); +* } +* +* var x = [ 0, 0, 0, 1, 0 ]; +* var y = [ false, null, false, null, false, null, false, null, false, null ]; +* +* var arr = cuanyBy.assign( x, y, 2, 0, isPositive ); +* // returns [ false, null, false, null, false, null, true, null, true, null ] +*/ +declare var cuanyBy: CuAnyBy; + + +// EXPORTS // + +export = cuanyBy; diff --git a/lib/node_modules/@stdlib/array/base/cuany-by/docs/types/test.ts b/lib/node_modules/@stdlib/array/base/cuany-by/docs/types/test.ts new file mode 100644 index 00000000000..2c28990aae2 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cuany-by/docs/types/test.ts @@ -0,0 +1,219 @@ +/* +* @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 cuanyBy = require( './index' ); + +/** +* Tests whether a value is positive. +* +* @param value - input value +* @returns boolean indicating whether an element is positive +*/ +function isPositive( value: number ): boolean { + return ( value > 0 ); +} + + +// TESTS // + +// The function returns an array... +{ + cuanyBy( [ 1, 2, 3 ], isPositive ); // $ExpectType boolean[] + cuanyBy( new Float64Array( [ 1, 2, 3 ] ), isPositive ); // $ExpectType boolean[] + cuanyBy( new Float32Array( [ 1, 2, 3 ] ), isPositive ); // $ExpectType boolean[] + cuanyBy( new Int32Array( [ 1, 2, 3 ] ), isPositive ); // $ExpectType boolean[] + cuanyBy( new Int16Array( [ 1, 2, 3 ] ), isPositive ); // $ExpectType boolean[] + cuanyBy( new Int8Array( [ 1, 2, 3 ] ), isPositive ); // $ExpectType boolean[] + cuanyBy( new Uint32Array( [ 1, 2, 3 ] ), isPositive ); // $ExpectType boolean[] + cuanyBy( new Uint16Array( [ 1, 2, 3 ] ), isPositive ); // $ExpectType boolean[] + cuanyBy( new Uint8Array( [ 1, 2, 3 ] ), isPositive ); // $ExpectType boolean[] + cuanyBy( new Uint8ClampedArray( [ 1, 2, 3 ] ), isPositive ); // $ExpectType boolean[] + + cuanyBy( [ 1, 2, 3 ], isPositive, {} ); // $ExpectType boolean[] + cuanyBy( new Float64Array( [ 1, 2, 3 ] ), isPositive, {} ); // $ExpectType boolean[] + cuanyBy( new Float32Array( [ 1, 2, 3 ] ), isPositive, {} ); // $ExpectType boolean[] + cuanyBy( new Int32Array( [ 1, 2, 3 ] ), isPositive, {} ); // $ExpectType boolean[] + cuanyBy( new Int16Array( [ 1, 2, 3 ] ), isPositive, {} ); // $ExpectType boolean[] + cuanyBy( new Int8Array( [ 1, 2, 3 ] ), isPositive, {} ); // $ExpectType boolean[] + cuanyBy( new Uint32Array( [ 1, 2, 3 ] ), isPositive, {} ); // $ExpectType boolean[] + cuanyBy( new Uint16Array( [ 1, 2, 3 ] ), isPositive, {} ); // $ExpectType boolean[] + cuanyBy( new Uint8Array( [ 1, 2, 3 ] ), isPositive, {} ); // $ExpectType boolean[] + cuanyBy( new Uint8ClampedArray( [ 1, 2, 3 ] ), isPositive, {} ); // $ExpectType boolean[] +} + +// The compiler throws an error if the function is provided a first argument which is not like a function.. +{ + const x = [ 1, 2, 3, 4 ]; + + cuanyBy( x, null ); // $ExpectError + cuanyBy( x, {} ); // $ExpectError + cuanyBy( x, [] ); // $ExpectError + cuanyBy( x, '' ); // $ExpectError + cuanyBy( x, undefined ); // $ExpectError + + cuanyBy( x, null, {} ); // $ExpectError + cuanyBy( x, {}, {} ); // $ExpectError + cuanyBy( x, [], {} ); // $ExpectError + cuanyBy( x, '', {} ); // $ExpectError + cuanyBy( x, undefined, {} ); // $ExpectError + +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + cuanyBy(); // $ExpectError + cuanyBy( [] ); // $ExpectError + cuanyBy( [ 1, 2 ], isPositive, {}, '' ); // $ExpectError +} + +// Attached to the main export is an `assign` method which returns a collection... +{ + const x = [ 0, 0, 0, 1, 0 ]; + const y = [ false, null, false, null, false, null, false, null, false, null ]; + + cuanyBy.assign( x, y, 2, 0, isPositive ); // $ExpectType (boolean | null)[] + cuanyBy.assign( x, y, 2, 0, isPositive, {} ); // $ExpectType (boolean | null)[] + cuanyBy.assign( x, new Float64Array( 4 ), 1, 0, isPositive ); // $ExpectType Float64Array + cuanyBy.assign( x, new Float32Array( 4 ), 1, 0, isPositive ); // $ExpectType Float32Array + cuanyBy.assign( x, new Int32Array( 4 ), 1, 0, isPositive ); // $ExpectType Int32Array + cuanyBy.assign( x, new Int16Array( 4 ), 1, 0, isPositive ); // $ExpectType Int16Array + cuanyBy.assign( x, new Int8Array( 4 ), 1, 0, isPositive ); // $ExpectType Int8Array + cuanyBy.assign( x, new Uint32Array( 4 ), 1, 0, isPositive ); // $ExpectType Uint32Array + cuanyBy.assign( x, new Uint16Array( 4 ), 1, 0, isPositive ); // $ExpectType Uint16Array + cuanyBy.assign( x, new Uint8Array( 4 ), 1, 0, isPositive ); // $ExpectType Uint8Array + cuanyBy.assign( x, new Uint8ClampedArray( 4 ), 1, 0, isPositive ); // $ExpectType Uint8ClampedArray + + cuanyBy.assign( x, [ 0, 0, 0, 0 ], 1, 0, isPositive, {} ); // $ExpectType (number | boolean)[] + cuanyBy.assign( x, new Float64Array( 4 ), 1, 0, isPositive, {} ); // $ExpectType Float64Array + cuanyBy.assign( x, new Float32Array( 4 ), 1, 0, isPositive, {} ); // $ExpectType Float32Array + cuanyBy.assign( x, new Int32Array( 4 ), 1, 0, isPositive, {} ); // $ExpectType Int32Array + cuanyBy.assign( x, new Int16Array( 4 ), 1, 0, isPositive, {} ); // $ExpectType Int16Array + cuanyBy.assign( x, new Int8Array( 4 ), 1, 0, isPositive, {} ); // $ExpectType Int8Array + cuanyBy.assign( x, new Uint32Array( 4 ), 1, 0, isPositive, {} ); // $ExpectType Uint32Array + cuanyBy.assign( x, new Uint16Array( 4 ), 1, 0, isPositive, {} ); // $ExpectType Uint16Array + cuanyBy.assign( x, new Uint8Array( 4 ), 1, 0, isPositive, {} ); // $ExpectType Uint8Array + cuanyBy.assign( x, new Uint8ClampedArray( 4 ), 1, 0, isPositive, {} ); // $ExpectType Uint8ClampedArray +} + +// The compiler throws an error if the `assign` method is provided a first argument which is not an array-like object... +{ + const x = [ false, false, true, false, false ]; + + cuanyBy.assign( 1, x, 2, 0, isPositive ); // $ExpectError + cuanyBy.assign( true, x, 2, 0, isPositive ); // $ExpectError + cuanyBy.assign( false, x, 2, 0, isPositive ); // $ExpectError + cuanyBy.assign( null, x, 2, 0, isPositive ); // $ExpectError + cuanyBy.assign( void 0, x, 2, 0, isPositive ); // $ExpectError + cuanyBy.assign( {}, x, 2, 0, isPositive ); // $ExpectError + + cuanyBy.assign( 1, x, 2, 0, isPositive, {} ); // $ExpectError + cuanyBy.assign( true, x, 2, 0, isPositive, {} ); // $ExpectError + cuanyBy.assign( false, x, 2, 0, isPositive, {} ); // $ExpectError + cuanyBy.assign( null, x, 2, 0, isPositive, {} ); // $ExpectError + cuanyBy.assign( void 0, x, 2, 0, isPositive, {} ); // $ExpectError + cuanyBy.assign( {}, x, 2, 0, isPositive, {} ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a second argument which is not an array-like object... +{ + const x = [ false, false, true, false, false ]; + + cuanyBy.assign( x, 1, 2, 0, isPositive ); // $ExpectError + cuanyBy.assign( x, true, 2, 0, isPositive ); // $ExpectError + cuanyBy.assign( x, false, 2, 0, isPositive ); // $ExpectError + cuanyBy.assign( x, null, 2, 0, isPositive ); // $ExpectError + cuanyBy.assign( x, void 0, 2, 0, isPositive ); // $ExpectError + cuanyBy.assign( x, {}, 2, 0, isPositive ); // $ExpectError + + cuanyBy.assign( x, 1, 2, 0, isPositive, {} ); // $ExpectError + cuanyBy.assign( x, true, 2, 0, isPositive, {} ); // $ExpectError + cuanyBy.assign( x, false, 2, 0, isPositive, {} ); // $ExpectError + cuanyBy.assign( x, null, 2, 0, isPositive, {} ); // $ExpectError + cuanyBy.assign( x, void 0, 2, 0, isPositive, {} ); // $ExpectError + cuanyBy.assign( x, {}, 2, 0, isPositive, {} ); // $ExpectError +} + + +// The compiler throws an error if the `assign` method is provided a third argument which is not a number... +{ + const x = [ false, false, true, false, false ]; + const y = [ false, null, false, null, false, null, false, null, false, null ]; + + cuanyBy.assign( x, y , '1', 0, isPositive ); // $ExpectError + cuanyBy.assign( x, y , true, 0, isPositive ); // $ExpectError + cuanyBy.assign( x, y , false, 0, isPositive ); // $ExpectError + cuanyBy.assign( x, y , null, 0, isPositive ); // $ExpectError + cuanyBy.assign( x, y , void 0, isPositive ); // $ExpectError + cuanyBy.assign( x, y , {}, 0, isPositive ); // $ExpectError + cuanyBy.assign( x, y , [], 0, isPositive ); // $ExpectError + + cuanyBy.assign( x, y , '1', 0, isPositive, {} ); // $ExpectError + cuanyBy.assign( x, y , true, 0, isPositive, {} ); // $ExpectError + cuanyBy.assign( x, y , false, 0, isPositive, {} ); // $ExpectError + cuanyBy.assign( x, y , null, 0, isPositive, {} ); // $ExpectError + cuanyBy.assign( x, y , void 0, isPositive, {} ); // $ExpectError + cuanyBy.assign( x, y , {}, 0, isPositive, {} ); // $ExpectError + cuanyBy.assign( x, y , [], 0, isPositive, {} ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a fourth argument which is not a number... +{ + const x = [ false, false, true, false, false ]; + const y = [ false, null, false, null, false, null, false, null, false, null ]; + + cuanyBy.assign( x, y, 1, '1', isPositive ); // $ExpectError + cuanyBy.assign( x, y, 1, true, isPositive ); // $ExpectError + cuanyBy.assign( x, y, 1, false, isPositive ); // $ExpectError + cuanyBy.assign( x, y, 1, null, isPositive ); // $ExpectError + cuanyBy.assign( x, y, 1, void 0, isPositive ); // $ExpectError + cuanyBy.assign( x, y, 1, {}, isPositive ); // $ExpectError + cuanyBy.assign( x, y, 1, [], isPositive ); // $ExpectError + + cuanyBy.assign( x, y, 1, '1', isPositive, {} ); // $ExpectError + cuanyBy.assign( x, y, 1, true, isPositive, {} ); // $ExpectError + cuanyBy.assign( x, y, 1, false, isPositive, {} ); // $ExpectError + cuanyBy.assign( x, y, 1, null, isPositive, {} ); // $ExpectError + cuanyBy.assign( x, y, 1, void 0, isPositive, {} ); // $ExpectError + cuanyBy.assign( x, y, 1, {}, isPositive, {} ); // $ExpectError + cuanyBy.assign( x, y, 1, [], isPositive, {} ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a fourth argument which is not like a function... +{ + const x = [ false, false, true, false, false ]; + const y = [ false, null, false, null, false, null, false, null, false, null ]; + + cuanyBy.assign( x, y, 1, 2, {} ); // $ExpectError + cuanyBy.assign( x, y, 1, 2, void 0 ); // $ExpectError + cuanyBy.assign( x, y, 1, 1, [] ); // $ExpectError + cuanyBy.assign( x, y, 1, 1, '' ); // $ExpectError + + cuanyBy.assign( x, y, 1, 2, {}, {} ); // $ExpectError + cuanyBy.assign( x, y, 1, 2, void 0, {} ); // $ExpectError + cuanyBy.assign( x, y, 1, 1, [], {} ); // $ExpectError + cuanyBy.assign( x, y, 1, 1, '', {} ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... +{ + cuanyBy.assign(); // $ExpectError + cuanyBy.assign( [] ); // $ExpectError + cuanyBy.assign( [], [] ); // $ExpectError + cuanyBy.assign( [], [], 2 ); // $ExpectError + cuanyBy.assign( [], [], 1, 1, isPositive, [], {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/array/base/cuany-by/examples/index.js b/lib/node_modules/@stdlib/array/base/cuany-by/examples/index.js new file mode 100644 index 00000000000..8c0cf648601 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cuany-by/examples/index.js @@ -0,0 +1,31 @@ +/** +* @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 bernoulli = require( '@stdlib/random/array/bernoulli' ); +var isPositiveInteger = require( '@stdlib/assert/is-positive-integer' ); +var cuanyBy = require( './../lib' ); + +// Create an array of random values: +var x = bernoulli( 10, 0.1 ); +console.log( x ); + +// Cumulatively determine whether values are truthy: +var out = cuanyBy( x, isPositiveInteger ); +console.log( out ); diff --git a/lib/node_modules/@stdlib/array/base/cuany-by/lib/assign.js b/lib/node_modules/@stdlib/array/base/cuany-by/lib/assign.js new file mode 100644 index 00000000000..ecc4e6b9083 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cuany-by/lib/assign.js @@ -0,0 +1,180 @@ +/** +* @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 arraylike2object = require( '@stdlib/array/base/arraylike2object' ); + + +// FUNCTIONS // + +/** +* Cumulatively tests whether at least one element in a provided array passes a test implemented by a predicate function. +* +* @private +* @param {Collection} x - input array +* @param {Collection} y - output array +* @param {integer} stride - output array stride +* @param {NonNegativeInteger} offset - output array offset +* @param {Function} predicate - test function +* @param {*} thisArg - execution context +* @returns {Collection} output array +* +* @example +* function isPositive( v ) { +* return v > 0; +* } +* +* var x = [ false, false, false, true, false ]; +* var y = [ false, null, false, null, false, null, false, null, false, null ]; +* +* var out = indexed( x, y, 2, 0, isPositive ); +* // returns [ false, null, false, null, false, null, true, null, true, null ] +*/ +function indexed( x, y, stride, offset, predicate, thisArg ) { + var flg; + var io; + var i; + + flg = false; + io = offset; + for ( i = 0; i < x.length; i++ ) { + if ( !flg && predicate.call(thisArg, x[ i ], i, x ) ) { + flg = true; + } + y[ io ] = flg; + io += stride; + } + return y; +} + +/** +* Cumulatively tests whether at least one element in a provided array passes a test implemented by a predicate function. +* +* @private +* @param {Object} x - input array object +* @param {Object} y - output array object +* @param {integer} stride - output array stride +* @param {NonNegativeInteger} offset - output array offset +* @param {Function} predicate - test function +* @param {*} thisArg - execution context +* @returns {Collection} output array +* +* @example +* function isPositive( v ) { +* return v > 0; +* } +* +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +* +* var x = toAccessorArray( [ false, false, false, true, false ] ); +* var y = toAccessorArray( [ false, null, false, null, false, null, false, null, false, null ] ); +* +* var arr = accessors( arraylike2object( x ), arraylike2object( y ), 2, 0, isPositive ); +* +* var v = y.get( 0 ); +* // returns false +* +* v = y.get( 2 ); +* // returns false +* +* v = y.get( 4 ); +* // returns false +* +* v = y.get( 6 ); +* // returns true +* +* v = y.get( 8 ); +* // returns true +*/ +function accessors( x, y, stride, offset, predicate, thisArg ) { + var xdata; + var ydata; + var xget; + var yset; + var flg; + var io; + var i; + + xdata = x.data; + ydata = y.data; + + xget = x.accessors[ 0 ]; + yset = y.accessors[ 1 ]; + + flg = false; + io = offset; + for ( i = 0; i < xdata.length; i++ ) { + if ( !flg && predicate.call( thisArg, xget( xdata, i ), i, x ) ) { + flg = true; + } + yset( ydata, io, flg ); + io += stride; + } + return ydata; +} + + +// MAIN // + +/** +* Cumulatively tests whether at least one element in a provided array passes a test implemented by a predicate function and assigns results to provided output array. +* +* @param {Collection} x - input array +* @param {Collection} y - output array +* @param {integer} stride - output array stride +* @param {NonNegativeInteger} offset - output array offset +* @param {Function} predicate - test function +* @param {*} [thisArg] - execution context +* @returns {Collection} output array +* +* @example +* function isPositive( v ) { +* return v > 0; +* } +* +* var x = [ 0, 0, 0, 1, 0 ]; +* var y = [ false, null, false, null, false, null, false, null, false, null ]; +* +* var out = assign( x, y, 2, 0, isPositive ); +// returns [ false, null, false, null, false, null, true, null, true, null ] +* +* var bool = ( y === out ); +* // returns true +*/ +function assign( x, y, stride, offset, predicate, thisArg ) { + var xo = arraylike2object( x ); + var yo = arraylike2object( y ); + + if ( + xo.accessorProtocol || + yo.accessorProtocol + ) { + return accessors( xo, yo, stride, offset, predicate, thisArg ); + } + indexed( x, y, stride, offset, predicate, thisArg ); + return y; +} + + +// EXPORTS // + +module.exports = assign; diff --git a/lib/node_modules/@stdlib/array/base/cuany-by/lib/index.js b/lib/node_modules/@stdlib/array/base/cuany-by/lib/index.js new file mode 100644 index 00000000000..38b0b7bd966 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cuany-by/lib/index.js @@ -0,0 +1,66 @@ +/** +* @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'; + +/** +* Cumulatively test whether at least one element in a provided array passes a test implemented by a predicate function. +* +* @module @stdlib/array/base/cuany-by +* +* @example +* var cuanyBy = require( '@stdlib/array/base/cuany-by' ); +* +* function isPositive( v ) { +* return v > 0; +* } +* +* var x = [ 0, 0, 0, 1, 0 ]; +* +* var y = cuanyBy( x, isPositive ); +* // returns [ false, false, false, true, true ] +* +* @example +* var cuanyBy = require( '@stdlib/array/base/cuany-by' ); +* +* function isPositive( v ) { +* return v > 0; +* } +* +* var x = [ 0, 0, 0, 1, 0 ]; +* var y = [ false, null, false, null, false, null, false, null, false, null ]; +* +* var arr = cuanyBy.assign( x, y, 2, 0, isPositive ); +* // returns [ false, null, false, null, false, null, true, null, true, null ] +*/ + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var main = require( './main.js' ); +var assign = require( './assign.js' ); + + +// MAIN // + +setReadOnly( main, 'assign', assign ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/array/base/cuany-by/lib/main.js b/lib/node_modules/@stdlib/array/base/cuany-by/lib/main.js new file mode 100644 index 00000000000..92505823fac --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cuany-by/lib/main.js @@ -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. +*/ + +'use strict'; + +// MODULES // + +var filled = require( '@stdlib/array/base/filled' ); +var assign = require( './assign.js' ); + + +// MAIN // + +/** +* Cumulatively tests whether at least one element in a provided array passes a test implemented by a predicate function. +* +* @param {Collection} x - input array +* @param {Function} predicate - test function +* @param {*} [thisArg] - execution context +* @returns {Array} output array +* +* @example +* function isPositive( v ) { +* return v > 0; +* } +* +* var x = [ 0, 0, 0, 1, 0 ]; +* +* var y = cuanyBy( x, isPositive ); +* // returns [ false, false, false, true, true ] +*/ +function cuanyBy( x, predicate, thisArg ) { + var y = filled( false, x.length ); + return assign( x, y, 1, 0, predicate, thisArg ); +} + + +// EXPORTS // + +module.exports = cuanyBy; diff --git a/lib/node_modules/@stdlib/array/base/cuany-by/package.json b/lib/node_modules/@stdlib/array/base/cuany-by/package.json new file mode 100644 index 00000000000..09b579ad405 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cuany-by/package.json @@ -0,0 +1,67 @@ +{ + "name": "@stdlib/array/base/cuany", + "version": "0.0.0", + "description": "Cumulatively test whether at least one element in a provided array passes a test implemented by a predicate function.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "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", + "stdtypes", + "types", + "data", + "structure", + "utils", + "generic", + "array", + "cuany", + "cumulative", + "test", + "some", + "array.some", + "validate" + ] +} diff --git a/lib/node_modules/@stdlib/array/base/cuany-by/test/test.assign.js b/lib/node_modules/@stdlib/array/base/cuany-by/test/test.assign.js new file mode 100644 index 00000000000..6729e9eb6b7 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cuany-by/test/test.assign.js @@ -0,0 +1,304 @@ +/** +* @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 BooleanArray = require( '@stdlib/array/bool' ); +var Float64Array = require( '@stdlib/array/float64' ); +var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var cuanyBy = require( './../lib/assign.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof cuanyBy, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function cumulatively tests whether at least one element in a provided array passes a test implemented by a predicate function (generic)', function test( t ) { + var expected; + var actual; + var ctx; + var x; + var y; + + ctx = { + 'count': 0 + }; + x = [ true, false, true, false, true ]; + y = [ false, true, false, true, false ]; + + actual = cuanyBy( x, y, 1, 0, predicate, ctx ); + expected = [ true, true, true, true, true ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = [ false, false, true, false, false ]; + y = [ false, null, false, null, false, null, false, null, false, null ]; + + actual = cuanyBy( x, y, 2, 0, predicate, ctx ); + expected = [ false, null, false, null, true, null, true, null, true, null ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = [ false, false, true, false, false ]; + y = [ false, false, false, true, true, true ]; + + actual = cuanyBy( x, y, 1, 1, predicate, ctx ); + expected = [ false, false, false, true, true, true ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = []; + y = [ false, false, false, false, false ]; + + actual = cuanyBy( x, y, 1, 0, predicate, ctx ); + expected = [ false, false, false, false, false ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = [ true ]; + y = [ false, false ]; + + actual = cuanyBy( x, y, 1, 1, predicate, ctx ); + expected = [ false, true ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); + + function predicate( value ) { + this.count += 1; // eslint-disable-line no-invalid-this + return value; + } +}); + +tape( 'the function cumulatively tests whether at least one element in a provided array passes a test implemented by a predicate function (typed)', function test( t ) { + var expected; + var actual; + var ctx; + var x; + var y; + + ctx = { + 'count': 0 + }; + x = new Float64Array( [ 1.0, 0.0, 1.0, 0.0, 1.0 ] ); + y = [ false, true, false, true, false ]; + + actual = cuanyBy( x, y, 1, 0, predicate, ctx ); + expected = [ true, true, true, true, true ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Float64Array( [ 0.0, 0.0, 1.0, 0.0, 0.0 ] ); + y = [ false, null, false, null, false, null, false, null, false, null ]; + + actual = cuanyBy( x, y, 2, 0, predicate, ctx ); + expected = [ false, null, false, null, true, null, true, null, true, null ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Float64Array( [ 0.0, 0.0, 1.0, 0.0, 0.0 ] ); + y = [ false, false, false, true, true, true ]; + + actual = cuanyBy( x, y, 1, 1, predicate, ctx ); + expected = [ false, false, false, true, true, true ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Float64Array( [] ); + y = [ false, false, false, false, false ]; + + actual = cuanyBy( x, y, 1, 0, predicate, ctx ); + expected = [ false, false, false, false, false ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Float64Array( [ 1.0 ] ); + y = [ false, false ]; + + actual = cuanyBy( x, y, 1, 1, predicate, ctx ); + expected = [ false, true ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); + + function predicate( value ) { + this.count += 1; // eslint-disable-line no-invalid-this + return ( value > 0 ); + } +}); + +tape( 'the function cumulatively tests whether at least one element in a provided array passes a test implemented by a predicate function (boolean)', function test( t ) { + var expected; + var actual; + var ctx; + var x; + var y; + + ctx = { + 'count': 0 + }; + x = new BooleanArray( [ true, true, true, true, true ] ); + y = [ false, true, false, true, false ]; + + actual = cuanyBy( x, y, 1, 0, predicate, ctx ); + expected = [ true, true, true, true, true ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new BooleanArray( [ false, false, true, false, false ] ); + y = [ false, null, false, null, false, null, false, null, false, null ]; + + actual = cuanyBy( x, y, 2, 0, predicate, ctx ); + expected = [ false, null, false, null, true, null, true, null, true, null ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new BooleanArray( [ false, false, true, false, false ] ); + y = [ false, false, false, true, true, true ]; + + actual = cuanyBy( x, y, 1, 1, predicate, ctx ); + expected = [ false, false, false, true, true, true ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new BooleanArray( [] ); + y = [ false, false, false, false, false ]; + + actual = cuanyBy( x, y, 1, 0, predicate, ctx ); + expected = [ false, false, false, false, false ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new BooleanArray( [ true ] ); + y = [ false, false ]; + + actual = cuanyBy( x, y, 1, 1, predicate, ctx ); + expected = [ false, true ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); + + function predicate( value ) { + this.count += 1; // eslint-disable-line no-invalid-this + return ( value > 0 ); + } +}); + +tape( 'the function cumulatively tests whether at least one element in a provided array passes a test implemented by a predicate function (accessor)', function test( t ) { + var expected; + var actual; + var ybuf; + var ctx; + var x; + var y; + + ctx = { + 'count': 0 + }; + x = toAccessorArray( [ true, false, true, false, true ] ); + ybuf = [ false, true, false, true, false ]; + y = toAccessorArray( ybuf ); + + actual = cuanyBy( x, y, 1, 0, predicate, ctx ); + expected = [ true, true, true, true, true ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ybuf, expected, 'returns expected value' ); + + x = toAccessorArray( [ false, false, true, false, false ] ); + ybuf = [ false, null, false, null, false, null, false, null, false, null ]; + y = toAccessorArray( ybuf ); + + actual = cuanyBy( x, y, 2, 0, predicate, ctx ); + expected = [ false, null, false, null, true, null, true, null, true, null ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ybuf, expected, 'returns expected value' ); + + x = toAccessorArray( [ false, false, true, false, false ] ); + ybuf = [ false, false, false, false, false, false ]; + y = toAccessorArray( ybuf ); + + actual = cuanyBy( x, y, 1, 1, predicate, ctx ); + expected = [ false, false, false, true, true, true ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ybuf, expected, 'returns expected value' ); + + x = toAccessorArray( [ true, false, false, false, false ] ); + ybuf = [ false, false, false, false, false ]; + y = toAccessorArray( ybuf ); + + actual = cuanyBy( x, y, 1, 0, predicate, ctx ); + expected = [ true, true, true, true, true ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ybuf, expected, 'returns expected value' ); + + x = toAccessorArray( [] ); + ybuf = [ false, false, false, false, false ]; + y = toAccessorArray( ybuf ); + + actual = cuanyBy( x, y, 1, 0, predicate, ctx ); + expected = [ false, false, false, false, false ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ybuf, expected, 'returns expected value' ); + + x = toAccessorArray( [ true ] ); + ybuf = [ false, false ]; + y = toAccessorArray( ybuf ); + + actual = cuanyBy( x, y, 1, 1, predicate, ctx ); + expected = [ false, true ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ybuf, expected, 'returns expected value' ); + + t.end(); + + function predicate( value ) { + this.count += 1; // eslint-disable-line no-invalid-this + return value; + } +}); diff --git a/lib/node_modules/@stdlib/array/base/cuany-by/test/test.js b/lib/node_modules/@stdlib/array/base/cuany-by/test/test.js new file mode 100644 index 00000000000..21a2aeb9903 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cuany-by/test/test.js @@ -0,0 +1,41 @@ +/** +* @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 hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var hasMethod = require( '@stdlib/assert/is-method' ); +var cuanyBy = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof cuanyBy, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is an `assign` method', function test( t ) { + t.strictEqual( hasOwnProp( cuanyBy, 'assign' ), true, 'returns expected value' ); + t.strictEqual( hasMethod( cuanyBy, 'assign' ), true, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/array/base/cuany-by/test/test.main.js b/lib/node_modules/@stdlib/array/base/cuany-by/test/test.main.js new file mode 100644 index 00000000000..9c2ffa587af --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cuany-by/test/test.main.js @@ -0,0 +1,185 @@ +/** +* @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 BooleanArray = require( '@stdlib/array/bool' ); +var Float64Array = require( '@stdlib/array/float64' ); +var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var cuanyBy = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof cuanyBy, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function cumulatively tests whether at least one element in a provided array passes a test implemented by a predicate function (generic)', function test( t ) { + var expected; + var actual; + var x; + + x = [ false, false, true, false, false ]; + actual = cuanyBy( x, predicate ); + expected = [ false, false, true, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; + actual = cuanyBy( x, predicate ); + expected = [ false, false, false, false, false ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = [ true, true, true, true, true ]; + actual = cuanyBy( x, predicate ); + expected = [ true, true, true, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = [ null, {}, null ]; + actual = cuanyBy( x, predicate ); + expected = [ false, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = [ true, false, false, false, false ]; + actual = cuanyBy( x, predicate ); + expected = [ true, true, true, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); + + function predicate( value ) { + return value; + } +}); + +tape( 'the function cumulatively tests whether at least one element in a provided array passes a test implemented by a predicate function (typed)', function test( t ) { + var expected; + var actual; + var x; + + x = new Float64Array( [ 0.0, 0.0, 1.0, 0.0, 0.0 ] ); + actual = cuanyBy( x, predicate ); + expected = [ false, false, true, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + actual = cuanyBy( x, predicate ); + expected = [ false, false, false, false, false ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ); + actual = cuanyBy( x, predicate ); + expected = [ true, true, true, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Float64Array( [ 0.0, 1.0, 0.0 ] ); + actual = cuanyBy( x, predicate ); + expected = [ false, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Float64Array( [ 1.0, 0.0, 0.0, 0.0, 0.0 ] ); + actual = cuanyBy( x, predicate ); + expected = [ true, true, true, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); + + function predicate( value ) { + return ( value > 0 ); + } +}); + +tape( 'the function cumulatively tests whether at least one element in a provided array passes a test implemented by a predicate function (boolean)', function test( t ) { + var expected; + var actual; + var x; + + x = new BooleanArray( [ false, false, true, false, false ] ); + actual = cuanyBy( x, predicate ); + expected = [ false, false, true, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new BooleanArray( [ false, false, false, false, false ] ); + actual = cuanyBy( x, predicate ); + expected = [ false, false, false, false, false ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new BooleanArray( [ true, true, true, true, true ] ); + actual = cuanyBy( x, predicate ); + expected = [ true, true, true, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new BooleanArray( [ false, true, true ] ); + actual = cuanyBy( x, predicate ); + expected = [ false, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new BooleanArray( [ true, false, true, false, false ] ); + actual = cuanyBy( x, predicate ); + expected = [ true, true, true, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); + + function predicate( value ) { + return value; + } +}); + +tape( 'the function cumulatively tests whether at least one element of an accessor array is truthy (accessor)', function test( t ) { + var expected; + var actual; + var x; + + x = toAccessorArray( [ false, false, true, false, false ] ); + + actual = cuanyBy( x, predicate ); + expected = [ false, false, true, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = toAccessorArray( [ false, false, false, false, false ] ); + actual = cuanyBy( x, predicate ); + expected = [ false, false, false, false, false ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = toAccessorArray( [ true, true, true, true, true ] ); + actual = cuanyBy( x, predicate ); + expected = [ true, true, true, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = toAccessorArray( [ false, true, false ] ); + actual = cuanyBy( x, predicate ); + expected = [ false, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = toAccessorArray( [ true, false, false, false, false ] ); + actual = cuanyBy( x, predicate ); + expected = [ true, true, true, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); + + function predicate( value ) { + return value; + } +}); diff --git a/lib/node_modules/@stdlib/array/base/cuevery-by/README.md b/lib/node_modules/@stdlib/array/base/cuevery-by/README.md new file mode 100644 index 00000000000..346246a6327 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cuevery-by/README.md @@ -0,0 +1,145 @@ + + +# cueveryBy + +> Cumulatively test whether every array element in a provided array passes a test implemented by a predicate function. + +
+ +## Usage + +```javascript +var cueveryBy = require( '@stdlib/array/base/cuevery-by' ); +``` + +#### cueveryBy( x, predicate\[, thisArg ] ) + +Cumulatively tests whether every array element in a provided array passes a test implemented by a predicate function. + +```javascript +function fcn( value) { + return ( value > 0 ); +} + +var x = [ 1, 1, 0, 0, 0 ]; + +var y = cueveryBy( x, fcn ); +// returns [ true, true, false, false, false ] +``` + +The invoked `predicate` function is provided three arguments: + +- **value**: collection element. +- **index**: collection index. +- **collection**: input collection. + +To set the function execution context, provide a `thisArg`. + +```javascript +function fcn( v ) { + this.count += 1; + return ( v > 0 ); +} + +var x = [ 1, 1, 0, 0, 0 ]; + +var context = { + 'count': 0 +}; + +var bool = cueveryBy( x, fcn, context ); +// returns [ true, true, false, false, false ] + +var count = context.count; +// returns 3 +``` + +#### cueveryBy.assign( x, out, stride, offset, predicate\[, thisArg ] ) + +Cumulatively tests whether every array element in a provided array passes a test implemented by a predicate function and assigns the results to a provided output array. + +```javascript +function fcn( v ) { + return ( v > 0 ); +} + +var x = [ 1, 1, 0, 0, 0 ]; +var y = [ false, null, false, null, false, null, false, null, false, null ]; + +var out = cueveryBy.assign( x, y, 2, 0, fcn ); +// returns [ true, null, true, null, false, null, false, null, false, null ] + +var bool = ( out === y ); +// returns true +``` + +
+ + + +
+ +
+ + + +
+ +## Examples + + + +```javascript +var bernoulli = require( '@stdlib/random/array/bernoulli' ); +var cueveryBy = require( '@stdlib/array/base/cuevery-by' ); + +function fcn( value ) { + return ( value > 0 ); +} + +// Create an array of random values: +var x = bernoulli( 10, 0.8 ); +console.log( x ); + +// Cumulatively tests whether every array element passes a test: +var y = cueveryBy( x, fcn ); +console.log( y ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/array/base/cuevery-by/benchmark/benchmark.assign.length.js b/lib/node_modules/@stdlib/array/base/cuevery-by/benchmark/benchmark.assign.length.js new file mode 100644 index 00000000000..31344ed8eba --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cuevery-by/benchmark/benchmark.assign.length.js @@ -0,0 +1,99 @@ +/** +* @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 pow = require( '@stdlib/math/base/special/pow' ); +var isArray = require( '@stdlib/assert/is-array' ); +var isPositiveInteger = require( '@stdlib/assert/is-positive-integer' ).isPrimitive; +var filled = require( '@stdlib/array/base/filled' ); +var pkg = require( './../package.json' ).name; +var cueveryBy = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = filled( 1.5, len ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var y; + var v; + var i; + + y = filled( false, len ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = cueveryBy.assign( x, y, 1, 0, isPositiveInteger ); + if ( typeof v !== 'object' ) { + b.fail( 'should return an array' ); + } + } + b.toc(); + if ( !isArray( v ) ) { + b.fail( 'should return an array' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':assign:len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/base/cuevery-by/benchmark/benchmark.js b/lib/node_modules/@stdlib/array/base/cuevery-by/benchmark/benchmark.js new file mode 100644 index 00000000000..83b7a4f2869 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cuevery-by/benchmark/benchmark.js @@ -0,0 +1,53 @@ +/** +* @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 isArray = require( '@stdlib/assert/is-array' ); +var zeroTo = require( '@stdlib/array/base/zero-to' ); +var isPositiveInteger = require( '@stdlib/assert/is-positive-integer' ).isPrimitive; +var pkg = require( './../package.json' ).name; +var cueveryBy = require( './../lib' ); + + +// MAIN // + +bench( pkg+'::copy:len=100', function benchmark( b ) { + var x; + var i; + var v; + + x = zeroTo( 100 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = cueveryBy( x, isPositiveInteger ); + if ( typeof v !== 'object' ) { + b.fail( 'should return an array' ); + } + } + b.toc(); + if ( !isArray( v ) ) { + b.fail( 'should return an array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/base/cuevery-by/benchmark/benchmark.length.js b/lib/node_modules/@stdlib/array/base/cuevery-by/benchmark/benchmark.length.js new file mode 100644 index 00000000000..152c965f1fd --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cuevery-by/benchmark/benchmark.length.js @@ -0,0 +1,96 @@ +/** +* @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 pow = require( '@stdlib/math/base/special/pow' ); +var isArray = require( '@stdlib/assert/is-array' ); +var isPositiveInteger = require( '@stdlib/assert/is-positive-integer' ).isPrimitive; +var filled = require( '@stdlib/array/base/filled' ); +var pkg = require( './../package.json' ).name; +var cueveryBy = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = filled( 1.5, len ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = cueveryBy( x, isPositiveInteger ); + if ( typeof v !== 'object' ) { + b.fail( 'should return an array' ); + } + } + b.toc(); + if ( !isArray( v ) ) { + b.fail( 'should return an array' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/base/cuevery-by/docs/repl.txt b/lib/node_modules/@stdlib/array/base/cuevery-by/docs/repl.txt new file mode 100644 index 00000000000..4afd732fafa --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cuevery-by/docs/repl.txt @@ -0,0 +1,77 @@ + +{{alias}}( x, predicate[, thisArg] ) + Cumulatively tests whether every array element in a provided array passes a + test implemented by a predicate function. + + The predicate function is provided three arguments: + + - value: current array element. + - index: current array element index. + - arr: the input array. + + Parameters + ---------- + x: ArrayLikeObject + Input array. + + predicate: Function + Predicate function. + + thisArg: any (optional) + Execution context. + + Returns + ------- + out: Array + Output array. + + Examples + -------- + > function fcn( v ) { return ( v > 0 ); }; + > var x = [ 1, 1, 0, 0, 0 ]; + > var y = {{alias}}( x, fcn ) + [ true, true, false, false, false ] + + +{{alias}}.assign( x, out, stride, offset, predicate[, thisArg] ) + Cumulatively tests whether every array element in a provided array passes a + test implemented by a predicate function and assigns the values to elements + in a provided output array. + + Parameters + ---------- + x: ArrayLikeObject + Input array. + + out: ArrayLikeObject + Output array. + + stride: integer + Output array stride. + + offset: integer + Output array offset. + + predicate: Function + Predicate function. + + thisArg: any (optional) + Execution context. + + Returns + ------- + out: ArrayLikeObject + Output array. + + Examples + -------- + > function fcn( v ) { return ( v > 0 ); }; + > var x = [ 1, 1, 0, 0 ]; + > var out = [ false, null, false, null, false, null, false, null ]; + > var arr = {{alias}}.assign( x, out, 2, 0, fcn ) + [ true, null, true, null, false, null, false, null ] + > var bool = ( arr === out ) + true + + See Also + -------- diff --git a/lib/node_modules/@stdlib/array/base/cuevery-by/docs/types/index.d.ts b/lib/node_modules/@stdlib/array/base/cuevery-by/docs/types/index.d.ts new file mode 100644 index 00000000000..728e8d24f88 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cuevery-by/docs/types/index.d.ts @@ -0,0 +1,200 @@ +/* +* @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 { Collection, AccessorArrayLike, TypedArray, BooleanArray } from '@stdlib/types/array'; + +/** +* Checks whether an element in a collection passes a test. +* +* @returns boolean indicating whether an element in a collection passes a test +*/ +type Nullary = ( this: U ) => boolean; + +/** +* Checks whether an element in a collection passes a test. +* +* @param value - collection value +* @returns boolean indicating whether an element in a collection passes a test +*/ +type Unary = ( this: U, value: T ) => boolean; + +/** +* Checks whether an element in a collection passes a test. +* +* @param value - collection value +* @param index - collection index +* @returns boolean indicating whether an element in a collection passes a test +*/ +type Binary = ( this: U, value: T, index: number ) => boolean; + +/** +* Checks whether an element in a collection passes a test. +* +* @param value - collection value +* @param index - collection index +* @param collection - input collection +* @returns boolean indicating whether an element in a collection passes a test +*/ +type Ternary = ( this: U, value: T, index: number, collection: Collection ) => boolean; + +/** +* Checks whether an element in a collection passes a test. +* +* @param value - collection value +* @param index - collection index +* @param collection - input collection +* @returns boolean indicating whether an element in a collection passes a test +*/ +type Predicate = Nullary | Unary | Binary | Ternary; + +/** +* Interface describing `cueveryBy`. +*/ +interface CuEveryBy { + /** + * Cumulatively tests whether every array element in a provided array passes a test implemented by a predicate function. + * + * @param x - input array + * @param predicate - test function + * @param thisArg - execution context + * @returns output array + * + * @example + * function isPositive( v ) { + * return ( v > 0 ); + * } + * var x = [ 1, 1, 1, 0, 0 ]; + * + * var y = cueveryBy( x, isPositive ); + * // returns [ true, true, true, false, false ]; + */ + ( x: Collection | AccessorArrayLike, predicate: Predicate, thisArg?: ThisParameterType> ): Array; + + /** + * Cumulatively tests whether every array element in a provided array passes a test implemented by a predicate function and assigns the results to the provided output array. + * + * @param x - input array + * @param y - output array + * @param stride - output array stride + * @param offset - output array offset + * @param predicate - test function + * @param thisArg - execution context + * @returns output array + * + * @example + * function isPositive( v ) { + * return ( v > 0 ); + * } + * var x = [ 1, 1, 0, 0, 0 ]; + * var y = [ false, null, false, null, false, null, false, null, false, null ]; + * + * var arr = cueveryBy.assign( x, y, 2, 0, isPositive );, + * // returns [ true, null, true, null, false, null, false, null, false, null ]; + */ + assign( x: Collection | AccessorArrayLike, out: Array, stride: number, offset: number, predicate: Predicate, thisArg?: ThisParameterType> ): Array; + + /** + * Cumulatively tests whether every array element in a provided array passes a test implemented by a predicate function and assigns the results to the provided output array. + * + * @param x - input array + * @param out - output array + * @param stride - output array stride + * @param offset - output array offset + * @param predicate - test function + * @param thisArg - execution context + * @returns output array + * + * @example + * var BooleanArray = require( '@stdlib/array/bool' ); + * + * function isPositive( v ) { + * return ( v > 0 ); + * } + * var x = [ 0, 0, 0, 1, 0 ]; + * var y = new BooleanArray( [ false, false, false, false, false, false, false, false, false, false ] ); + * + * var arr = cueveryBy.assign( x, y, 2, 0, isPositive ); + * // returns + * + * var v = arr.get( 4 ); + * // returns false + */ + assign( x: Collection | AccessorArrayLike, out: U, stride: number, offset: number, predicate: Predicate, thisArg?: ThisParameterType> ): U; + + /** + * Cumulatively tests whether every array element in a provided array passes a test implemented by a predicate function and assigns the results to the provided output array. + * + * @param x - input array + * @param y - output array + * @param stride - output array stride + * @param offset - output array offset + * @param predicate - test function + * @param thisArg - execution context + * @returns output array + * + * @example + * function isPositive( v ) { + * return ( v > 0 ); + * } + * var x = [ 1, 1, 0, 0, 0 ]; + * var y = [ false, null, false, null, false, null, false, null, false, null ]; + * + * var arr = cueveryBy.assign( x, y, 2, 0, isPositive );, + * // returns [ true, null, true, null, false, null, false, null, false, null ]; + */ + assign( x: Collection | AccessorArrayLike, out: Collection | AccessorArrayLike, stride: number, offset: number, predicate: Predicate, thisArg?: ThisParameterType> ): Collection | AccessorArrayLike; + +} + +/** +* Cumulatively tests whether every array element in a provided array passes a test implemented by a predicate function. +* +* @param x - input array +* @param predicate - test function +* @param thisArg - execution context +* @returns output array +* +* @example +* function isPositive( v ) { +* return ( v > 0 ); +* } +* var x = [ 1, 1, 0, 0, 0 ]; +* +* var result = cueveryBy( x, isPositive ); +* // returns [ true, true, false, false, false ] +* +* @example +* function isPositive( v ) { +* return ( v > 0 ); +* } +* var x = [ 1, 1, 0, 0, 0 ]; +* var y = [ false, null, false, null, false, null, false, null, false, null ]; +* +* var arr = cueveryBy.assign( x, y, 2, 0, isPositive ); +* // returns [ true, null, true, null, false, null, false, null, false, null ]; +*/ +declare var cueveryBy: CuEveryBy; + + +// EXPORTS // + +export = cueveryBy; diff --git a/lib/node_modules/@stdlib/array/base/cuevery-by/docs/types/test.ts b/lib/node_modules/@stdlib/array/base/cuevery-by/docs/types/test.ts new file mode 100644 index 00000000000..bf19f6906ed --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cuevery-by/docs/types/test.ts @@ -0,0 +1,205 @@ +/* +* @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 cueveryBy = require( './index' ); + +const isPositive = ( v: number ): boolean => { + return ( v > 0 ); +}; + + +// TESTS // + +// The function returns an array... +{ + cueveryBy( [ 1, 2, 3, 4 ], isPositive ); // $ExpectType boolean[] + cueveryBy( [ 1, 2, 3, 4 ], isPositive ); // $ExpectType boolean[] + + cueveryBy( [ 1, 2, 3, 4 ], isPositive, {} ); // $ExpectType boolean[] + cueveryBy( [ 1, 2, 3, 4 ], isPositive, {} ); // $ExpectType boolean[] +} + +// The compiler throws an error if the function is provided a first argument which is not an array-like object... +{ + cueveryBy( 1, isPositive ); // $ExpectError + cueveryBy( true, isPositive ); // $ExpectError + cueveryBy( false, isPositive ); // $ExpectError + cueveryBy( null, isPositive ); // $ExpectError + cueveryBy( void 0, isPositive ); // $ExpectError + cueveryBy( {}, isPositive ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... +{ + cueveryBy( [], 1 ); // $ExpectError + cueveryBy( [], true ); // $ExpectError + cueveryBy( [], false ); // $ExpectError + cueveryBy( [], null ); // $ExpectError + cueveryBy( [], void 0 ); // $ExpectError + cueveryBy( [], {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + cueveryBy(); // $ExpectError + cueveryBy( [] ); // $ExpectError + cueveryBy( [], [], 'throw', {} ); // $ExpectError +} + +// Attached to the main export is an `assign` method which returns a collection... +{ + const x = [ 1, 2, 3, 4 ]; + + cueveryBy.assign( x, [ 0, 0, 0, 0 ], 1, 0, isPositive ); // $ExpectType (number | boolean)[] + cueveryBy.assign( x, new Float64Array( 4 ), 1, 0, isPositive ); // $ExpectType Float64Array + cueveryBy.assign( x, new Float32Array( 4 ), 1, 0, isPositive ); // $ExpectType Float32Array + cueveryBy.assign( x, new Int32Array( 4 ), 1, 0, isPositive ); // $ExpectType Int32Array + cueveryBy.assign( x, new Int16Array( 4 ), 1, 0, isPositive ); // $ExpectType Int16Array + cueveryBy.assign( x, new Int8Array( 4 ), 1, 0, isPositive ); // $ExpectType Int8Array + cueveryBy.assign( x, new Uint32Array( 4 ), 1, 0, isPositive ); // $ExpectType Uint32Array + cueveryBy.assign( x, new Uint16Array( 4 ), 1, 0, isPositive ); // $ExpectType Uint16Array + cueveryBy.assign( x, new Uint8Array( 4 ), 1, 0, isPositive ); // $ExpectType Uint8Array + cueveryBy.assign( x, new Uint8ClampedArray( 4 ), 1, 0, isPositive ); // $ExpectType Uint8ClampedArray + + cueveryBy.assign( x, [ 0, 0, 0, 0 ], 1, 0, isPositive, {} ); // $ExpectType (number | boolean)[] + cueveryBy.assign( x, new Float64Array( 4 ), 1, 0, isPositive, {} ); // $ExpectType Float64Array + cueveryBy.assign( x, new Float32Array( 4 ), 1, 0, isPositive, {} ); // $ExpectType Float32Array + cueveryBy.assign( x, new Int32Array( 4 ), 1, 0, isPositive, {} ); // $ExpectType Int32Array + cueveryBy.assign( x, new Int16Array( 4 ), 1, 0, isPositive, {} ); // $ExpectType Int16Array + cueveryBy.assign( x, new Int8Array( 4 ), 1, 0, isPositive, {} ); // $ExpectType Int8Array + cueveryBy.assign( x, new Uint32Array( 4 ), 1, 0, isPositive, {} ); // $ExpectType Uint32Array + cueveryBy.assign( x, new Uint16Array( 4 ), 1, 0, isPositive, {} ); // $ExpectType Uint16Array + cueveryBy.assign( x, new Uint8Array( 4 ), 1, 0, isPositive, {} ); // $ExpectType Uint8Array + cueveryBy.assign( x, new Uint8ClampedArray( 4 ), 1, 0, isPositive, {} ); // $ExpectType Uint8ClampedArray +} + +// The compiler throws an error if the `assign` method is provided a first argument which is not an array-like object... +{ + const x = [ 1, 1, 0, 0, 0 ]; + + cueveryBy.assign( 1, x, 2, 0, isPositive ); // $ExpectError + cueveryBy.assign( true, x, 2, 0, isPositive ); // $ExpectError + cueveryBy.assign( false, x, 2, 0, isPositive ); // $ExpectError + cueveryBy.assign( null, x, 2, 0, isPositive ); // $ExpectError + cueveryBy.assign( void 0, x, 2, 0, isPositive ); // $ExpectError + cueveryBy.assign( {}, x, 2, 0, isPositive ); // $ExpectError + + cueveryBy.assign( 1, x, 2, 0, isPositive, {} ); // $ExpectError + cueveryBy.assign( true, x, 2, 0, isPositive, {} ); // $ExpectError + cueveryBy.assign( false, x, 2, 0, isPositive, {} ); // $ExpectError + cueveryBy.assign( null, x, 2, 0, isPositive, {} ); // $ExpectError + cueveryBy.assign( void 0, x, 2, 0, isPositive, {} ); // $ExpectError + cueveryBy.assign( {}, x, 2, 0, isPositive, {} ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a second argument which is not an array-like object containing numbers... +{ + const x = [ 1, 1, 0, 0, 0 ]; + + cueveryBy.assign( x, 1, 1, 0, isPositive ); // $ExpectError + cueveryBy.assign( x, true, 1, 0, isPositive ); // $ExpectError + cueveryBy.assign( x, false, 1, 0, isPositive ); // $ExpectError + cueveryBy.assign( x, null, 1, 0, isPositive ); // $ExpectError + cueveryBy.assign( x, void 0, 1, 0, isPositive ); // $ExpectError + cueveryBy.assign( x, {}, 1, 0, isPositive ); // $ExpectError + + cueveryBy.assign( x, 1, 1, 0, isPositive, {} ); // $ExpectError + cueveryBy.assign( x, true, 1, 0, isPositive, {} ); // $ExpectError + cueveryBy.assign( x, false, 1, 0, isPositive, {} ); // $ExpectError + cueveryBy.assign( x, null, 1, 0, isPositive, {} ); // $ExpectError + cueveryBy.assign( x, void 0, 1, 0, isPositive, {} ); // $ExpectError + cueveryBy.assign( x, {}, 1, 0, isPositive, {} ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a third argument which is not a valid index... +{ + const x = [ 1, 1, 0, 0, 0 ]; + const y = [ false, null, false, null, false, null, false, null, false, null ]; + + cueveryBy.assign( x, y, '1', 1, isPositive ); // $ExpectError + cueveryBy.assign( x, y, true, 1, isPositive ); // $ExpectError + cueveryBy.assign( x, y, false, 1, isPositive ); // $ExpectError + cueveryBy.assign( x, y, null, 1, isPositive ); // $ExpectError + cueveryBy.assign( x, y, void 0, 1, isPositive ); // $ExpectError + cueveryBy.assign( x, y, {}, 1, isPositive ); // $ExpectError + cueveryBy.assign( x, y, [], 1, isPositive ); // $ExpectError + cueveryBy.assign( x, y, ( x: number ): number => x, 1, isPositive ); // $ExpectError + + cueveryBy.assign( x, y, '1', 1, isPositive, {} ); // $ExpectError + cueveryBy.assign( x, y, true, 1, isPositive, {} ); // $ExpectError + cueveryBy.assign( x, y, false, 1, isPositive, {} ); // $ExpectError + cueveryBy.assign( x, y, null, 1, isPositive, {} ); // $ExpectError + cueveryBy.assign( x, y, void 0, 1, isPositive, {} ); // $ExpectError + cueveryBy.assign( x, y, {}, 1, isPositive, {} ); // $ExpectError + cueveryBy.assign( x, y, [], 1, isPositive, {} ); // $ExpectError + cueveryBy.assign( x, y, ( x: number ): number => x, 1, isPositive, {} ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a fourth argument which is not a number... +{ + const x = [ 1, 1, 0, 0, 0 ]; + const y = [ false, null, false, null, false, null, false, null, false, null ]; + + cueveryBy.assign( x, y, 0, '1', isPositive ); // $ExpectError + cueveryBy.assign( x, y, 0, true, isPositive ); // $ExpectError + cueveryBy.assign( x, y, 0, false, isPositive ); // $ExpectError + cueveryBy.assign( x, y, 0, null, isPositive ); // $ExpectError + cueveryBy.assign( x, y, 0, void 0, isPositive ); // $ExpectError + cueveryBy.assign( x, y, 0, {}, isPositive ); // $ExpectError + cueveryBy.assign( x, y, 0, [], isPositive ); // $ExpectError + + cueveryBy.assign( x, y, 0, '1', isPositive, {} ); // $ExpectError + cueveryBy.assign( x, y, 0, true, isPositive, {} ); // $ExpectError + cueveryBy.assign( x, y, 0, false, isPositive, {} ); // $ExpectError + cueveryBy.assign( x, y, 0, null, isPositive, {} ); // $ExpectError + cueveryBy.assign( x, y, 0, void 0, isPositive, {} ); // $ExpectError + cueveryBy.assign( x, y, 0, {}, isPositive, {} ); // $ExpectError + cueveryBy.assign( x, y, 0, [], isPositive, {} ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a fifth argument which is not a function... +{ + const x = [ 1, 1, 0, 0, 0 ]; + const y = [ false, null, false, null, false, null, false, null, false, null ]; + + cueveryBy.assign( x, y, 0, 1, '1' ); // $ExpectError + cueveryBy.assign( x, y, 0, 1, true ); // $ExpectError + cueveryBy.assign( x, y, 0, 1, false ); // $ExpectError + cueveryBy.assign( x, y, 0, 1, null ); // $ExpectError + cueveryBy.assign( x, y, 0, 1, void 0 ); // $ExpectError + cueveryBy.assign( x, y, 0, 1, {} ); // $ExpectError + cueveryBy.assign( x, y, 0, 1, [] ); // $ExpectError + + cueveryBy.assign( x, y, 0, 1, '1', {} ); // $ExpectError + cueveryBy.assign( x, y, 0, 1, true, {} ); // $ExpectError + cueveryBy.assign( x, y, 0, 1, false, {} ); // $ExpectError + cueveryBy.assign( x, y, 0, 1, null, {} ); // $ExpectError + cueveryBy.assign( x, y, 0, 1, void 0, {} ); // $ExpectError + cueveryBy.assign( x, y, 0, 1, {}, {} ); // $ExpectError + cueveryBy.assign( x, y, 0, 1, [], {} ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... +{ + cueveryBy.assign(); // $ExpectError + cueveryBy.assign( [] ); // $ExpectError + cueveryBy.assign( [], [] ); // $ExpectError + cueveryBy.assign( [], [], 'throw' ); // $ExpectError + cueveryBy.assign( [], [], 'throw', [] ); // $ExpectError + cueveryBy.assign( [], [], 'throw', [], 1, 0, {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/array/base/cuevery-by/examples/index.js b/lib/node_modules/@stdlib/array/base/cuevery-by/examples/index.js new file mode 100644 index 00000000000..4f66c381674 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cuevery-by/examples/index.js @@ -0,0 +1,34 @@ +/** +* @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 bernoulli = require( '@stdlib/random/array/bernoulli' ); +var cueveryBy = require( './../lib' ); + +function fcn( value ) { + return ( value > 0 ); +} + +// Generate an array of random values: +var x = bernoulli( 10, 0.8 ); +console.log( x ); + +// Cumulatively tests whether every array element passes a test: +var y = cueveryBy( x, fcn ); +console.log( y ); diff --git a/lib/node_modules/@stdlib/array/base/cuevery-by/lib/assign.js b/lib/node_modules/@stdlib/array/base/cuevery-by/lib/assign.js new file mode 100644 index 00000000000..03504aafdfb --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cuevery-by/lib/assign.js @@ -0,0 +1,178 @@ +/** +* @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 arraylike2object = require( '@stdlib/array/base/arraylike2object' ); + + +// FUNCTIONS // + +/** +* Cumulatively tests whether every array element in a provided array passes a test implemented by a predicate function. +* +* @private +* @param {Collection} x - input array +* @param {Collection} out - output array +* @param {integer} stride - output array stride +* @param {NonNegativeInteger} offset - output array offset +* @param {Function} predicate - test function +* @param {*} thisArg - execution context +* @returns {Collection} output array +* +* @example +* function isPositive( value ) { +* return ( value > 0 ); +* } +* +* var x = [ 1, 1, 0, 0, 0 ]; +* +* var out = [ 0, 0, 0, 0, 0 ]; +* var arr = indexed( x, out, 1, 0, isPositive ); +* // returns [ true, true, false, false, false ] +*/ +function indexed( x, out, stride, offset, predicate, thisArg ) { + var flg; + var io; + var i; + + flg = true; + io = offset; + for ( i = 0; i <= x.length - 1; i++ ) { + if ( !flg ) { + out[ io ] = flg; + io += stride; + continue; + } + if ( !predicate.call( thisArg, x[ i ], i, x )) { + flg = false; + } + out[ io ] = flg; + io += stride; + } + return out; +} + +/** +* Cumulatively tests whether every array element in a provided array passes a test implemented by a predicate function. +* +* @private +* @param {Object} x - input array object +* @param {Object} out - output array object +* @param {integer} stride - output array stride +* @param {NonNegativeInteger} offset - output array offset +* @param {Function} predicate - test function +* @param {*} thisArg - execution context +* @returns {Collection} output array +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +* +* function isPositive( value ) { +* return ( value > 0 ); +* } +* +* var x = toAccessorArray( [ 1, 1, 0, 0, 0 ] ); +* +* var out = toAccessorArray( [ 0, 0, 0, 0, 0 ] ); +* var arr = accessors( arraylike2object( x ), arraylike2object( out ), 1, 0, isPositive ); +* +* var v = arr.get( 4 ); +* // returns false +*/ +function accessors( x, out, stride, offset, predicate, thisArg ) { + var xdata; + var odata; + var xget; + var oset; + var flg; + var io; + var i; + + xdata = x.data; + odata = out.data; + + xget = x.accessors[ 0 ]; + oset = out.accessors[ 1 ]; + + io = offset; + flg = true; + for ( i = 0; i <= xdata.length - 1; i++ ) { + if ( !flg ) { + oset( odata, io, flg ); + io += stride; + continue; + } + if ( !predicate.call( thisArg, xget( xdata, i ), i, xdata ) ) { + flg = false; + } + oset( odata, io, flg ); + io += stride; + } + return odata; +} + + +// MAIN // + +/** +* Cumulatively tests whether every array element in a provided array passes a test implemented by a predicate function. +* +* @param {Collection} x - input array +* @param {Collection} out - output array +* @param {integer} stride - output array stride +* @param {NonNegativeInteger} offset - output array offset +* @param {Function} predicate - test function +* @param {*} [thisArg] - execution context +* @returns {Collection} output array +* +* @example +* function isPositive( value ) { +* return ( value > 0 ); +* } +* +* var x = [ 1, 1, 1, 0, 1 ]; +* +* var y = [ false, null, false, null, false, null, false, null, false, null ]; +* var out = assign( x, y, 2, 0, isPositive ); +* // returns [ true, null, true, null, true, null, false, null, false, null ] +* +* var bool = ( y === out ); +* // returns true +*/ +function assign( x, out, stride, offset, predicate, thisArg ) { + var xo; + var oo; + + xo = arraylike2object( x ); + oo = arraylike2object( out ); + if ( xo.accessorProtocol || oo.accessorProtocol ) { + accessors( xo, oo, stride, offset, predicate, thisArg ); + return out; + } + indexed( x, out, stride, offset, predicate, thisArg ); + return out; +} + + +// EXPORTS // + +module.exports = assign; diff --git a/lib/node_modules/@stdlib/array/base/cuevery-by/lib/index.js b/lib/node_modules/@stdlib/array/base/cuevery-by/lib/index.js new file mode 100644 index 00000000000..a294acf89c2 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cuevery-by/lib/index.js @@ -0,0 +1,64 @@ +/** +* @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'; + +/** +* Cumulatively test whether every array element in a provided array passes a test implemented by a predicate function. +* +* @module @stdlib/array/base/cuevery-by +* +* @example +* var cueveryBy = require( '@stdlib/array/base/cuevery-by' ); +* +* function isPositive( value ) { +* return ( value > 0 ); +* } +* +* var x = [ 1, 1, 1, 0, 1 ]; +* var y = cueveryBy( x, isPositive ); +* // returns [ true, true, true, false, false ] +* +* @example +* var cueveryBy = require( '@stdlib/array/base/cuevery-by' ); +* +* var x = [ 1, 1, 1, 0, 1 ]; +* +* var y = [ false, null, false, null, false, null, false, null, false, null ]; +* var out = cueveryBy.assign( x, y, 2, 0, isPositive ); +* // returns [ true, null, true, null, true, null, false, null, false, null ] +* +* var bool = ( arr === out ); +* // returns true +*/ + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var main = require( './main.js' ); +var assign = require( './assign.js' ); + + +// MAIN // + +setReadOnly( main, 'assign', assign ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/array/base/cuevery-by/lib/main.js b/lib/node_modules/@stdlib/array/base/cuevery-by/lib/main.js new file mode 100644 index 00000000000..ec6598204bc --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cuevery-by/lib/main.js @@ -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. +*/ + +'use strict'; + +// MODULES // + +var filled = require( '@stdlib/array/base/filled' ); +var assign = require( './assign.js' ); + + +// MAIN // + +/** +* Cumulatively tests whether every array element in a provided array passes a test implemented by a predicate function. +* +* @param {Collection} x - input collection +* @param {Function} predicate - test function +* @param {*} [thisArg] - execution context +* @returns {Array} output array +* +* @example +* function isPositive( value ) { +* return ( value > 0 ); +* } +* +* var x = [ 1, 1, 1, 0, 1 ]; +* +* var y = cueveryBy( x, isPositive ); +* // returns [ true, true, true, false, false ] +*/ +function cueveryBy( x, predicate, thisArg ) { + var out = filled( false, x.length ); + return assign( x, out, 1, 0, predicate, thisArg ); +} + + +// EXPORTS // + +module.exports = cueveryBy; diff --git a/lib/node_modules/@stdlib/array/base/cuevery-by/package.json b/lib/node_modules/@stdlib/array/base/cuevery-by/package.json new file mode 100644 index 00000000000..d772df514dc --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cuevery-by/package.json @@ -0,0 +1,67 @@ +{ + "name": "@stdlib/array/base/cuevery-by", + "version": "0.0.0", + "description": "Cumulatively test whether every array element in a provided array passes a test implemented by a predicate function.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "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", + "stdtypes", + "types", + "data", + "structure", + "utils", + "generic", + "array", + "cuevery-by", + "cumulative", + "test", + "every", + "array.every", + "validate" + ] +} diff --git a/lib/node_modules/@stdlib/array/base/cuevery-by/test/test.assign.js b/lib/node_modules/@stdlib/array/base/cuevery-by/test/test.assign.js new file mode 100644 index 00000000000..b50c2831e58 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cuevery-by/test/test.assign.js @@ -0,0 +1,244 @@ +/** +* @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 Float64Array = require( '@stdlib/array/float64' ); +var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var cueveryBy = require( './../lib/assign.js' ); + + +// TESTS // + +function isPositive( v ) { + return ( v > 0 ); +} + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof cueveryBy, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function cumulatively tests whether every array element in a provided array passes a test implemented by a predicate function (generic)', function test( t ) { + var expected; + var actual; + var x; + var y; + + x = [ 1, 1, 1, 0, 1 ]; + y = [ false, null, false, null, false, null, false, null, false, null ]; + + actual = cueveryBy( x, y, 2, 0, isPositive); + expected = [ true, null, true, null, true, null, false, null, false, null ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = [ 1, 1, 0, 0 ]; + y = [ false, null, false, null, false, null, false, null ]; + + actual = cueveryBy( x, y, 2, 0, isPositive ); + expected = [ true, null, true, null, false, null, false, null ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = [ 0, 0, 1, 0, 1 ]; + y = [ false, false, false, true, true, true ]; + + actual = cueveryBy( x, y, 1, 1, isPositive ); + expected = [ false, false, false, false, false, false ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = []; + y = [ false, false, false, false, false ]; + + actual = cueveryBy( x, y, 1, 0, isPositive ); + expected = [ false, false, false, false, false ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = [ 1 ]; + y = [ false, false ]; + + actual = cueveryBy( x, y, 1, 1, isPositive ); + expected = [ false, true ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function cumulatively tests whether every array element in a provided array passes a test implemented by a predicate function (typed)', function test( t ) { + var expected; + var actual; + var x; + var y; + + x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + y = [ false, true, false, true, false ]; + + actual = cueveryBy( x, y, 1, 0, isPositive ); + expected = [ true, true, true, true, false ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Float64Array( [ 1.0, 1.0, 0.0, 0.0 ] ); + y = [ false, null, false, null, false, null, false, null ]; + + actual = cueveryBy( x, y, 2, 0, isPositive ); + expected = [ true, null, true, null, false, null, false, null ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Float64Array( [ 0.0, 1.0, 1.0, 0.0, 0.0 ] ); + y = [ true, false, false, true, true, true ]; + + actual = cueveryBy( x, y, 1, 0, isPositive ); + expected = [ false, false, false, false, false, true ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Float64Array( [] ); + y = [ false, false, false, false, false ]; + + actual = cueveryBy( x, y, 1, 0, isPositive ); + expected = [ false, false, false, false, false ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Float64Array( [ 1.0 ] ); + y = [ false, false ]; + + actual = cueveryBy( x, y, 1, 1, isPositive ); + expected = [ false, true ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function cumulatively tests whether every array element in a provided array passes a test implemented by a predicate function (accessor)', function test( t ) { + var expected; + var actual; + var ybuf; + var x; + var y; + + x = toAccessorArray( [ 1, 0, 0, 0, 1 ] ); + ybuf = [ false, true, false, true, false ]; + y = toAccessorArray( ybuf ); + + actual = cueveryBy( x, y, 1, 0, isPositive ); + expected = [ true, false, false, false, false ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ybuf, expected, 'returns expected value' ); + + x = toAccessorArray( [ 0, 1, 1, 0 ] ); + ybuf = [ false, null, false, null, false, null, false, null ]; + y = toAccessorArray( ybuf ); + + actual = cueveryBy( x, y, 2, 0, isPositive ); + expected = [ false, null, false, null, false, null, false, null ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ybuf, expected, 'returns expected value' ); + + x = toAccessorArray( [ 1, 1, 1, 0, 0 ] ); + ybuf = [ true, false, false, false, false, false ]; + y = toAccessorArray( ybuf ); + + actual = cueveryBy( x, y, 1, 1, isPositive ); + expected = [ true, true, true, true, false, false ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ybuf, expected, 'returns expected value' ); + + x = toAccessorArray( [ 1, 0, 0, 0, 1 ] ); + ybuf = [ false, false, false, false, false ]; + y = toAccessorArray( ybuf ); + + actual = cueveryBy( x, y, 1, 0, isPositive ); + expected = [ true, false, false, false, false ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ybuf, expected, 'returns expected value' ); + + x = toAccessorArray( [] ); + ybuf = [ false, false, false, false, false ]; + y = toAccessorArray( ybuf ); + + actual = cueveryBy( x, y, 1, 0, isPositive ); + expected = [ false, false, false, false, false ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ybuf, expected, 'returns expected value' ); + + x = toAccessorArray( [ 1 ] ); + ybuf = [ false, false ]; + y = toAccessorArray( ybuf ); + + actual = cueveryBy( x, y, 1, 1, isPositive ); + expected = [ false, true ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ybuf, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing an execution context', function test( t ) { + var expected; + var actual; + var ctx; + var x; + var y; + + ctx = { + 'count': 0 + }; + + x = [ 1, 1, 1, 0, 1 ]; + y = [ false, null, false, null, false, null, false, null, false, null ]; + + actual = cueveryBy( x, y, 2, 0, predicate, ctx); + expected = [ true, null, true, null, true, null, false, null, false, null ]; + + t.deepEqual( actual, expected, 'returns expected value' ); + t.strictEqual( ctx.count, 4, 'returns expected value' ); + t.end(); + + function predicate( v ) { + this.count += 1; // eslint-disable-line no-invalid-this + return ( v > 0 ); + } +}); diff --git a/lib/node_modules/@stdlib/array/base/cuevery-by/test/test.js b/lib/node_modules/@stdlib/array/base/cuevery-by/test/test.js new file mode 100644 index 00000000000..d49635ce2da --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cuevery-by/test/test.js @@ -0,0 +1,41 @@ +/** +* @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 hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var hasMethod = require( '@stdlib/assert/is-method' ); +var cueveryBy = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof cueveryBy, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is an `assign` method', function test( t ) { + t.strictEqual( hasOwnProp( cueveryBy, 'assign' ), true, 'returns expected value' ); + t.strictEqual( hasMethod( cueveryBy, 'assign' ), true, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/array/base/cuevery-by/test/test.main.js b/lib/node_modules/@stdlib/array/base/cuevery-by/test/test.main.js new file mode 100644 index 00000000000..627034f0449 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cuevery-by/test/test.main.js @@ -0,0 +1,172 @@ +/** +* @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 toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var Float64Array = require( '@stdlib/array/float64' ); +var cueveryBy = require( './../lib' ); + + +// FUNCTIONS // + +function isPositive( v ) { + return ( v > 0 ); +} + +function isNotNull( v ) { + return v !== null; +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual(typeof cueveryBy, 'function', 'main export is a function'); + t.end(); +}); + +tape( 'the function cumulatively tests whether every array element in a provided array passes a test implemented by a predicate function (generic)', function test( t ) { + var expected; + var actual; + var x; + + x = [ 1, 2, 0, 4 ]; + + actual = cueveryBy( x, isPositive ); + expected = [true, true, false, false]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = [ 0.0, 0.0, 0.0, 1.0, 1.0 ]; + actual = cueveryBy( x, isPositive ); + expected = [ false, false, false, false, false ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = [ true, true, true, true, true ]; + actual = cueveryBy( x, isPositive ); + expected = [ true, true, true, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = [ {}, null, {} ]; + actual = cueveryBy( x, isNotNull ); + expected = [ true, false, false ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function cumulatively tests whether every array element in a provided array passes a test implemented by a predicate function (typed)', function test( t ) { + var expected; + var actual; + var x; + + x = new Float64Array( [ 1.0, 1.0, 1.0, 0.0, 1.0 ] ); + actual = cueveryBy( x, isPositive ); + expected = [ true, true, true, false, false ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + actual = cueveryBy( x, isPositive ); + expected = [ false, false, false, false, false ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ); + actual =cueveryBy( x, isPositive ); + expected = [ true, true, true, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Float64Array( [ 1.0, 1.0, 0.0 ] ); + actual = cueveryBy( x, isPositive ); + expected = [ true, true, false ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Float64Array( [ 1.0, -2.0, 3.0, 0.0, 1.0 ] ); + actual = cueveryBy( x, isPositive ); + expected = [ true, false, false, false, false ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function cumulatively tests whether every array element in a provided array passes a test implemented by a predicate function (accessor array)', function test( t ) { + var expected; + var actual; + var x; + + x = toAccessorArray( [ 1, 1, 0, 0, 0 ] ); + + actual = cueveryBy( x, isPositive ); + expected = [true, true, false, false, false]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = toAccessorArray( [ 0, 0, 0, 0, 0 ] ); + actual = cueveryBy( x, isPositive ); + expected = [false, false, false, false, false]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = toAccessorArray( [ 1, 1, 1, 1, 1 ] ); + actual = cueveryBy( x, isPositive ); + expected = [true, true, true, true, true]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = toAccessorArray( [ 0, 1, 0 ] ); + actual = cueveryBy( x, isPositive ); + expected = [ false, false, false ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = toAccessorArray( [ 1, 0, 0, 0, 0 ] ); + actual = cueveryBy( x, isPositive ); + expected = [ true, false, false, false, false ]; + t.deepEqual( actual, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns an empty array if provided an empty input array as a first argument', function test( t ) { + var x = []; + t.deepEqual( cueveryBy( x, isPositive ), [], 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports providing an execution context', function test( t ) { + var expected; + var out; + var ctx; + var x; + + ctx = { + 'count': 0 + }; + + x = [ 1, 2, 0, 4 ]; + + out = cueveryBy( x, predicate, ctx ); + expected = [ true, true, false, false ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.strictEqual( ctx.count, 3, 'returns expected value' ); + t.end(); + + function predicate( v ) { + this.count += 1; // eslint-disable-line no-invalid-this + return ( v > 0 ); + } +}); diff --git a/lib/node_modules/@stdlib/array/base/cunone-by-right/README.md b/lib/node_modules/@stdlib/array/base/cunone-by-right/README.md index af6211e504e..4c2920358c9 100644 --- a/lib/node_modules/@stdlib/array/base/cunone-by-right/README.md +++ b/lib/node_modules/@stdlib/array/base/cunone-by-right/README.md @@ -20,7 +20,7 @@ limitations under the License. # cunoneByRight -> Cumulatively test whether no array element in a provided array passes a test implemented by a predicate function, while iterating from right-to-left. +> Cumulatively test whether every array element in a provided array fails a test implemented by a predicate function, while iterating from right-to-left.
@@ -32,7 +32,7 @@ var cunoneByRight = require( '@stdlib/array/base/cunone-by-right' ); #### cunoneByRight( x, predicate\[, thisArg ] ) -Cumulatively tests whether no array element in a provided array passes a test implemented by a `predicate` function, while iterating from right-to-left. +Cumulatively tests whether every array element in a provided array fails a test implemented by a `predicate` function, while iterating from right-to-left. ```javascript function fcn( value ) { @@ -45,25 +45,6 @@ var y = cunoneByRight( x, fcn ); // returns [ true, true, true, false, false ]; ``` -#### cunoneByRight.assign( x, out, stride, offset, predicate\[, thisArg ] ) - -Cumulatively tests whether no array element in a provided array passes a test implemented by a `predicate` function, while iterating from right-to-left, and assigns the results to the elements in the output array. - -```javascript -function fcn( v ) { - return v > 0; -} - -var x = [ 1, 1, 0, 0, 0 ]; -var y = [ false, null, false, null, false, null, false, null, false, null ]; - -var out = cunoneByRight.assign( x, y, 2, 0, fcn ); -// returns [ true, null, true, null, true, null, false, null, false, null ] - -var bool = ( out === y ); -// returns true -``` - The invoked `predicate` function is provided three arguments: - **value**: collection element. @@ -91,6 +72,25 @@ var count = context.count; // returns 4 ``` +#### cunoneByRight.assign( x, out, stride, offset, predicate\[, thisArg ] ) + +Cumulatively test whether every array element in a provided array fails a test implemented by a `predicate` function, while iterating from right-to-left, and assigns the results to the elements in the output array. + +```javascript +function fcn( v ) { + return v > 0; +} + +var x = [ 1, 1, 0, 0, 0 ]; +var y = [ false, null, false, null, false, null, false, null, false, null ]; + +var out = cunoneByRight.assign( x, y, 2, 0, fcn ); +// returns [ true, null, true, null, true, null, false, null, false, null ] + +var bool = ( out === y ); +// returns true +``` +
diff --git a/lib/node_modules/@stdlib/array/base/cunone-by-right/docs/repl.txt b/lib/node_modules/@stdlib/array/base/cunone-by-right/docs/repl.txt index af7b294b5c7..533a7ef4390 100644 --- a/lib/node_modules/@stdlib/array/base/cunone-by-right/docs/repl.txt +++ b/lib/node_modules/@stdlib/array/base/cunone-by-right/docs/repl.txt @@ -1,13 +1,14 @@ + {{alias}}( x, predicate[, thisArg] ) - Cumulatively tests whether no array element in a provided array passes a - test implemented by a predicate function, while iterating from - right-to-left. + Cumulatively tests whether every array element in a provided array fails a + test implemented by a predicate function, while iterating from right-to- + left. The predicate function is provided three arguments: - - `value`: current array element. - - `index`: current array element index. - - `arr`: the input array. + - value: current array element. + - index: current array element index. + - arr: the input array. Parameters ---------- @@ -34,15 +35,15 @@ {{alias}}.assign( x, out, stride, offset, predicate[, thisArg] ) - Cumulatively tests whether no array element in a provided array passes a - test implemented by a predicate function, while iterating from - right-to-left, and assign the results to the provided output array. + Cumulatively tests whether every array element in a provided array fails a + test implemented by a predicate function, while iterating from right-to- + left, and assigns the results to the provided output array. The predicate function is provided three arguments: - - `value`: current array element. - - `index`: current array element index. - - `arr`: the input array. + - value: current array element. + - index: current array element index. + - arr: the input array. Parameters ---------- diff --git a/lib/node_modules/@stdlib/array/base/cunone-by-right/docs/types/index.d.ts b/lib/node_modules/@stdlib/array/base/cunone-by-right/docs/types/index.d.ts index f96cb0bb0e9..90549a70343 100644 --- a/lib/node_modules/@stdlib/array/base/cunone-by-right/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/array/base/cunone-by-right/docs/types/index.d.ts @@ -71,7 +71,7 @@ type Predicate = Nullary | Unary | Binary | Ternary; */ interface CunoneByRight { /** - * Cumulatively test whether no array element in a provided array passes a test implemented by a predicate function, while iterating from right-to-left. + * Cumulatively tests whether every array element in a provided array fails a test implemented by a predicate function, while iterating from right-to-left. * * @param x - input array * @param predicate - test function @@ -90,7 +90,7 @@ interface CunoneByRight { ( x: Collection | AccessorArrayLike, predicate: Predicate, thisArg?: ThisParameterType> ): Array; /** - * Cumulatively tests whether no array element in a provided array passes a test implemented by a predicate function, while iterating from right-to-left, and assigns the results to the provided output array. + * Cumulatively tests whether every array element in a provided array fails a test implemented by a predicate function, while iterating from right-to-left, and assigns the results to the provided output array. * * @param x - input array * @param y - output array @@ -113,7 +113,7 @@ interface CunoneByRight { assign( x: Collection | AccessorArrayLike, out: Array, stride: number, offset: number, predicate: Predicate, thisArg?: ThisParameterType> ): Array; /** - * Cumulatively tests whether no array element in a provided array passes a test implemented by a predicate function, while iterating from right-to-left, and assigns the results to the provided output array. + * Cumulatively tests whether every array element in a provided array fails a test implemented by a predicate function, while iterating from right-to-left, and assigns the results to the provided output array. * * @param x - input array * @param out - output array @@ -141,7 +141,7 @@ interface CunoneByRight { assign( x: Collection | AccessorArrayLike, out: U, stride: number, offset: number, predicate: Predicate, thisArg?: ThisParameterType> ): U; /** - * Cumulatively tests whether no array element in a provided array passes a test implemented by a predicate function, while iterating from right-to-left, and assigns the results to the provided output array. + * Cumulatively tests whether every array element in a provided array fails a test implemented by a predicate function, while iterating from right-to-left, and assigns the results to the provided output array. * * @param x - input array * @param out - output array @@ -158,7 +158,7 @@ interface CunoneByRight { * var x = [ 0, 0, 0, 1, 0 ]; * var y = [ false, null, false, null, false, null, false, null, false, null ]; * - * var arr = cunoneBy.cunoneByRight( x, y, 2, 0, isPositive );, + * var arr = cunoneBy.assign( x, y, 2, 0, isPositive );, * // returns [ true, null, false, null, false, null, false, null, false, null ] */ assign( x: Collection | AccessorArrayLike, out: Collection | AccessorArrayLike, stride: number, offset: number, predicate: Predicate, thisArg?: ThisParameterType> ): Collection | AccessorArrayLike; diff --git a/lib/node_modules/@stdlib/array/base/cunone-by-right/lib/assign.js b/lib/node_modules/@stdlib/array/base/cunone-by-right/lib/assign.js index b0bc824e3d4..12cf3a4cf87 100644 --- a/lib/node_modules/@stdlib/array/base/cunone-by-right/lib/assign.js +++ b/lib/node_modules/@stdlib/array/base/cunone-by-right/lib/assign.js @@ -26,7 +26,7 @@ var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); // FUNCTIONS // /** -* Cumulatively tests whether no element in a provided array passes a test implemented by a predicate function, while iterating from right-to-left, and assigns the results to elements in the provided output array. +* Cumulatively tests whether every array element in a provided array fails a test implemented by a predicate function, while iterating from right-to-left, and assigns the results to elements in the provided output array. * * @private * @param {Collection} x - input array @@ -34,7 +34,7 @@ var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); * @param {integer} stride - output array stride * @param {NonNegativeInteger} offset - output array offset * @param {Function} predicate - test function -* @param {*} [thisArg] - execution context +* @param {*} thisArg - execution context * @returns {Collection} output array * * @example @@ -56,7 +56,7 @@ function indexed( x, out, stride, offset, predicate, thisArg ) { flg = true; io = offset; for ( i = x.length - 1; i >= 0; i-- ) { - if ( flg === true && predicate.call( thisArg, x[ i ], i, x ) ) { + if ( flg && predicate.call( thisArg, x[ i ], i, x ) ) { flg = false; } out[ io ] = flg; @@ -66,7 +66,7 @@ function indexed( x, out, stride, offset, predicate, thisArg ) { } /** -* Cumulatively tests whether no element in a provided accessor array passes a test implemented by a predicate function, while iterating from right-to-left, and assigns the results to elements in the accessor output array. +* Cumulatively tests whether every array element in a provided array fails a test implemented by a predicate function, while iterating from right-to-left, and assigns the results to elements in the accessor output array. * * @private * @param {Object} x - input array object @@ -74,7 +74,7 @@ function indexed( x, out, stride, offset, predicate, thisArg ) { * @param {integer} stride - output array stride * @param {NonNegativeInteger} offset - output array offset * @param {Function} predicate - test function -* @param {*} [thisArg] - execution context +* @param {*} thisArg - execution context * @returns {Collection} output array * * @example @@ -111,8 +111,7 @@ function accessors( x, out, stride, offset, predicate, thisArg ) { io = offset; flg = true; for ( i = xdata.length - 1; i >= 0; i-- ) { - if ( flg === true && - predicate.call( thisArg, xget( xdata, i ), i, xdata ) ) { + if ( flg && predicate.call( thisArg, xget( xdata, i ), i, xdata ) ) { flg = false; } oset( odata, io, flg ); @@ -125,7 +124,7 @@ function accessors( x, out, stride, offset, predicate, thisArg ) { // MAIN // /** -* Cumulatively tests whether no element in a provided array passes a test implemented by a predicate function, while iterating from right-to-left, and assigns the results to elements in the output array. +* Cumulatively tests whether every array element in a provided array fails a test implemented by a predicate function, while iterating from right-to-left, and assigns the results to elements in the output array. * * @param {Collection} x - input array * @param {Collection} out - output array diff --git a/lib/node_modules/@stdlib/array/base/cunone-by-right/lib/index.js b/lib/node_modules/@stdlib/array/base/cunone-by-right/lib/index.js index 36823a7c47b..38175a52608 100644 --- a/lib/node_modules/@stdlib/array/base/cunone-by-right/lib/index.js +++ b/lib/node_modules/@stdlib/array/base/cunone-by-right/lib/index.js @@ -19,7 +19,7 @@ 'use strict'; /** -* Cumulatively test whether no element in a provided array passes a test implemented by a predicate function, while iterating from right-to-left. +* Cumulatively test whether every array element in a provided array fails a test implemented by a predicate function, while iterating from right-to-left. * * @module @stdlib/array/base/cunone-by-right * diff --git a/lib/node_modules/@stdlib/array/base/cunone-by-right/lib/main.js b/lib/node_modules/@stdlib/array/base/cunone-by-right/lib/main.js index e7668166483..257ba1dd54b 100644 --- a/lib/node_modules/@stdlib/array/base/cunone-by-right/lib/main.js +++ b/lib/node_modules/@stdlib/array/base/cunone-by-right/lib/main.js @@ -27,7 +27,7 @@ var assign = require( './assign.js' ); // MAIN // /** -* Cumulatively tests whether no element in a provided array passes a test implemented by a predicate function, while iterating from right-to-left. +* Cumulatively tests whether every array element in a provided array fails a test implemented by a predicate function, while iterating from right-to-left. * * @param {Collection} x - input array * @param {Function} predicate - test function diff --git a/lib/node_modules/@stdlib/array/base/cunone-by-right/package.json b/lib/node_modules/@stdlib/array/base/cunone-by-right/package.json index 0d7c87db764..7dba32baf21 100644 --- a/lib/node_modules/@stdlib/array/base/cunone-by-right/package.json +++ b/lib/node_modules/@stdlib/array/base/cunone-by-right/package.json @@ -1,7 +1,7 @@ { "name": "@stdlib/array/base/cunone-by-right", "version": "0.0.0", - "description": "Cumulatively test whether no array element in a provided array passes a test implemented by a predicate function, while iterating from right-to-left.", + "description": "Cumulatively test whether every array element in a provided array fails a test implemented by a predicate function, while iterating from right-to-left.", "license": "Apache-2.0", "author": { "name": "The Stdlib Authors", diff --git a/lib/node_modules/@stdlib/array/base/cunone-by-right/test/test.assign.js b/lib/node_modules/@stdlib/array/base/cunone-by-right/test/test.assign.js index df6cf43a040..d88cf762656 100644 --- a/lib/node_modules/@stdlib/array/base/cunone-by-right/test/test.assign.js +++ b/lib/node_modules/@stdlib/array/base/cunone-by-right/test/test.assign.js @@ -26,6 +26,13 @@ var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); var cunoneByRight = require( './../lib/assign.js' ); +// FUNCTIONS // + +function isPositive( v ) { + return v > 0; +} + + // TESTS // tape( 'main export is a function', function test( t ) { @@ -40,14 +47,10 @@ tape( 'the function cumulatively tests whether no element in a provided array pa var x; var y; - function fcn( v ) { - return v > 0; - } - x = [ 0, 0, 1, 1, 0 ]; y = [ false, true, false, true, false ]; - actual = cunoneByRight( x, y, 1, 0, fcn ); + actual = cunoneByRight( x, y, 1, 0, isPositive ); expected = [ true, false, false, false, false ]; t.strictEqual( actual, y, 'returns expected value' ); @@ -56,7 +59,7 @@ tape( 'the function cumulatively tests whether no element in a provided array pa x = [ 1, 1, 0, 0 ]; y = [ false, null, false, null, false, null, false, null ]; - actual = cunoneByRight( x, y, 2, 0, fcn ); + actual = cunoneByRight( x, y, 2, 0, isPositive ); expected = [ true, null, true, null, false, null, false, null ]; t.strictEqual( actual, y, 'returns expected value' ); @@ -65,7 +68,7 @@ tape( 'the function cumulatively tests whether no element in a provided array pa x = [ 1, 1, 0, 0, 0 ]; y = [ false, false, false, true, true, true ]; - actual = cunoneByRight( x, y, 1, 1, fcn ); + actual = cunoneByRight( x, y, 1, 1, isPositive ); expected = [ false, true, true, true, false, false ]; t.strictEqual( actual, y, 'returns expected value' ); @@ -74,7 +77,7 @@ tape( 'the function cumulatively tests whether no element in a provided array pa x = []; y = [ false, false, false, false, false ]; - actual = cunoneByRight( x, y, 1, 0, fcn ); + actual = cunoneByRight( x, y, 1, 0, isPositive ); expected = [ false, false, false, false, false ]; t.strictEqual( actual, y, 'returns expected value' ); @@ -83,7 +86,7 @@ tape( 'the function cumulatively tests whether no element in a provided array pa x = [ 0 ]; y = [ false, false ]; - actual = cunoneByRight( x, y, 1, 1, fcn ); + actual = cunoneByRight( x, y, 1, 1, isPositive ); expected = [ false, true ]; t.strictEqual( actual, y, 'returns expected value' ); @@ -98,14 +101,10 @@ tape( 'the function cumulatively tests whether no element in a provided array pa var x; var y; - function fcn( v ) { - return v > 0; - } - x = new Float64Array( [ 1.0, 0.0, 1.0, 0.0, 0.0 ] ); y = [ false, true, false, true, false ]; - actual = cunoneByRight( x, y, 1, 0, fcn ); + actual = cunoneByRight( x, y, 1, 0, isPositive ); expected = [ true, true, false, false, false ]; t.strictEqual( actual, y, 'returns expected value' ); @@ -114,7 +113,7 @@ tape( 'the function cumulatively tests whether no element in a provided array pa x = new Float64Array( [ 1.0, 1.0, 0.0, 0.0 ] ); y = [ false, null, false, null, false, null, false, null ]; - actual = cunoneByRight( x, y, 2, 0, fcn ); + actual = cunoneByRight( x, y, 2, 0, isPositive ); expected = [ true, null, true, null, false, null, false, null ]; t.strictEqual( actual, y, 'returns expected value' ); @@ -123,7 +122,7 @@ tape( 'the function cumulatively tests whether no element in a provided array pa x = new Float64Array( [ 0.0, 1.0, 1.0, 0.0, 0.0 ] ); y = [ true, false, false, true, true, true ]; - actual = cunoneByRight( x, y, 1, 1, fcn ); + actual = cunoneByRight( x, y, 1, 1, isPositive ); expected = [ true, true, true, false, false, false ]; t.strictEqual( actual, y, 'returns expected value' ); @@ -132,7 +131,7 @@ tape( 'the function cumulatively tests whether no element in a provided array pa x = new Float64Array( [] ); y = [ false, false, false, false, false ]; - actual = cunoneByRight( x, y, 1, 0, fcn ); + actual = cunoneByRight( x, y, 1, 0, isPositive ); expected = [ false, false, false, false, false ]; t.strictEqual( actual, y, 'returns expected value' ); @@ -141,7 +140,7 @@ tape( 'the function cumulatively tests whether no element in a provided array pa x = new Float64Array( [ 0.0 ] ); y = [ false, false ]; - actual = cunoneByRight( x, y, 1, 1, fcn ); + actual = cunoneByRight( x, y, 1, 1, isPositive ); expected = [ false, true ]; t.strictEqual( actual, y, 'returns expected value' ); @@ -157,14 +156,11 @@ tape( 'the function cumulatively tests whether no element in a provided array pa var x; var y; - function fcn( v ) { - return v > 0; - } x = toAccessorArray( [ 1, 0, 0, 0, 0 ] ); ybuf = [ false, true, false, true, false ]; y = toAccessorArray( ybuf ); - actual = cunoneByRight( x, y, 1, 0, fcn ); + actual = cunoneByRight( x, y, 1, 0, isPositive ); expected = [ true, true, true, true, false ]; t.strictEqual( actual, y, 'returns expected value' ); @@ -174,7 +170,7 @@ tape( 'the function cumulatively tests whether no element in a provided array pa ybuf = [ false, null, false, null, false, null, false, null ]; y = toAccessorArray( ybuf ); - actual = cunoneByRight( x, y, 2, 0, fcn ); + actual = cunoneByRight( x, y, 2, 0, isPositive ); expected = [ true, null, false, null, false, null, false, null ]; t.strictEqual( actual, y, 'returns expected value' ); @@ -184,7 +180,7 @@ tape( 'the function cumulatively tests whether no element in a provided array pa ybuf = [ true, false, false, false, false, false ]; y = toAccessorArray( ybuf ); - actual = cunoneByRight( x, y, 1, 1, fcn ); + actual = cunoneByRight( x, y, 1, 1, isPositive ); expected = [ true, true, true, false, false, false ]; t.strictEqual( actual, y, 'returns expected value' ); @@ -194,7 +190,7 @@ tape( 'the function cumulatively tests whether no element in a provided array pa ybuf = [ true, true, true, true, true ]; y = toAccessorArray( ybuf ); - actual = cunoneByRight( x, y, 1, 0, fcn ); + actual = cunoneByRight( x, y, 1, 0, isPositive ); expected = [ false, false, false, false, false ]; t.strictEqual( actual, y, 'returns expected value' ); @@ -204,7 +200,7 @@ tape( 'the function cumulatively tests whether no element in a provided array pa ybuf = [ false, false, false, false, false ]; y = toAccessorArray( ybuf ); - actual = cunoneByRight( x, y, 1, 0, fcn ); + actual = cunoneByRight( x, y, 1, 0, isPositive ); expected = [ false, false, false, false, false ]; t.strictEqual( actual, y, 'returns expected value' ); @@ -214,7 +210,7 @@ tape( 'the function cumulatively tests whether no element in a provided array pa ybuf = [ false, false ]; y = toAccessorArray( ybuf ); - actual = cunoneByRight( x, y, 1, 1, fcn ); + actual = cunoneByRight( x, y, 1, 1, isPositive ); expected = [ false, true ]; t.strictEqual( actual, y, 'returns expected value' ); @@ -222,3 +218,30 @@ tape( 'the function cumulatively tests whether no element in a provided array pa t.end(); }); + +tape( 'the function supports providing an execution context', function test( t ) { + var expected; + var actual; + var ctx; + var x; + var y; + + ctx = { + 'count': 0 + }; + + x = [ 0, 1, 0, 0, 0 ]; + y = [ false, null, false, null, false, null, false, null, false, null ]; + + actual = cunoneByRight( x, y, 2, 0, predicate, ctx ); + expected = [ true, null, true, null, true, null, false, null, false, null ]; + + t.deepEqual( actual, expected, 'returns expected value' ); + t.strictEqual( ctx.count, 4, 'returns expected value' ); + t.end(); + + function predicate( v ) { + this.count += 1; // eslint-disable-line no-invalid-this + return ( v > 0 ); + } +}); diff --git a/lib/node_modules/@stdlib/array/base/cunone-by-right/test/test.main.js b/lib/node_modules/@stdlib/array/base/cunone-by-right/test/test.main.js index 51e813d9100..c08f0369b7c 100644 --- a/lib/node_modules/@stdlib/array/base/cunone-by-right/test/test.main.js +++ b/lib/node_modules/@stdlib/array/base/cunone-by-right/test/test.main.js @@ -26,6 +26,17 @@ var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); var cunoneByRight = require( './../lib' ); +// FUNCTIONS // + +function isPositive( v ) { + return v > 0; +} + +function isNotNull( v ) { + return v !== null; +} + + // TESTS // tape( 'main export is a function', function test( t ) { @@ -39,26 +50,19 @@ tape( 'the function cumulatively tests whether no array element in a provided ar var actual; var x; - function fcn( v ) { - return v > 0; - } - - function isNotNull( v ) { - return v !== null; - } x = [ 1, 1, 0, 0, 0 ]; - actual = cunoneByRight( x, fcn ); + actual = cunoneByRight( x, isPositive ); expected = [ true, true, true, false, false ]; t.deepEqual( actual, expected, 'returns expected value' ); x = [ 0.0, 0.0, 0.0, 1.0, 1.0 ]; - actual = cunoneByRight( x, fcn ); + actual = cunoneByRight( x, isPositive ); expected = [ false, false, false, false, false ]; t.deepEqual( actual, expected, 'returns expected value' ); x = [ true, false, false, false, false ]; - actual = cunoneByRight( x, fcn ); + actual = cunoneByRight( x, isPositive ); expected = [ true, true, true, true, false ]; t.deepEqual( actual, expected, 'returns expected value' ); @@ -75,32 +79,28 @@ tape( 'the function cumulatively tests whether no array element in a provided ar var actual; var x; - function fcn( v ) { - return v > 0; - } - x = new Float64Array( [ 0.0, 0.0, 1.0, 1.0, 0.0 ] ); - actual = cunoneByRight( x, fcn ); + actual = cunoneByRight( x, isPositive ); expected = [ true, false, false, false, false ]; t.deepEqual( actual, expected, 'returns expected value' ); x = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); - actual = cunoneByRight( x, fcn ); + actual = cunoneByRight( x, isPositive ); expected = [ true, true, true, true, true ]; t.deepEqual( actual, expected, 'returns expected value' ); x = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ); - actual = cunoneByRight( x, fcn ); + actual = cunoneByRight( x, isPositive ); expected = [ false, false, false, false, false ]; t.deepEqual( actual, expected, 'returns expected value' ); x = new Float64Array( [ 0.0, 1.0, 0.0 ] ); - actual = cunoneByRight( x, fcn ); + actual = cunoneByRight( x, isPositive ); expected = [ true, false, false ]; t.deepEqual( actual, expected, 'returns expected value' ); x = new Float64Array( [ 0.0, 1.0, 0.0, 0.0, 0.0 ] ); - actual = cunoneByRight( x, fcn ); + actual = cunoneByRight( x, isPositive ); expected = [ true, true, true, false, false ]; t.deepEqual( actual, expected, 'returns expected value' ); @@ -112,34 +112,55 @@ tape( 'the function cumulatively tests whether no array element in a provided ar var actual; var x; - function fcn( v ) { - return v > 0; - } - x = toAccessorArray( [ 1, 1, 0, 0, 0 ] ); - actual = cunoneByRight( x, fcn ); + actual = cunoneByRight( x, isPositive ); expected = [ true, true, true, false, false ]; t.deepEqual( actual, expected, 'returns expected value' ); x = toAccessorArray( [ 0, 0, 0, 0, 0 ] ); - actual = cunoneByRight( x, fcn ); + actual = cunoneByRight( x, isPositive ); expected = [ true, true, true, true, true ]; t.deepEqual( actual, expected, 'returns expected value' ); x = toAccessorArray( [ 1, 1, 1, 1, 1 ] ); - actual = cunoneByRight( x, fcn ); + actual = cunoneByRight( x, isPositive ); expected = [ false, false, false, false, false ]; t.deepEqual( actual, expected, 'returns expected value' ); x = toAccessorArray( [ 0, 0, 1 ] ); - actual = cunoneByRight( x, fcn ); + actual = cunoneByRight( x, isPositive ); expected = [ false, false, false ]; t.deepEqual( actual, expected, 'returns expected value' ); x = toAccessorArray( [ 1, 0, 0, 0, 0 ] ); - actual = cunoneByRight( x, fcn ); + actual = cunoneByRight( x, isPositive ); expected = [ true, true, true, true, false ]; t.deepEqual( actual, expected, 'returns expected value' ); t.end(); }); + +tape( 'the function supports providing an execution context', function test( t ) { + var expected; + var out; + var ctx; + var x; + + ctx = { + 'count': 0 + }; + + x = [ 1, -2, 0, -1 ]; + + out = cunoneByRight( x, predicate, ctx ); + expected = [ true, true, true, false ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.strictEqual( ctx.count, 4, 'returns expected value' ); + t.end(); + + function predicate( v ) { + this.count += 1; // eslint-disable-line no-invalid-this + return ( v > 0 ); + } +}); diff --git a/lib/node_modules/@stdlib/array/base/cunone-by/docs/repl.txt b/lib/node_modules/@stdlib/array/base/cunone-by/docs/repl.txt index 1dfb433d881..1d565b986af 100644 --- a/lib/node_modules/@stdlib/array/base/cunone-by/docs/repl.txt +++ b/lib/node_modules/@stdlib/array/base/cunone-by/docs/repl.txt @@ -5,9 +5,9 @@ The predicate function is provided three arguments: - - `value`: current array element. - - `index`: current array element index. - - `arr`: the input array. + - value: current array element. + - index: current array element index. + - arr: the input array. Parameters ---------- diff --git a/lib/node_modules/@stdlib/array/base/cunone-by/test/test.main.js b/lib/node_modules/@stdlib/array/base/cunone-by/test/test.main.js index 0ccae5acdd4..fdbb135d528 100644 --- a/lib/node_modules/@stdlib/array/base/cunone-by/test/test.main.js +++ b/lib/node_modules/@stdlib/array/base/cunone-by/test/test.main.js @@ -140,7 +140,7 @@ tape( 'the function cumulatively tests whether every array element in a provided t.end(); }); -tape( 'the function returns an empty array if provided an empty input array as first argument', function test( t ) { +tape( 'the function returns an empty array if provided an empty input array as a first argument', function test( t ) { var x = []; t.deepEqual( cunoneBy( x, isPositive ), [], 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/array/base/cunone/benchmark/benchmark.assign.length.js b/lib/node_modules/@stdlib/array/base/cunone/benchmark/benchmark.assign.length.js index b2a753cde2e..45e0f57e402 100644 --- a/lib/node_modules/@stdlib/array/base/cunone/benchmark/benchmark.assign.length.js +++ b/lib/node_modules/@stdlib/array/base/cunone/benchmark/benchmark.assign.length.js @@ -23,7 +23,7 @@ var bench = require( '@stdlib/bench' ); var pow = require( '@stdlib/math/base/special/pow' ); var isArray = require( '@stdlib/assert/is-array' ); -var filled = require('@stdlib/array/base/filled'); +var filled = require( '@stdlib/array/base/filled' ); var pkg = require( './../package.json' ).name; var cunone = require( './../lib' ); diff --git a/lib/node_modules/@stdlib/array/base/cusome-by-right/README.md b/lib/node_modules/@stdlib/array/base/cusome-by-right/README.md index 4a19d7dfe5c..4480a1158bb 100644 --- a/lib/node_modules/@stdlib/array/base/cusome-by-right/README.md +++ b/lib/node_modules/@stdlib/array/base/cusome-by-right/README.md @@ -74,7 +74,7 @@ var count = context.count; #### cusomeByRight.assign( x, n, out, stride, offset, predicate\[, thisArg ] ) -Cumulatively tests whether at least `n` elements in a provided array pass a test implemented by a `predicate` function, while iterating from right-to-left and assign the results to the elements in the output array. +Cumulatively tests whether at least `n` elements in a provided array pass a test implemented by a `predicate` function, while iterating from right-to-left, and assigns the results to the elements in the output array. ```javascript function fcn( v ) { diff --git a/lib/node_modules/@stdlib/array/base/cusome-by-right/docs/repl.txt b/lib/node_modules/@stdlib/array/base/cusome-by-right/docs/repl.txt index bd8fe70ed23..24c274afd73 100644 --- a/lib/node_modules/@stdlib/array/base/cusome-by-right/docs/repl.txt +++ b/lib/node_modules/@stdlib/array/base/cusome-by-right/docs/repl.txt @@ -1,13 +1,14 @@ + {{alias}}( x, n, predicate[, thisArg] ) - Cumulatively test whether at least `n` elements in a provided array pass a + Cumulatively tests whether at least `n` elements in a provided array pass a test implemented by a predicate function, while iterating from right-to-left. The predicate function is provided three arguments: - - `value`: current array element. - - `index`: current array element index. - - `arr`: the input array. + - value: current array element. + - index: current array element index. + - arr: the input array. Parameters ---------- @@ -37,15 +38,15 @@ {{alias}}.assign( x, n, out, stride, offset, predicate[, thisArg] ) - Cumulatively test whether at least `n` elements in a provided array pass a - test implemented by a predicate function, while iterating from right-to-left - and assign the results to the provided output array. + Cumulatively tests whether at least `n` elements in a provided array pass a + test implemented by a predicate function, while iterating from + right-to-left, and assigns the results to the provided output array. The predicate function is provided three arguments: - - `value`: current array element. - - `index`: current array element index. - - `arr`: the input array. + - value: current array element. + - index: current array element index. + - arr: the input array. Parameters ---------- diff --git a/lib/node_modules/@stdlib/array/base/cusome-by-right/docs/types/index.d.ts b/lib/node_modules/@stdlib/array/base/cusome-by-right/docs/types/index.d.ts index f626703ad60..d345d95f28b 100644 --- a/lib/node_modules/@stdlib/array/base/cusome-by-right/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/array/base/cusome-by-right/docs/types/index.d.ts @@ -71,7 +71,7 @@ type Predicate = Nullary | Unary | Binary | Ternary; */ interface CusomeByRight { /** - * Cumulatively test whether at least `n` elements in a provided array pass a test implemented by a predicate function, while iterating from right-to-left. + * Cumulatively tests whether at least `n` elements in a provided array pass a test implemented by a predicate function, while iterating from right-to-left. * * @param x - input array * @param n - number of elements @@ -91,7 +91,7 @@ interface CusomeByRight { ( x: Collection | AccessorArrayLike, n: number, predicate: Predicate, thisArg?: ThisParameterType> ): Array; /** - * Cumulatively test whether at least `n` elements in a provided array pass a test implemented by a predicate function, while iterating from right-to-left and assigns the results to the provided output array. + * Cumulatively tests whether at least `n` elements in a provided array pass a test implemented by a predicate function, while iterating from right-to-left, and assigns the results to the provided output array. * * @param x - input array * @param n - number of elements @@ -115,7 +115,7 @@ interface CusomeByRight { assign( x: Collection | AccessorArrayLike, n: number, out: Array, stride: number, offset: number, predicate: Predicate, thisArg?: ThisParameterType> ): Array; /** - * Cumulatively test whether at least `n` elements in a provided array pass a test implemented by a predicate function, while iterating from right-to-left and assigns the results to the provided output array. + * Cumulatively tests whether at least `n` elements in a provided array pass a test implemented by a predicate function, while iterating from right-to-left, and assigns the results to the provided output array. * * @param x - input array * @param n - number of elements @@ -127,19 +127,24 @@ interface CusomeByRight { * @returns output array * * @example - * function fcn( v ) { - * return v > 0; + * var BooleanArray = require( '@stdlib/array/bool' ); + * + * function isPositive( v ) { + * return ( v > 0 ); * } - * var x = [ 1, 1, 0, 0, 0 ]; - * var y = [ false, null, false, null, false, null, false, null, false, null ]; + * var x = [ 0, 0, 0, 1, 0 ]; + * var y = new BooleanArray( [ false, false, false, false, false, false, false, false, false, false ] ); * - * var arr = cusomeByRight.assign( x, 2, y, 2, 0, fcn );, - * // returns [ false, null, false, null, false, null, false, null, true, null ]; + * var arr = cusomeByRight.assign( x, 2, y, 2, 0, isPositive ); + * // returns + * + * var v = arr.get( 4 ); + * // returns false */ assign( x: Collection | AccessorArrayLike, n: number, out: U, stride: number, offset: number, predicate: Predicate, thisArg?: ThisParameterType> ): U; /** - * Cumulatively tests whether no array element in a provided array passes a test implemented by a predicate function, while iterating from right-to-left, and assigns the results to the provided output array. + * Cumulatively tests whether at least `n` elements in a provided array passes a test implemented by a predicate function, while iterating from right-to-left, and assigns the results to the provided output array. * * @param x - input array * @param n - number of elements @@ -151,14 +156,14 @@ interface CusomeByRight { * @returns output array * * @example - * function isPositive( v ) { - * return ( v > 0 ); + * function fcn( v ) { + * return v > 0; * } - * var x = [ 0, 0, 0, 1, 0 ]; + * var x = [ 1, 1, 0, 0, 0 ]; * var y = [ false, null, false, null, false, null, false, null, false, null ]; * - * var arr = cunoneBy.cunoneByRight( x, y, 2, 0, isPositive );, - * // returns [ true, null, false, null, false, null, false, null, false, null ] + * var arr = cusomeByRight.assign( x, 2, y, 2, 0, fcn );, + * // returns [ false, null, false, null, false, null, false, null, true, null ]; */ assign( x: Collection | AccessorArrayLike, n: number, out: Collection | AccessorArrayLike, stride: number, offset: number, predicate: Predicate, thisArg?: ThisParameterType> ): Collection | AccessorArrayLike; } diff --git a/lib/node_modules/@stdlib/array/base/cusome-by-right/docs/types/test.ts b/lib/node_modules/@stdlib/array/base/cusome-by-right/docs/types/test.ts index 9575a4ae080..b63505cea9a 100644 --- a/lib/node_modules/@stdlib/array/base/cusome-by-right/docs/types/test.ts +++ b/lib/node_modules/@stdlib/array/base/cusome-by-right/docs/types/test.ts @@ -169,7 +169,7 @@ const isPositive = ( v: number ): boolean => { cusomeByRight.assign( x, 1, y, 1, [], isPositive ); // $ExpectError } -// The compiler throws an error if the `assign` method is provided a fifth argument which is not a function... +// The compiler throws an error if the `assign` method is provided a sixth argument which is not a function... { const x = [ 1, 1, 0, 0, 0 ]; const y = [ false, null, false, null, false, null, false, null, false, null ]; diff --git a/lib/node_modules/@stdlib/array/base/cusome-by-right/lib/assign.js b/lib/node_modules/@stdlib/array/base/cusome-by-right/lib/assign.js index 4dbae5f7835..afe7670c665 100644 --- a/lib/node_modules/@stdlib/array/base/cusome-by-right/lib/assign.js +++ b/lib/node_modules/@stdlib/array/base/cusome-by-right/lib/assign.js @@ -26,7 +26,7 @@ var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); // FUNCTIONS // /** -* Cumulatively test whether at least `n` elements in a provided array pass a test implemented by a predicate function, while iterating from right-to-left and assign the results to elements in the provided output array. +* Cumulatively tests whether at least `n` elements in a provided array pass a test implemented by a predicate function, while iterating from right-to-left, and assign the results to elements in the provided output array. * * @private * @param {Collection} x - input array @@ -35,7 +35,7 @@ var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); * @param {integer} stride - output array stride * @param {NonNegativeInteger} offset - output array offset * @param {Function} predicate - test function -* @param {*} [thisArg] - execution context +* @param {*} thisArg - execution context * @returns {Collection} output array * * @example @@ -72,7 +72,7 @@ function indexed( x, n, out, stride, offset, predicate, thisArg ) { } /** -* Cumulatively test whether at least `n` elements in a provided accessor array pass a test implemented by a predicate function, while iterating from right-to-left and assign the results to elements in the accessor output array. +* Cumulatively tests whether at least `n` elements in a provided accessor array pass a test implemented by a predicate function, while iterating from right-to-left, and assigns the results to elements in the accessor output array. * * @private * @param {Object} x - input array object @@ -81,7 +81,7 @@ function indexed( x, n, out, stride, offset, predicate, thisArg ) { * @param {integer} stride - output array stride * @param {NonNegativeInteger} offset - output array offset * @param {Function} predicate - test function -* @param {*} [thisArg] - execution context +* @param {*} thisArg - execution context * @returns {Collection} output array * * @example @@ -137,7 +137,7 @@ function accessors( x, n, out, stride, offset, predicate, thisArg ) { // MAIN // /** -* Cumulatively test whether at least `n` elements in a provided array pass a test implemented by a predicate function, while iterating from right-to-left and assign the results to elements in the output array. +* Cumulatively tests whether at least `n` elements in a provided array pass a test implemented by a predicate function, while iterating from right-to-left, and assigns the results to elements in the output array. * * @param {Collection} x - input array * @param {PositiveInteger} n - number of elements diff --git a/lib/node_modules/@stdlib/array/base/cusome-by-right/test/test.assign.js b/lib/node_modules/@stdlib/array/base/cusome-by-right/test/test.assign.js index 9de3c9c31ff..af5e39e8ab7 100644 --- a/lib/node_modules/@stdlib/array/base/cusome-by-right/test/test.assign.js +++ b/lib/node_modules/@stdlib/array/base/cusome-by-right/test/test.assign.js @@ -26,6 +26,13 @@ var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); var cusomeByRight = require( './../lib/assign.js' ); +// FUNCTIONS // + +function isPositive( v ) { + return v > 0; +} + + // TESTS // tape( 'main export is a function', function test( t ) { @@ -40,14 +47,10 @@ tape( 'the function cumulatively tests whether at least n elements in a provided var x; var y; - function fcn( v ) { - return v > 0; - } - x = [ 1, 1, 0, 0, 1 ]; y = [ false, true, false, true, false ]; - actual = cusomeByRight( x, 2, y, 1, 0, fcn ); + actual = cusomeByRight( x, 2, y, 1, 0, isPositive ); expected = [ false, false, false, true, true ]; t.strictEqual( actual, y, 'returns expected value' ); @@ -56,7 +59,7 @@ tape( 'the function cumulatively tests whether at least n elements in a provided x = [ 1, 1, 0, 0 ]; y = [ false, null, false, null, false, null, false, null ]; - actual = cusomeByRight( x, 2, y, 2, 0, fcn ); + actual = cusomeByRight( x, 2, y, 2, 0, isPositive ); expected = [ false, null, false, null, false, null, true, null ]; t.strictEqual( actual, y, 'returns expected value' ); @@ -65,7 +68,7 @@ tape( 'the function cumulatively tests whether at least n elements in a provided x = [ 0, 0, 1, 0, 1 ]; y = [ false, false, false, true, true, true ]; - actual = cusomeByRight( x, 2, y, 1, 1, fcn ); + actual = cusomeByRight( x, 2, y, 1, 1, isPositive ); expected = [ false, false, false, true, true, true ]; t.strictEqual( actual, y, 'returns expected value' ); @@ -74,7 +77,7 @@ tape( 'the function cumulatively tests whether at least n elements in a provided x = []; y = [ false, false, false, false, false ]; - actual = cusomeByRight( x, 1, y, 1, 0, fcn ); + actual = cusomeByRight( x, 1, y, 1, 0, isPositive ); expected = [ false, false, false, false, false ]; t.strictEqual( actual, y, 'returns expected value' ); @@ -83,7 +86,7 @@ tape( 'the function cumulatively tests whether at least n elements in a provided x = [ 1 ]; y = [ false, false ]; - actual = cusomeByRight( x, 1, y, 1, 1, fcn ); + actual = cusomeByRight( x, 1, y, 1, 1, isPositive ); expected = [ false, true ]; t.strictEqual( actual, y, 'returns expected value' ); @@ -98,14 +101,10 @@ tape( 'the function cumulatively tests whether at least n elements in a provided var x; var y; - function fcn( v ) { - return v > 0; - } - x = new Float64Array( [ 1.0, 0.0, 1.0, 0.0, 1.0 ] ); y = [ false, true, false, true, false ]; - actual = cusomeByRight( x, 2, y, 1, 0, fcn ); + actual = cusomeByRight( x, 2, y, 1, 0, isPositive ); expected = [ false, false, true, true, true ]; t.strictEqual( actual, y, 'returns expected value' ); @@ -114,7 +113,7 @@ tape( 'the function cumulatively tests whether at least n elements in a provided x = new Float64Array( [ 1.0, 1.0, 0.0, 0.0 ] ); y = [ false, null, false, null, false, null, false, null ]; - actual = cusomeByRight( x, 2, y, 2, 0, fcn ); + actual = cusomeByRight( x, 2, y, 2, 0, isPositive ); expected = [ false, null, false, null, false, null, true, null ]; t.strictEqual( actual, y, 'returns expected value' ); @@ -123,7 +122,7 @@ tape( 'the function cumulatively tests whether at least n elements in a provided x = new Float64Array( [ 0.0, 1.0, 1.0, 0.0, 0.0 ] ); y = [ true, false, false, true, true, true ]; - actual = cusomeByRight( x, 2, y, 1, 1, fcn ); + actual = cusomeByRight( x, 2, y, 1, 1, isPositive ); expected = [ true, false, false, false, true, true ]; t.strictEqual( actual, y, 'returns expected value' ); @@ -132,7 +131,7 @@ tape( 'the function cumulatively tests whether at least n elements in a provided x = new Float64Array( [] ); y = [ false, false, false, false, false ]; - actual = cusomeByRight( x, 1, y, 1, 0, fcn ); + actual = cusomeByRight( x, 1, y, 1, 0, isPositive ); expected = [ false, false, false, false, false ]; t.strictEqual( actual, y, 'returns expected value' ); @@ -141,7 +140,7 @@ tape( 'the function cumulatively tests whether at least n elements in a provided x = new Float64Array( [ 1.0 ] ); y = [ false, false ]; - actual = cusomeByRight( x, 1, y, 1, 1, fcn ); + actual = cusomeByRight( x, 1, y, 1, 1, isPositive ); expected = [ false, true ]; t.strictEqual( actual, y, 'returns expected value' ); @@ -157,14 +156,11 @@ tape( 'the function cumulatively tests whether at least n elements in a provided var x; var y; - function fcn( v ) { - return v > 0; - } x = toAccessorArray( [ 1, 0, 0, 0, 1 ] ); ybuf = [ false, true, false, true, false ]; y = toAccessorArray( ybuf ); - actual = cusomeByRight( x, 2, y, 1, 0, fcn ); + actual = cusomeByRight( x, 2, y, 1, 0, isPositive ); expected = [ false, false, false, false, true ]; t.strictEqual( actual, y, 'returns expected value' ); @@ -174,7 +170,7 @@ tape( 'the function cumulatively tests whether at least n elements in a provided ybuf = [ false, null, false, null, false, null, false, null ]; y = toAccessorArray( ybuf ); - actual = cusomeByRight( x, 2, y, 2, 0, fcn ); + actual = cusomeByRight( x, 2, y, 2, 0, isPositive ); expected = [ false, null, false, null, true, null, true, null ]; t.strictEqual( actual, y, 'returns expected value' ); @@ -184,7 +180,7 @@ tape( 'the function cumulatively tests whether at least n elements in a provided ybuf = [ true, false, false, false, false, false ]; y = toAccessorArray( ybuf ); - actual = cusomeByRight( x, 2, y, 1, 1, fcn ); + actual = cusomeByRight( x, 2, y, 1, 1, isPositive ); expected = [ true, false, false, false, true, true ]; t.strictEqual( actual, y, 'returns expected value' ); @@ -194,7 +190,7 @@ tape( 'the function cumulatively tests whether at least n elements in a provided ybuf = [ false, false, false, false, false ]; y = toAccessorArray( ybuf ); - actual = cusomeByRight( x, 1, y, 1, 0, fcn ); + actual = cusomeByRight( x, 1, y, 1, 0, isPositive ); expected = [ true, true, true, true, true ]; t.strictEqual( actual, y, 'returns expected value' ); @@ -204,7 +200,7 @@ tape( 'the function cumulatively tests whether at least n elements in a provided ybuf = [ false, false, false, false, false ]; y = toAccessorArray( ybuf ); - actual = cusomeByRight( x, 1, y, 1, 0, fcn ); + actual = cusomeByRight( x, 1, y, 1, 0, isPositive ); expected = [ false, false, false, false, false ]; t.strictEqual( actual, y, 'returns expected value' ); @@ -214,7 +210,7 @@ tape( 'the function cumulatively tests whether at least n elements in a provided ybuf = [ false, false ]; y = toAccessorArray( ybuf ); - actual = cusomeByRight( x, 0, y, 1, 1, fcn ); + actual = cusomeByRight( x, 0, y, 1, 1, isPositive ); expected = [ false, true ]; t.strictEqual( actual, y, 'returns expected value' ); diff --git a/lib/node_modules/@stdlib/array/base/cusome-by-right/test/test.main.js b/lib/node_modules/@stdlib/array/base/cusome-by-right/test/test.main.js index 3970006054d..a3b47c2c34c 100644 --- a/lib/node_modules/@stdlib/array/base/cusome-by-right/test/test.main.js +++ b/lib/node_modules/@stdlib/array/base/cusome-by-right/test/test.main.js @@ -26,6 +26,17 @@ var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); var cusomeByRight = require( './../lib' ); +// FUNCTIONS // + +function isPositive( v ) { + return v > 0; +} + +function isNotNull( v ) { + return v !== null; +} + + // TESTS // tape( 'main export is a function', function test( t ) { @@ -39,26 +50,19 @@ tape( 'the function cumulatively tests whether at least n array elements in a pr var actual; var x; - function fcn( v ) { - return v > 0; - } - - function isNotNull( v ) { - return v !== null; - } x = [ 1, 1, 0, 0, 0 ]; - actual = cusomeByRight( x, 2, fcn ); + actual = cusomeByRight( x, 2, isPositive ); expected = [ false, false, false, false, true ]; t.deepEqual( actual, expected, 'returns expected value' ); x = [ 0.0, 0.0, 0.0, 1.0, 1.0 ]; - actual = cusomeByRight( x, 2, fcn ); + actual = cusomeByRight( x, 2, isPositive ); expected = [ false, true, true, true, true ]; t.deepEqual( actual, expected, 'returns expected value' ); x = [ true, true, true, true, true ]; - actual = cusomeByRight( x, 4, fcn ); + actual = cusomeByRight( x, 4, isPositive ); expected = [ false, false, false, true, true ]; t.deepEqual( actual, expected, 'returns expected value' ); @@ -75,32 +79,28 @@ tape( 'the function cumulatively tests whether at least n elements in a provided var actual; var x; - function fcn( v ) { - return v > 0; - } - x = new Float64Array( [ 0.0, 0.0, 1.0, 1.0, 0.0 ] ); - actual = cusomeByRight( x, 2, fcn ); + actual = cusomeByRight( x, 2, isPositive ); expected = [ false, false, true, true, true ]; t.deepEqual( actual, expected, 'returns expected value' ); x = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); - actual = cusomeByRight( x, 2, fcn ); + actual = cusomeByRight( x, 2, isPositive ); expected = [ false, false, false, false, false ]; t.deepEqual( actual, expected, 'returns expected value' ); x = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ); - actual = cusomeByRight( x, 2, fcn ); + actual = cusomeByRight( x, 2, isPositive ); expected = [ false, true, true, true, true ]; t.deepEqual( actual, expected, 'returns expected value' ); x = new Float64Array( [ 0.0, 1.0, 0.0 ] ); - actual = cusomeByRight( x, 1, fcn ); + actual = cusomeByRight( x, 1, isPositive ); expected = [ false, true, true ]; t.deepEqual( actual, expected, 'returns expected value' ); x = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 1.0 ] ); - actual = cusomeByRight( x, 1, fcn ); + actual = cusomeByRight( x, 1, isPositive ); expected = [ true, true, true, true, true ]; t.deepEqual( actual, expected, 'returns expected value' ); @@ -112,33 +112,29 @@ tape( 'the function cumulatively tests whether at least n elements in a provided var actual; var x; - function fcn( v ) { - return v > 0; - } - x = toAccessorArray( [ 1, 1, 0, 0, 0 ] ); - actual = cusomeByRight( x, 2, fcn ); + actual = cusomeByRight( x, 2, isPositive ); expected = [ false, false, false, false, true ]; t.deepEqual( actual, expected, 'returns expected value' ); x = toAccessorArray( [ 0, 0, 0, 0, 0 ] ); - actual = cusomeByRight( x, 1, fcn ); + actual = cusomeByRight( x, 1, isPositive ); expected = [ false, false, false, false, false ]; t.deepEqual( actual, expected, 'returns expected value' ); x = toAccessorArray( [ 1, 1, 1, 1, 1 ] ); - actual = cusomeByRight( x, 1, fcn ); + actual = cusomeByRight( x, 1, isPositive ); expected = [ true, true, true, true, true ]; t.deepEqual( actual, expected, 'returns expected value' ); x = toAccessorArray( [ 0, 0, 1 ] ); - actual = cusomeByRight( x, 1, fcn ); + actual = cusomeByRight( x, 1, isPositive ); expected = [ true, true, true ]; t.deepEqual( actual, expected, 'returns expected value' ); x = toAccessorArray( [ 1, 0, 0, 0, 0 ] ); - actual = cusomeByRight( x, 1, fcn ); + actual = cusomeByRight( x, 1, isPositive ); expected = [ false, false, false, false, true ]; t.deepEqual( actual, expected, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/array/base/cusome/README.md b/lib/node_modules/@stdlib/array/base/cusome/README.md new file mode 100644 index 00000000000..cbc394963f4 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cusome/README.md @@ -0,0 +1,114 @@ + + +# cusome + +> Cumulatively test whether at least `n` array elements in a provided array are truthy. + +
+ +## Usage + +```javascript +var cusome = require( '@stdlib/array/base/cusome' ); +``` + +#### cusome( x, n ) + +Cumulatively tests whether at least `n` array elements in a provided array are truthy. + +```javascript +var x = [ false, false, false, true, true ]; + +var y = cusome( x, 2 ); +// returns [ false, false, false, false, true ]; +``` + +#### cusome.assign( x, n, y, stride, offset ) + +Cumulatively tests whether at least `n` array elements in a provided array are truthy and assigns results to a provided output array. + +```javascript +var x = [ false, false, false, true, true ]; +var y = [ false, null, false, null, false, null, false, null, false, null ]; + +var out = cusome.assign( x, 2, y, 2, 0 ); +// returns [ false, null, false, null, false, null, false, null, true, null ] + +var bool = ( out === y ); +// returns true +``` + +The function supports the following parameters: + +- **x**: input array. +- **n**: number of elements. +- **out**: output array. +- **stride**: output array stride. +- **offset**: output array offset. + +
+ + + +
+ +
+ + + +
+ +## Examples + + + +```javascript +var bernoulli = require( '@stdlib/random/array/bernoulli' ); +var cusome = require( '@stdlib/array/base/cusome' ); + +// Create an array of random values: +var x = bernoulli( 10, 0.3 ); +console.log( x ); + +// Cumulatively test whether at least two array elements are truthy: +var out = cusome( x, 2 ); +console.log( out ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/array/base/cusome/benchmark/benchmark.assign.length.js b/lib/node_modules/@stdlib/array/base/cusome/benchmark/benchmark.assign.length.js new file mode 100644 index 00000000000..e0e43ff4e77 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cusome/benchmark/benchmark.assign.length.js @@ -0,0 +1,98 @@ +/** +* @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 pow = require( '@stdlib/math/base/special/pow' ); +var isArray = require( '@stdlib/assert/is-array' ); +var filled = require( '@stdlib/array/base/filled' ); +var pkg = require( './../package.json' ).name; +var cusome = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = filled( 0, len ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var y; + var v; + var i; + + y = filled( true, len ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = cusome.assign( x, 2, y, 1, 0 ); + if ( typeof v !== 'object' ) { + b.fail( 'should return an array' ); + } + } + b.toc(); + if ( !isArray( v ) ) { + b.fail( 'should return an array' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':assign:len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/base/cusome/benchmark/benchmark.js b/lib/node_modules/@stdlib/array/base/cusome/benchmark/benchmark.js new file mode 100644 index 00000000000..416e480616d --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cusome/benchmark/benchmark.js @@ -0,0 +1,51 @@ +/** +* @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 isArray = require( '@stdlib/assert/is-array' ); +var pkg = require( './../package.json' ).name; +var cusome = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var x; + var i; + var v; + + x = [ false, false, true, false, false ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = cusome( x, 2 ); + if ( typeof v !== 'object' ) { + b.fail( 'should return an array' ); + } + } + b.toc(); + if ( !isArray( v ) ) { + b.fail( 'should return an array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/base/cusome/benchmark/benchmark.length.js b/lib/node_modules/@stdlib/array/base/cusome/benchmark/benchmark.length.js new file mode 100644 index 00000000000..557079bf781 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cusome/benchmark/benchmark.length.js @@ -0,0 +1,95 @@ +/** +* @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 pow = require( '@stdlib/math/base/special/pow' ); +var isArray = require( '@stdlib/assert/is-array' ); +var filled = require( '@stdlib/array/base/filled' ); +var pkg = require( './../package.json' ).name; +var cusome = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = filled( 0, len ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = cusome( x, 2 ); + if ( typeof v !== 'object' ) { + b.fail( 'should return an array' ); + } + } + b.toc(); + if ( !isArray( v ) ) { + b.fail( 'should return an array' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/base/cusome/docs/repl.txt b/lib/node_modules/@stdlib/array/base/cusome/docs/repl.txt new file mode 100644 index 00000000000..417ea0e2ec4 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cusome/docs/repl.txt @@ -0,0 +1,61 @@ + +{{alias}}( x, n ) + Cumulatively tests whether at least `n` array elements in a provided array + are truthy. + + Parameters + ---------- + x: ArrayLikeObject + Input array. + + n: integer + Number of elements. + + Returns + ------- + out: Array + Output array. + + Examples + -------- + > var x = [ false, false, false, true, true ]; + > var y = {{alias}}( x, 2 ) + [ false, false, false, false, true ]; + + +{{alias}}.assign( x, n, y, stride, offset ) + Cumulatively tests whether at least `n` array elements in a provided array + are truthy and assigns results to provided output array. + + Parameters + ---------- + x: ArrayLikeObject + Input array. + + n: integer + Number of elements. + + y: ArrayLikeObject + Output array. + + stride: integer + Output array stride. + + offset: integer + Output array offset. + + Returns + ------- + y: ArrayLikeObject + Output array. + + Examples + -------- + > var x = [ false, false, false, true, true ]; + > var y = [ false, null, false, null, false, null, true, null, false ]; + > var result = {{alias}}.assign( x, 2, y, 2, 0 ) + [ false, null, false, null, false, null, false, null, true ]; + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/array/base/cusome/docs/types/index.d.ts b/lib/node_modules/@stdlib/array/base/cusome/docs/types/index.d.ts new file mode 100644 index 00000000000..8051d003639 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cusome/docs/types/index.d.ts @@ -0,0 +1,89 @@ +/* +* @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 { Collection, AccessorArrayLike } from '@stdlib/types/array'; + +/** +* Interface describing `cusome`. +*/ +interface cusome { + /** + * Cumulatively tests whether at least `n` array elements in a provided array are truthy. + * + * @param x - input array + * @param n - number of elements + * @returns output array + * + * @example + * var x = [ false, false, false, true, true ]; + * + * var y = cusome( x, 2 ); + * // returns [ false, false, false, false, true ]; + */ + ( x: Collection | AccessorArrayLike, n: number ): Array; + + /** + * Cumulatively tests whether at least `n` array elements in a provided array are truthy and assigns the results to a provided output array. + * + * @param x - input array + * @param n - number of elements + * @param y - output array + * @param stride - output array stride + * @param offset - output array offset + * @returns output array + * + * @example + * var x = [ false, false, false, true, true ]; + * var y = [ false, null, false, null, false, null, false, null, false, null ]; + * + * var arr = cusome.assign( x, 2, y, 2, 0 );, + * // returns [ false, null, false, null, false, null, false, null, true, null ]; + */ + assign | AccessorArrayLike>( x: Collection | AccessorArrayLike, n: number, y: U, stride: number, offset: number ): U; +} + +/** +* Cumulatively tests whether at least `n` array elements in a provided array are truthy. +* +* @param x - input array +* @param n - number of elements +* @returns output array +* +* @example +* var x = [ false, false, false, true, true ]; +* +* var result = cusome( x, 2 ); +* // returns [ false, false, false, false, true ]; +* +* @example +* var x = [ false, false, false, true, true ]; +* var y = [ false, null, false, null, false, null, false, null, false, null ]; +* +* var arr = cusome.assign( x, y, 2, 0 ); +* // returns [ false, null, false, null, false, null, false, null, true, null ]; +*/ +declare var cusome: cusome; + + +// EXPORTS // + +export = cusome; diff --git a/lib/node_modules/@stdlib/array/base/cusome/docs/types/test.ts b/lib/node_modules/@stdlib/array/base/cusome/docs/types/test.ts new file mode 100644 index 00000000000..45d3da57065 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cusome/docs/types/test.ts @@ -0,0 +1,137 @@ +/* +* @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 cusome = require( './index' ); + + +// TESTS // + +// The function returns an array... +{ + cusome( [false, false, true, false, false], 2 ); // $ExpectType boolean[] + cusome( [ false, false, true, false, false ], 1 ); // $ExpectType boolean[] +} + +// The compiler throws an error if the function is provided a first argument which is not an array-like object... +{ + cusome( 1, 2 ); // $ExpectError + cusome( true, 2 ); // $ExpectError + cusome( false, 2 ); // $ExpectError + cusome( null, 2 ); // $ExpectError + cusome( void 0, 2 ); // $ExpectError + cusome( {}, 2 ); // $ExpectError + cusome( undefined, 2 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a number... +{ + cusome( [ true, false, true ], true ); // $ExpectError + cusome( [ true, false, true ], false ); // $ExpectError + cusome( [ true, false, true ], null ); // $ExpectError + cusome( [ true, false, true ], [] ); // $ExpectError + cusome( [ true, false, true ], {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + cusome(); // $ExpectError + cusome( [] ); // $ExpectError + cusome( [], [], [] ); // $ExpectError +} + +// Attached to the main export is an `assign` method which returns a collection... +{ + const x = [ false, false, true, false, false ]; + const y = [ false, null, false, null, false, null, false, null, false, null ]; + + cusome.assign( x, 2, y, 2, 0 ); // $ExpectType (boolean | null)[] +} + +// The compiler throws an error if the `assign` method is provided a first argument which is not an array-like object... +{ + const y = [ false, false, true, false, false ]; + + cusome.assign( 1, 2, y, 2, 0 ); // $ExpectError + cusome.assign( true, 2, y, 2, 0 ); // $ExpectError + cusome.assign( false, 2, y, 2, 0 ); // $ExpectError + cusome.assign( null, 2, y, 2, 0 ); // $ExpectError + cusome.assign( void 0, 2, y, 2, 0 ); // $ExpectError + cusome.assign( {}, 2, y, 2, 0 ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a second argument which is not an number... +{ + const x = [ false, false, true, false, false ]; + const y = [false, false, true, false, false]; + + cusome.assign( x, undefined, y, 2, 0 ); // $ExpectError + cusome.assign( x, true, y, 2, 0 ); // $ExpectError + cusome.assign( x, false, y, 2, 0 ); // $ExpectError + cusome.assign( x, null, y, 2, 0 ); // $ExpectError + cusome.assign( x, void 0, y, 2, 0 ); // $ExpectError + cusome.assign( x, {}, y, 2, 0 ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a third argument which is not an array-like object... +{ + const x = [ false, false, true, false, false ]; + + cusome.assign( x, 2, true, 2, 0 ); // $ExpectError + cusome.assign( x, 2, false, 2, 0 ); // $ExpectError + cusome.assign( x, 2, null, 2, 0 ); // $ExpectError + cusome.assign( x, 2, void 0, 2, 0 ); // $ExpectError + cusome.assign( x, 2, {}, 2, 0 ); // $ExpectError + cusome.assign( x, 2, undefined, 2, 0 ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a fourth argument which is not a number... +{ + const x = [ false, false, true, false, false ]; + const y = [ false, null, false, null, false, null, false, null, false, null ]; + + cusome.assign( x, 2, y, true, 2 ); // $ExpectError + cusome.assign( x, 2, y, false, 2 ); // $ExpectError + cusome.assign( x, 2, y, null, 2 ); // $ExpectError + cusome.assign( x, 2, y, void 0, 2 ); // $ExpectError + cusome.assign( x, 2, y, {}, 2 ); // $ExpectError + cusome.assign( x, 2, y, undefined, 2 ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a fifth argument which is not a number... +{ + const x = [ false, false, true, false, false ]; + const y = [ false, null, false, null, false, null, false, null, false, null ]; + + cusome.assign( x, 2, y, 1, '1' ); // $ExpectError + cusome.assign( x, 1, y, 1, true ); // $ExpectError + cusome.assign( x, 2, y, 1, false ); // $ExpectError + cusome.assign( x, 1, y, 1, null ); // $ExpectError + cusome.assign( x, 2, y, 1, void 0 ); // $ExpectError + cusome.assign( x, 1, y, 1, {} ); // $ExpectError + cusome.assign( x, 2, y, 1, [] ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... +{ + cusome.assign(); // $ExpectError + cusome.assign( [] ); // $ExpectError + cusome.assign( [], [] ); // $ExpectError + cusome.assign( [], [], 2 ); // $ExpectError + cusome.assign( [], [], 1, 1, {}, {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/array/base/cusome/examples/index.js b/lib/node_modules/@stdlib/array/base/cusome/examples/index.js new file mode 100644 index 00000000000..50680580d52 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cusome/examples/index.js @@ -0,0 +1,30 @@ +/** +* @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 bernoulli = require( '@stdlib/random/array/bernoulli' ); +var cusome = require( './../lib' ); + +// Create an array of random values: +var x = bernoulli( 10, 0.3 ); +console.log( x ); + +// Cumulatively test whether at least two array elements are truthy: +var out = cusome( x, 2 ); +console.log( out ); diff --git a/lib/node_modules/@stdlib/array/base/cusome/lib/assign.js b/lib/node_modules/@stdlib/array/base/cusome/lib/assign.js new file mode 100644 index 00000000000..c58f1a37974 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cusome/lib/assign.js @@ -0,0 +1,309 @@ +/** +* @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 isComplex128Array = require( '@stdlib/array/base/assert/is-complex128array' ); +var isComplex64Array = require( '@stdlib/array/base/assert/is-complex64array' ); +var isBooleanArray = require( '@stdlib/array/base/assert/is-booleanarray' ); +var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +var reinterpret128 = require( '@stdlib/strided/base/reinterpret-complex128' ); +var reinterpret64 = require( '@stdlib/strided/base/reinterpret-complex64' ); +var reinterpretBoolean = require( '@stdlib/strided/base/reinterpret-boolean' ); + + +// FUNCTIONS // + +/** +* Cumulatively tests whether at least `n` array elements in a provided array are truthy. +* +* @private +* @param {Collection} x - input array +* @param {integer} n - number of elements +* @param {Collection} y - output array +* @param {integer} stride - output array stride +* @param {NonNegativeInteger} offset - output array offset +* @returns {Collection} output array +* +* @example +* var x = [ false, false, false, true, true ]; +* var y = [ false, null, false, null, false, null, false, null, false, null ]; +* +* var out = indexed( x, 2, y, 2, 0 ); +* // returns [ false, null, false, null, false, null, false, null, true, null ] +*/ +function indexed( x, n, y, stride, offset ) { + var flg; + var io; + var i; + + flg = false; + io = offset; + for ( i = 0; i < x.length; i++ ) { + if ( !flg && x[ i ] ) { + n -= 1; + if ( n <= 0 ) { + flg = true; + } + } + y[ io ] = flg; + io += stride; + } + return y; +} + +/** +* Cumulatively tests whether at least `n` array elements in accessor array are truthy. +* +* @private +* @param {Object} x - input array object +* @param {integer} n - number of elements +* @param {Object} y - output array object +* @param {integer} stride - output array stride +* @param {NonNegativeInteger} offset - output array offset +* @returns {Collection} output array +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +* +* var x = toAccessorArray( [ false, false, false, true, true ] ); +* var y = toAccessorArray( [ false, null, false, null, false, null, false, null, true, null ] ); +* +* var arr = accessors( arraylike2object( x ), 2, arraylike2object( y ), 2, 0 ); +* +* var v = y.get( 0 ); +* // returns false +* +* v = y.get( 2 ); +* // returns false +* +* v = y.get( 4 ); +* // returns false +* +* v = y.get( 6 ); +* // returns false +* +* v = y.get( 8 ); +* // returns true +*/ +function accessors( x, n, y, stride, offset ) { + var xdata; + var ydata; + var xget; + var yset; + var flg; + var io; + var i; + + xdata = x.data; + ydata = y.data; + + xget = x.accessors[ 0 ]; + yset = y.accessors[ 1 ]; + + flg = false; + io = offset; + for ( i = 0; i < xdata.length; i++ ) { + if ( !flg && xget( xdata, i ) ) { + n -= 1; + if ( n <= 0 ) { + flg = true; + } + } + + yset( ydata, io, flg ); + io += stride; + } + return ydata; +} + +/** +* Cumulatively tests whether at least `n` array elements in a provided complex number are truthy and assigns results to provided output array. +* +* @private +* @param {Collection} x - array containing interleaved real and imaginary components +* @param {integer} n - number of elements +* @param {Object} y - output array object +* @param {integer} stride - output array stride +* @param {NonNegativeInteger} offset - output array offset +* @returns {Collection} output array +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +* +* var x = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0 ] ); +* var y = toAccessorArray( [ false, null, false, null, false, null, false, null, false, null ] ); +* +* var arr = complex( x, 2, arraylike2object( y ), 2, 0 ); +* +* var v = y.get( 0 ); +* // returns false +* +* v = y.get( 2 ); +* // returns false +* +* v = y.get( 4 ); +* // returns false +* +* v = y.get( 6 ); +* // returns false +* +* v = y.get( 8 ); +* // returns false +*/ +function complex( x, n, y, stride, offset ) { + var ydata; + var yset; + var flg; + var io; + var i; + + yset = y.accessors[ 1 ]; + ydata = y.data; + + flg = false; + io = offset; + for ( i = 0; i < x.length; i += 2 ) { + if ( !flg && ( x[ i ] || x[ i+1 ] ) ) { + n -= 1; + if ( n <= 0 ) { + flg = true; + } + } + yset( ydata, io, flg ); + io += stride; + } + return ydata; +} + +/** +* Cumulatively tests whether at least `n` array elements in a provided array are truthy. +* +* @private +* @param {Collection} x - input array +* @param {integer} n - number of elements +* @param {Object} y - output array object +* @param {integer} stride - output array stride +* @param {NonNegativeInteger} offset - output array offset +* @returns {Collection} output array +* +* @example +* var Uint8Array = require( '@stdlib/array/uint8' ); +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +* +* var x = new Uint8Array( [ 0, 0, 0, 1, 0 ] ); +* var y = toAccessorArray( [ false, null, false, null, false, null, false, null, false, null ] ); +* +* var arr = boolean( x, 2, arraylike2object( y ), 2, 0 ); +* +* var v = y.get( 0 ); +* // returns false +* +* v = y.get( 2 ); +* // returns false +* +* v = y.get( 4 ); +* // returns false +* +* v = y.get( 6 ); +* // returns false +* +* v = y.get( 8 ); +* // returns false +*/ +function boolean( x, n, y, stride, offset ) { + var ydata; + var yset; + var flg; + var io; + var i; + + yset = y.accessors[ 1 ]; + ydata = y.data; + + flg = false; + io = offset; + for ( i = 0; i < x.length; i++ ) { + if ( !flg && x[ i ] ) { + n -= 1; + if ( n <= 0 ) { + flg = true; + } + } + yset( ydata, io, flg ); + io += stride; + } + return ydata; +} + + +// MAIN // + +/** +* Cumulatively tests whether at least `n` array elements in a provided array are truthy and assigns results to provided output array. +* +* @param {Collection} x - input array +* @param {integer} n - number of elements +* @param {Collection} y - output array +* @param {integer} stride - output array stride +* @param {NonNegativeInteger} offset - output array offset +* @returns {Collection} output array +* +* @example +* var x = [ false, false, false, true, true ]; +* var y = [ false, null, false, null, false, null, false, null, false, null ]; +* +* var out = assign( x, 2, y, 2, 0 ); +* // returns [ false, null, false, null, false, null, false, null, true, null ] +* +* var bool = ( y === out ); +* // returns true +*/ +function assign( x, n, y, stride, offset ) { + var xo = arraylike2object( x ); + var yo = arraylike2object( y ); + if ( + xo.accessorProtocol || + yo.accessorProtocol + ) { + // If provided a complex number array, reinterpret as a real typed array and test interleaved real and imaginary components, where we consider a complex number to be truthy if at least one component is non-zero... + if ( isComplex128Array( x ) ) { + return complex( reinterpret128( x, 0 ), n, yo, stride, offset ); + } + if ( isComplex64Array( x ) ) { + return complex( reinterpret64( x, 0 ), n, yo, stride, offset ); + } + if ( isBooleanArray( x ) ) { + return boolean( reinterpretBoolean( x, 0 ), n, yo, stride, offset ); + } + return accessors( xo, n, yo, stride, offset ); + } + indexed( x, n, y, stride, offset ); + return y; +} + + +// EXPORTS // + +module.exports = assign; diff --git a/lib/node_modules/@stdlib/array/base/cusome/lib/index.js b/lib/node_modules/@stdlib/array/base/cusome/lib/index.js new file mode 100644 index 00000000000..43203f52928 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cusome/lib/index.js @@ -0,0 +1,58 @@ +/** +* @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'; + +/** +* Cumulatively test whether at least `n` array elements in a provided array are truthy. +* +* @module @stdlib/array/base/cusome +* +* @example +* var cusome = require( '@stdlib/array/base/cusome' ); +* +* var x = [ false, false, false, true, true ]; +* +* var y = cusome( x, 2 ); +* // returns [ false, false, false, false, true ] +* +* @example +* var cusome = require( '@stdlib/array/base/cusome' ); +* +* var x = [ false, false, false, true, true ]; +* var y = [ false, null, false, null, false, null, false, null, false, null ]; +* +* var arr = cusome.assign( x, 2, y, 2, 0 ); +* // returns [ false, null, false, null, false, null, false, null, true, null ] +*/ + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var main = require( './main.js' ); +var assign = require( './assign.js' ); + + +// MAIN // + +setReadOnly( main, 'assign', assign ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/array/base/cusome/lib/main.js b/lib/node_modules/@stdlib/array/base/cusome/lib/main.js new file mode 100644 index 00000000000..4ba62ce4461 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cusome/lib/main.js @@ -0,0 +1,50 @@ +/** +* @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 filled = require( '@stdlib/array/base/filled' ); +var assign = require( './assign.js' ); + + +// MAIN // + +/** +* Cumulatively tests whether at least `n` array elements in a provided array are truthy. +* +* @param {Collection} x - input array +* @param {integer} n - number of elements +* @returns {Array} output array +* +* @example +* var x = [ false, false, false, true, true ]; +* +* var y = cusome( x, 2 ); +* // returns [ false, false, false, false, true ] +*/ +function cusome( x, n ) { + var y = filled( true, x.length ); + return assign( x, n, y, 1, 0 ); +} + + +// EXPORTS // + +module.exports = cusome; diff --git a/lib/node_modules/@stdlib/array/base/cusome/package.json b/lib/node_modules/@stdlib/array/base/cusome/package.json new file mode 100644 index 00000000000..69a917f9073 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cusome/package.json @@ -0,0 +1,67 @@ +{ + "name": "@stdlib/array/base/cusome", + "version": "0.0.0", + "description": "Cumulatively test whether at least `n` array elements in a provided array are truthy.", + "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", + "stdtypes", + "types", + "data", + "structure", + "utils", + "generic", + "array", + "cusome", + "cumulative", + "test", + "every", + "array.every", + "validate" + ] +} diff --git a/lib/node_modules/@stdlib/array/base/cusome/test/test.assign.js b/lib/node_modules/@stdlib/array/base/cusome/test/test.assign.js new file mode 100644 index 00000000000..367e35861c3 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cusome/test/test.assign.js @@ -0,0 +1,400 @@ +/** +* @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 Complex128Array = require( '@stdlib/array/complex128' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var BooleanArray = require( '@stdlib/array/bool' ); +var Float64Array = require( '@stdlib/array/float64' ); +var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var cusome = require( './../lib/assign.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof cusome, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function cumulatively tests whether at least `n` array elements are truthy (generic)', function test( t ) { + var expected; + var actual; + var x; + var y; + + x = [ false, false, false, true, false ]; + y = [ false, true, false, true, false ]; + + actual = cusome( x, 1, y, 1, 0 ); + expected = [ false, false, false, true, true ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = [ false, false, true, false, false ]; + y = [ false, null, false, null, true, null, true, null, true, null ]; + + actual = cusome( x, 1, y, 2, 0 ); + expected = [ false, null, false, null, true, null, true, null, true, null ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = [ false, false, true, false, false ]; + y = [ false, false, false, true, true, true ]; + + actual = cusome( x, 2, y, 1, 1 ); + expected = [ false, false, false, false, false, false ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = []; + y = [ false, false, false, false, false ]; + + actual = cusome( x, 2, y, 1, 0 ); + expected = [ false, false, false, false, false ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = [ false ]; + y = [ false, false ]; + + actual = cusome( x, 1, y, 1, 1 ); + expected = [ false, false ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function cumulatively tests whether at least `n` array elements are truthy (typed)', function test( t ) { + var expected; + var actual; + var x; + var y; + + x = new Float64Array( [ 1.0, 0.0, 1.0, 0.0, 1.0 ] ); + y = [ false, true, false, true, false ]; + + actual = cusome( x, 1, y, 1, 0 ); + expected = [ true, true, true, true, true ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Float64Array( [ 0.0, 0.0, 1.0, 0.0, 0.0 ] ); + y = [ false, null, false, null, false, null, false, null, false, null ]; + + actual = cusome( x, 2, y, 2, 0 ); + expected = [ + false, null, false, null, false, null, false, null, false, null + ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Float64Array( [ 0.0, 0.0, 1.0, 0.0, 0.0 ] ); + y = [ false, false, false, true, true, true ]; + + actual = cusome( x, 1, y, 1, 1 ); + expected = [ false, false, false, true, true, true ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Float64Array( [] ); + y = [ false, false, false, false, false ]; + + actual = cusome( x, 2, y, 1, 0 ); + expected = [ false, false, false, false, false ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Float64Array( [ 1.0 ] ); + y = [ false, false ]; + + actual = cusome( x, 1, y, 1, 1 ); + expected = [ false, true ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function cumulatively tests whether at least `n` array elements are truthy (boolean)', function test( t ) { + var expected; + var actual; + var x; + var y; + + x = new BooleanArray( [ true, true, true, true, true ] ); + y = [ false, true, false, true, false ]; + + actual = cusome( x, 1, y, 1, 0 ); + expected = [ true, true, true, true, true ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new BooleanArray( [ false, false, true, false, false ] ); + y = [ false, null, false, null, false, null, false, null, false, null ]; + + actual = cusome( x, 2, y, 2, 0 ); + expected = [ + false, null, false, null, false, null, false, null, false, null + ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new BooleanArray( [ false, false, true, false, false ] ); + y = [ false, false, false, true, true, true ]; + + actual = cusome( x, 1, y, 1, 1 ); + expected = [ false, false, false, true, true, true ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new BooleanArray( [] ); + y = [ false, false, false, false, false ]; + + actual = cusome( x, 1, y, 1, 0 ); + expected = [ false, false, false, false, false ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new BooleanArray( [ true ] ); + y = [ false, false ]; + + actual = cusome( x, 1, y, 1, 1 ); + expected = [ false, true ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function cumulatively tests whether at least `n` array elements are truthy (complex128)', function test( t ) { + var expected; + var actual; + var x; + var y; + + x = new Complex128Array([ + 1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0 + ]); + y = [ false, true, false, true, false ]; + + actual = cusome( x, 1, y, 1, 0 ); + expected = [ true, true, true, true, true ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Complex128Array([ + 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0 + ]); + y = [ false, null, false, null, false, null, false, null, false, null ]; + + actual = cusome( x, 2, y, 2, 0 ); + expected = [ + false, null, false, null, false, null, false, null, false, null + ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Complex128Array([ + 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0 + ]); + y = [ false, false, false, true, true, true ]; + + actual = cusome( x, 1, y, 1, 1 ); + expected = [ false, false, false, true, true, true ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Complex128Array( [] ); + y = [ false, false, false, false, false ]; + + actual = cusome( x, 2, y, 1, 0 ); + expected = [ false, false, false, false, false ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Complex128Array( [ 1.0, 1.0 ] ); + y = [ false, false ]; + + actual = cusome( x, 1, y, 1, 1 ); + expected = [ false, true ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function cumulatively tests whether at least `n` array elements are truthy (complex64)', function test( t ) { + var expected; + var actual; + var x; + var y; + + x = new Complex64Array([ + 0.0, 1.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0 + ]); + y = [ false, true, false, true, false ]; + + actual = cusome( x, 1, y, 1, 0 ); + expected = [ true, true, true, true, true ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Complex64Array([ + 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0 + ]); + y = [ false, null, false, null, false, null, false, null, false, null ]; + + actual = cusome( x, 2, y, 2, 0 ); + expected = [ + false, null, false, null, false, null, false, null, false, null + ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Complex64Array([ + 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0 + ]); + y = [ false, false, false, true, true, true ]; + + actual = cusome( x, 1, y, 1, 1 ); + expected = [ false, false, false, true, true, true ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Complex64Array( [] ); + y = [ false, false, false, false, false ]; + + actual = cusome( x, 1, y, 1, 0 ); + expected = [ false, false, false, false, false ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Complex64Array( [ 1.0, 1.0 ] ); + y = [ false, false ]; + + actual = cusome( x, 1, y, 1, 1 ); + expected = [ false, true ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function cumulatively tests whether at least `n` array elements are truthy (accessor)', function test( t ) { + var expected; + var actual; + var ybuf; + var x; + var y; + + x = toAccessorArray( [ true, false, true, false, true ] ); + ybuf = [ false, true, false, true, false ]; + y = toAccessorArray( ybuf ); + + actual = cusome( x, 1, y, 1, 0 ); + expected = [ true, true, true, true, true ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ybuf, expected, 'returns expected value' ); + + x = toAccessorArray( [ false, false, true, false, false ] ); + ybuf = [ false, null, false, null, false, null, false, null, false, null ]; + y = toAccessorArray( ybuf ); + + actual = cusome( x, 2, y, 2, 0 ); + expected = [ + false, null, false, null, false, null, false, null, false, null + ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ybuf, expected, 'returns expected value' ); + + x = toAccessorArray( [ false, false, true, false, false ] ); + ybuf = [ false, false, false, false, false, false ]; + y = toAccessorArray( ybuf ); + + actual = cusome( x, 1, y, 1, 1 ); + expected = [ false, false, false, true, true, true ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ybuf, expected, 'returns expected value' ); + + x = toAccessorArray( [ true, false, false, false, false ] ); + ybuf = [ false, false, false, false, false ]; + y = toAccessorArray( ybuf ); + + actual = cusome( x, 1, y, 1, 0 ); + expected = [ true, true, true, true, true ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ybuf, expected, 'returns expected value' ); + + x = toAccessorArray( [] ); + ybuf = [ false, false, false, false, false ]; + y = toAccessorArray( ybuf ); + + actual = cusome( x, 2, y, 1, 0 ); + expected = [ false, false, false, false, false ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ybuf, expected, 'returns expected value' ); + + x = toAccessorArray( [ true ] ); + ybuf = [ false, false ]; + y = toAccessorArray( ybuf ); + + actual = cusome( x, 1, y, 1, 1 ); + expected = [ false, true ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ybuf, expected, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/array/base/cusome/test/test.js b/lib/node_modules/@stdlib/array/base/cusome/test/test.js new file mode 100644 index 00000000000..2924a728ba7 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cusome/test/test.js @@ -0,0 +1,41 @@ +/** +* @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 hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var hasMethod = require( '@stdlib/assert/is-method' ); +var cusome = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof cusome, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is an `assign` method', function test( t ) { + t.strictEqual( hasOwnProp( cusome, 'assign' ), true, 'returns expected value' ); + t.strictEqual( hasMethod( cusome, 'assign' ), true, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/array/base/cusome/test/test.main.js b/lib/node_modules/@stdlib/array/base/cusome/test/test.main.js new file mode 100644 index 00000000000..6e93aa5d4bf --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cusome/test/test.main.js @@ -0,0 +1,252 @@ +/** +* @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 Complex128Array = require( '@stdlib/array/complex128' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var BooleanArray = require( '@stdlib/array/bool' ); +var Float64Array = require( '@stdlib/array/float64' ); +var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var cusome = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof cusome, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function cumulatively tests whether at least `n` array elements are truthy (generic)', function test( t ) { + var expected; + var actual; + var x; + + x = [ false, false, false, true, false ]; + actual = cusome( x, 2 ); + expected = [ false, false, false, false, false ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; + actual = cusome( x, 1 ); + expected = [ false, false, false, false, false ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = [ true, true, true, true, true ]; + actual = cusome( x, 2 ); + expected = [ false, true, true, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = [ null, {}, null ]; + actual = cusome( x, 1 ); + expected = [ false, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = [ true, false, false, true, false ]; + actual = cusome( x, 1); + expected = [ true, true, true, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function cumulatively tests whether at least `n` array elements are truthy (typed)', function test( t ) { + var expected; + var actual; + var x; + + x = new Float64Array( [ 0.0, 0.0, 1.0, 0.0, 0.0 ] ); + actual = cusome( x, 1 ); + expected = [ false, false, true, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Float64Array( [ 0.0, 1.0, 1.0, 0.0, 0.0 ] ); + actual = cusome( x, 1 ); + expected = [ false, true, true, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ); + actual = cusome( x, 1 ); + expected = [ true, true, true, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Float64Array( [ 0.0, 1.0, 0.0 ] ); + actual = cusome( x, 1 ); + expected = [ false, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Float64Array( [ 1.0, 0.0, 0.0, 0.0, 0.0 ] ); + actual = cusome( x, 1); + expected = [ true, true, true, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function cumulatively tests whether at least `n` array elements are truthy (boolean)', function test( t ) { + var expected; + var actual; + var x; + + x = new BooleanArray( [ false, false, true, false, false ] ); + actual = cusome( x, 2 ); + expected = [ false, false, false, false, false ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new BooleanArray( [ false, false, false, false, false ] ); + actual = cusome( x, 1); + expected = [ false, false, false, false, false ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new BooleanArray( [ true, true, true, true, true ] ); + actual = cusome( x, 2 ); + expected = [ false, true, true, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new BooleanArray( [ false, true, true ] ); + actual = cusome( x, 1 ); + expected = [ false, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new BooleanArray( [ true, false, true, false, false ] ); + actual = cusome( x, 2); + expected = [ false, false, true, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function cumulatively tests whether at least `n` array elements are truthy (complex128)', function test( t ) { + var expected; + var actual; + var x; + + x = new Complex128Array([ + 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0 + ]); + actual = cusome( x, 1 ); + expected = [ false, false, true, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Complex128Array([ + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 + ]); + actual = cusome( x, 1 ); + expected = [ false, false, false, false, false ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Complex128Array([ + 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 + ]); + actual = cusome( x, 2 ); + expected = [ false, true, true, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Complex128Array( [ 0.0, 0.0, 0.0, 1.0, 1.0, 0.0 ] ); + actual = cusome( x, 1); + expected = [ false, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Complex128Array([ + 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0 + ]); + actual = cusome( x, 2); + expected = [ false, false, true, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function cumulatively tests whether at least `n` array elements are truthy (complex64)', function test( t ) { + var expected; + var actual; + var x; + + x = new Complex64Array([ + 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0 + ]); + actual = cusome( x, 1 ); + expected = [ false, false, true, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Complex64Array([ + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 + ]); + actual = cusome( x, 1 ); + expected = [ false, false, false, false, false ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Complex64Array([ + 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 + ]); + actual = cusome( x, 2 ); + expected = [ false, true, true, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Complex64Array( [ 0.0, 0.0, 0.0, 1.0, 1.0, 0.0 ] ); + actual = cusome( x, 1); + expected = [ false, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Complex64Array([ + 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0 + ]); + actual = cusome( x, 2); + expected = [ false, false, true, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function cumulatively tests whether at least `n` array elements are truthy (accessor)', function test( t ) { + var expected; + var actual; + var x; + + x = new toAccessorArray( [ false, false, true, false, false ] ); + actual = cusome( x, 2 ); + expected = [ false, false, false, false, false ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new toAccessorArray( [ false, false, false, false, false ] ); + actual = cusome( x, 1); + expected = [ false, false, false, false, false ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new toAccessorArray( [ true, true, true, true, true ] ); + actual = cusome( x, 2 ); + expected = [ false, true, true, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new toAccessorArray( [ false, true, true ] ); + actual = cusome( x, 1 ); + expected = [ false, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new toAccessorArray( [ true, false, true, false, false ] ); + actual = cusome( x, 2); + expected = [ false, false, true, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/array/base/getter/docs/repl.txt b/lib/node_modules/@stdlib/array/base/getter/docs/repl.txt index 4e0b3b30133..163b05ff3db 100644 --- a/lib/node_modules/@stdlib/array/base/getter/docs/repl.txt +++ b/lib/node_modules/@stdlib/array/base/getter/docs/repl.txt @@ -5,8 +5,8 @@ An accessor function accepts the following arguments: - - arr: input array - - idx: element index + - arr: input array. + - idx: element index. If provided an unsupported `dtype`, the function returns a default accessor function for accessing elements from any indexed array-like object. diff --git a/lib/node_modules/@stdlib/array/base/lib/index.js b/lib/node_modules/@stdlib/array/base/lib/index.js index 6612effb132..f2e24f3c0a8 100644 --- a/lib/node_modules/@stdlib/array/base/lib/index.js +++ b/lib/node_modules/@stdlib/array/base/lib/index.js @@ -1116,6 +1116,15 @@ setReadOnly( ns, 'noneBy', require( '@stdlib/array/base/none-by' ) ); */ setReadOnly( ns, 'noneByRight', require( '@stdlib/array/base/none-by-right' ) ); +/** +* @name nulls +* @memberof ns +* @readonly +* @type {Function} +* @see {@link module:@stdlib/array/base/nulls} +*/ +setReadOnly( ns, 'nulls', require( '@stdlib/array/base/nulls' ) ); + /** * @name oneTo * @memberof ns diff --git a/lib/node_modules/@stdlib/array/base/mskreject-map/docs/types/test.ts b/lib/node_modules/@stdlib/array/base/mskreject-map/docs/types/test.ts index 0328f60ce17..e74d7981e3b 100644 --- a/lib/node_modules/@stdlib/array/base/mskreject-map/docs/types/test.ts +++ b/lib/node_modules/@stdlib/array/base/mskreject-map/docs/types/test.ts @@ -16,16 +16,28 @@ * limitations under the License. */ -import mskrejectMap from './index'; +import mskrejectMap = require( './index' ); + + +// FUNCTIONS // + +function timesTwo( val: number ): number { + return val * 2; +} + +function identity( val: string ): string { + return val; +} + // TESTS // // The function returns an array... { - mskrejectMap( [ 1, 2, 3, 4 ], [ 0, 0, 0, 0 ], function( val ) { return val * 2 } ); // $ExpectType number[] - mskrejectMap( [ 1, 2, 3, 4 ], [ 0, 0, 0, 0 ], function( val ) { return val * 2 } ); // $ExpectType any[] - mskrejectMap( [ 1, 2, 3, 4 ], [ 0, 0, 0, 0 ], function( val ) { return val * 2 } ); // $ExpectType number[] - mskrejectMap( [ '1', '2', '3', '4' ], [ 0, 0, 0, 0 ], function( val ) { return val } ); // $ExpectType string[] + mskrejectMap( [ 1, 2, 3, 4 ], [ 0, 0, 0, 0 ], timesTwo ); // $ExpectType number[] + mskrejectMap( [ 1, 2, 3, 4 ], [ 0, 0, 0, 0 ], timesTwo ); // $ExpectType any[] + mskrejectMap( [ 1, 2, 3, 4 ], [ 0, 0, 0, 0 ], timesTwo ); // $ExpectType number[] + mskrejectMap( [ '1', '2', '3', '4' ], [ 0, 0, 0, 0 ], identity ); // $ExpectType string[] } // The compiler throws an error if the function is provided a first argument which is not an array-like object... diff --git a/lib/node_modules/@stdlib/array/base/nulls/README.md b/lib/node_modules/@stdlib/array/base/nulls/README.md new file mode 100644 index 00000000000..0659f9c0c22 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/nulls/README.md @@ -0,0 +1,108 @@ + + +# nulls + +> Create a "generic" array filled with null values. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var nulls = require( '@stdlib/array/base/nulls' ); +``` + +#### nulls( len ) + +Returns a "generic" array filled with `null` values. + +```javascript +var out = nulls( 3 ); +// returns [ null, null, null ] +``` + +
+ + + + + +
+ +
+ + + + + +
+ +## Examples + + + +```javascript +var nulls = require( '@stdlib/array/base/nulls' ); + +// Create a null value array: +var arr = nulls( 10 ); + +console.log( arr ); +// => [ null, null, null, null, null, null, null, null, null, null ] +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/array/base/nulls/benchmark/benchmark.length.js b/lib/node_modules/@stdlib/array/base/nulls/benchmark/benchmark.length.js new file mode 100644 index 00000000000..2b8c68504ad --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/nulls/benchmark/benchmark.length.js @@ -0,0 +1,94 @@ +/** +* @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 pow = require( '@stdlib/math/base/special/pow' ); +var isArray = require( '@stdlib/assert/is-array' ); +var pkg = require( './../package.json' ).name; +var nulls = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = nulls( len ); + if ( out.length !== len ) { + b.fail( 'unexpected length' ); + } + } + b.toc(); + if ( !isArray( out ) ) { + b.fail( 'should return an array' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + f = createBenchmark( len ); + bench( pkg+':len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/base/nulls/docs/repl.txt b/lib/node_modules/@stdlib/array/base/nulls/docs/repl.txt new file mode 100644 index 00000000000..fdaf39cb3bc --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/nulls/docs/repl.txt @@ -0,0 +1,22 @@ + +{{alias}}( len ) + Returns a "generic" array filled with null values. + + Parameters + ---------- + len: integer + Array length. + + Returns + ------- + out: Array + Output array. + + Examples + -------- + > var out = {{alias}}( 3 ) + [ null, null, null ] + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/array/base/nulls/docs/types/index.d.ts b/lib/node_modules/@stdlib/array/base/nulls/docs/types/index.d.ts new file mode 100644 index 00000000000..487ab3cc9ed --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/nulls/docs/types/index.d.ts @@ -0,0 +1,36 @@ +/* +* @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 + +/** +* Returns a "generic" array filled with nulls. +* +* @param len - array length +* @returns output array +* +* @example +* var out = nulls( 3 ); +* // returns [ null, null, null ] +*/ +declare function nulls( len: number ): Array; + + +// EXPORTS // + +export = nulls; diff --git a/lib/node_modules/@stdlib/array/base/nulls/docs/types/test.ts b/lib/node_modules/@stdlib/array/base/nulls/docs/types/test.ts new file mode 100644 index 00000000000..34fbde4883a --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/nulls/docs/types/test.ts @@ -0,0 +1,44 @@ +/* +* @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 nulls = require( './index' ); + + +// TESTS // + +// The function returns an array... +{ + nulls( 3 ); // $ExpectType null[] +} + +// The compiler throws an error if the function is provided an argument which is not a number... +{ + nulls( 'abc' ); // $ExpectError + nulls( true ); // $ExpectError + nulls( false ); // $ExpectError + nulls( null ); // $ExpectError + nulls( [] ); // $ExpectError + nulls( {} ); // $ExpectError + nulls( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + nulls(); // $ExpectError + nulls( 3, 2 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/array/base/nulls/examples/index.js b/lib/node_modules/@stdlib/array/base/nulls/examples/index.js new file mode 100644 index 00000000000..cc7ba529a2e --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/nulls/examples/index.js @@ -0,0 +1,27 @@ +/** +* @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 nulls = require( './../lib' ); + +// Create a null value array: +var arr = nulls( 10 ); + +console.log( arr ); +// => [ null, null, null, null, null, null, null, null, null, null ] diff --git a/lib/node_modules/@stdlib/array/base/nulls/lib/index.js b/lib/node_modules/@stdlib/array/base/nulls/lib/index.js new file mode 100644 index 00000000000..e30573f64c8 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/nulls/lib/index.js @@ -0,0 +1,40 @@ +/** +* @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 a "generic" array filled with null values. +* +* @module @stdlib/array/base/nulls +* +* @example +* var nulls = require( '@stdlib/array/base/nulls' ); +* +* var out = nulls( 3 ); +* // returns [ null, null, null ] +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapxsum/src/dapxsum.c b/lib/node_modules/@stdlib/array/base/nulls/lib/main.js similarity index 50% rename from lib/node_modules/@stdlib/blas/ext/base/dapxsum/src/dapxsum.c rename to lib/node_modules/@stdlib/array/base/nulls/lib/main.js index e0f5df95b41..9b92e7fe680 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapxsum/src/dapxsum.c +++ b/lib/node_modules/@stdlib/array/base/nulls/lib/main.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2020 The Stdlib Authors. +* 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. @@ -16,19 +16,30 @@ * limitations under the License. */ -#include "stdlib/blas/ext/base/dapxsum.h" -#include "stdlib/blas/ext/base/dapxsumkbn.h" -#include +'use strict'; + +// MODULES // + +var filled = require( '@stdlib/array/base/filled' ); + + +// MAIN // /** -* Adds a constant to each double-precision floating-point strided array element and computes the sum. +* Returns a "generic" array filled with null values. * -* @param N number of indexed elements -* @param alpha constant -* @param X input array -* @param stride stride length -* @return output value +* @param {NonNegativeInteger} len - array length +* @returns {Array} output array +* +* @example +* var out = nulls( 3 ); +* // returns [ null, null, null ] */ -double stdlib_strided_dapxsum( const int64_t N, const double alpha, const double *X, const int64_t stride ) { - return stdlib_strided_dapxsumkbn( N, alpha, X, stride ); +function nulls( len ) { + return filled( null, len ); } + + +// EXPORTS // + +module.exports = nulls; diff --git a/lib/node_modules/@stdlib/array/base/nulls/package.json b/lib/node_modules/@stdlib/array/base/nulls/package.json new file mode 100644 index 00000000000..41b9d684245 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/nulls/package.json @@ -0,0 +1,65 @@ +{ + "name": "@stdlib/array/base/nulls", + "version": "0.0.0", + "description": "Create a generic array filled with null values.", + "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", + "stdtypes", + "types", + "data", + "structure", + "array", + "generic", + "allocate", + "alloc", + "fill", + "filled", + "null" + ] +} diff --git a/lib/node_modules/@stdlib/array/base/nulls/test/test.js b/lib/node_modules/@stdlib/array/base/nulls/test/test.js new file mode 100644 index 00000000000..e67dc00286c --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/nulls/test/test.js @@ -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. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var nulls = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof nulls, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns a "generic" array filled with null values', function test( t ) { + var expected; + var actual; + + expected = [ null, null, null ]; + actual = nulls( 3 ); + + t.deepEqual( actual, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns an empty array if provided a length of `0`', function test( t ) { + var expected; + var actual; + + expected = []; + actual = nulls( 0 ); + + t.deepEqual( actual, expected, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/array/base/resolve-getter/docs/repl.txt b/lib/node_modules/@stdlib/array/base/resolve-getter/docs/repl.txt index 20f2549edf6..fc93602fa9b 100644 --- a/lib/node_modules/@stdlib/array/base/resolve-getter/docs/repl.txt +++ b/lib/node_modules/@stdlib/array/base/resolve-getter/docs/repl.txt @@ -5,8 +5,8 @@ An accessor function accepts the following arguments: - - arr: input array - - idx: element index + - arr: input array. + - idx: element index. If provided an array-like object having an unsupported data type, the function returns a default accessor function for accessing elements from diff --git a/lib/node_modules/@stdlib/array/base/resolve-setter/docs/repl.txt b/lib/node_modules/@stdlib/array/base/resolve-setter/docs/repl.txt index 27272a050ab..5465b60399e 100644 --- a/lib/node_modules/@stdlib/array/base/resolve-setter/docs/repl.txt +++ b/lib/node_modules/@stdlib/array/base/resolve-setter/docs/repl.txt @@ -4,9 +4,9 @@ An accessor function accepts the following arguments: - - arr: input array - - idx: element index - - value: value to set + - arr: input array. + - idx: element index. + - value: value to set. If provided an array-like object having an unsupported data type, the function returns a default accessor function for accessing elements in any diff --git a/lib/node_modules/@stdlib/array/base/setter/docs/repl.txt b/lib/node_modules/@stdlib/array/base/setter/docs/repl.txt index 4442c84838b..e41d7c700bb 100644 --- a/lib/node_modules/@stdlib/array/base/setter/docs/repl.txt +++ b/lib/node_modules/@stdlib/array/base/setter/docs/repl.txt @@ -5,9 +5,9 @@ An accessor function accepts the following arguments: - - arr: input array - - idx: element index - - value: value to set + - arr: input array. + - idx: element index. + - value: value to set. If provided an unsupported `dtype`, the function returns a default accessor function for accessing elements in any indexed array-like object. diff --git a/lib/node_modules/@stdlib/array/base/unary2d-by/docs/repl.txt b/lib/node_modules/@stdlib/array/base/unary2d-by/docs/repl.txt index 5945f052a6e..f53543c8b64 100644 --- a/lib/node_modules/@stdlib/array/base/unary2d-by/docs/repl.txt +++ b/lib/node_modules/@stdlib/array/base/unary2d-by/docs/repl.txt @@ -6,9 +6,9 @@ The callback function is provided the following arguments: - - value: array element - - indices: current array element indices - - arrays: input and output arrays + - value: array element. + - indices: current array element indices. + - arrays: input and output arrays. If the callback function does not return any value (or equivalently, explicitly returns `undefined`), the value is ignored. diff --git a/lib/node_modules/@stdlib/array/bool/benchmark/benchmark.index_of.js b/lib/node_modules/@stdlib/array/bool/benchmark/benchmark.index_of.js index bc4f86f448f..875befae707 100644 --- a/lib/node_modules/@stdlib/array/bool/benchmark/benchmark.index_of.js +++ b/lib/node_modules/@stdlib/array/bool/benchmark/benchmark.index_of.js @@ -21,7 +21,7 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var isInteger = require('@stdlib/assert/is-integer' ).isPrimitive; +var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive; var pkg = require( './../package.json' ).name; var BooleanArray = require( './../lib' ); diff --git a/lib/node_modules/@stdlib/array/bool/benchmark/benchmark.index_of.length.js b/lib/node_modules/@stdlib/array/bool/benchmark/benchmark.index_of.length.js index 86a2cec8703..6f800919e4c 100644 --- a/lib/node_modules/@stdlib/array/bool/benchmark/benchmark.index_of.length.js +++ b/lib/node_modules/@stdlib/array/bool/benchmark/benchmark.index_of.length.js @@ -22,7 +22,7 @@ var bench = require( '@stdlib/bench' ); var pow = require( '@stdlib/math/base/special/pow' ); -var isInteger = require('@stdlib/assert/is-integer' ).isPrimitive; +var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive; var pkg = require( './../package.json' ).name; var BooleanArray = require( './../lib' ); diff --git a/lib/node_modules/@stdlib/array/bool/benchmark/benchmark.last_index_of.js b/lib/node_modules/@stdlib/array/bool/benchmark/benchmark.last_index_of.js index 621dd6fbcb9..6a8ee0c6380 100644 --- a/lib/node_modules/@stdlib/array/bool/benchmark/benchmark.last_index_of.js +++ b/lib/node_modules/@stdlib/array/bool/benchmark/benchmark.last_index_of.js @@ -21,7 +21,7 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var isInteger = require('@stdlib/assert/is-integer' ).isPrimitive; +var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive; var pkg = require( './../package.json' ).name; var BooleanArray = require( './../lib' ); diff --git a/lib/node_modules/@stdlib/array/bool/benchmark/benchmark.last_index_of.length.js b/lib/node_modules/@stdlib/array/bool/benchmark/benchmark.last_index_of.length.js index 6fbc28acb3a..76171de7919 100644 --- a/lib/node_modules/@stdlib/array/bool/benchmark/benchmark.last_index_of.length.js +++ b/lib/node_modules/@stdlib/array/bool/benchmark/benchmark.last_index_of.length.js @@ -22,7 +22,7 @@ var bench = require( '@stdlib/bench' ); var pow = require( '@stdlib/math/base/special/pow' ); -var isInteger = require('@stdlib/assert/is-integer' ).isPrimitive; +var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive; var pkg = require( './../package.json' ).name; var BooleanArray = require( './../lib' ); diff --git a/lib/node_modules/@stdlib/array/bool/benchmark/benchmark.reduce_right.length.js b/lib/node_modules/@stdlib/array/bool/benchmark/benchmark.reduce_right.length.js index 22a0f391ff3..8de497b055e 100644 --- a/lib/node_modules/@stdlib/array/bool/benchmark/benchmark.reduce_right.length.js +++ b/lib/node_modules/@stdlib/array/bool/benchmark/benchmark.reduce_right.length.js @@ -22,7 +22,7 @@ var bench = require( '@stdlib/bench' ); var pow = require( '@stdlib/math/base/special/pow' ); -var isInteger = require('@stdlib/assert/is-integer').isPrimitive; +var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive; var Boolean = require( '@stdlib/boolean/ctor' ); var pkg = require( './../package.json' ).name; var BooleanArray = require( './../lib' ); diff --git a/lib/node_modules/@stdlib/array/bool/benchmark/benchmark.values.js b/lib/node_modules/@stdlib/array/bool/benchmark/benchmark.values.js index 7517e19e065..48283aaed09 100644 --- a/lib/node_modules/@stdlib/array/bool/benchmark/benchmark.values.js +++ b/lib/node_modules/@stdlib/array/bool/benchmark/benchmark.values.js @@ -23,7 +23,7 @@ var bench = require( '@stdlib/bench' ); var isIteratorLike = require( '@stdlib/assert/is-iterator-like' ); var pkg = require( './../package.json' ).name; -var BooleanArray = require('./../lib'); +var BooleanArray = require( './../lib' ); // MAIN // diff --git a/lib/node_modules/@stdlib/array/bool/benchmark/benchmark.with.length.js b/lib/node_modules/@stdlib/array/bool/benchmark/benchmark.with.length.js index 25816ddaa93..508e63f185c 100644 --- a/lib/node_modules/@stdlib/array/bool/benchmark/benchmark.with.length.js +++ b/lib/node_modules/@stdlib/array/bool/benchmark/benchmark.with.length.js @@ -22,7 +22,7 @@ var bench = require( '@stdlib/bench' ); var pow = require( '@stdlib/math/base/special/pow' ); -var isBooleanArray = require('@stdlib/assert/is-booleanarray' ); +var isBooleanArray = require( '@stdlib/assert/is-booleanarray' ); var pkg = require( './../package.json' ).name; var BooleanArray = require( './../lib' ); diff --git a/lib/node_modules/@stdlib/array/bool/lib/main.js b/lib/node_modules/@stdlib/array/bool/lib/main.js index 989eafe8f12..15660a9da1b 100644 --- a/lib/node_modules/@stdlib/array/bool/lib/main.js +++ b/lib/node_modules/@stdlib/array/bool/lib/main.js @@ -78,7 +78,7 @@ function isBooleanArray( value ) { * @returns {boolean} boolean indicating if a value is a boolean typed array constructor */ function isBooleanArrayConstructor( value ) { - return ( value === BooleanArray); + return ( value === BooleanArray ); } diff --git a/lib/node_modules/@stdlib/array/byte-orders/README.md b/lib/node_modules/@stdlib/array/byte-orders/README.md new file mode 100644 index 00000000000..7f18a6c05ab --- /dev/null +++ b/lib/node_modules/@stdlib/array/byte-orders/README.md @@ -0,0 +1,119 @@ + + +# byteOrders + +> List of byte orders. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var byteOrders = require( '@stdlib/array/byte-orders' ); +``` + +#### byteOrders() + +Returns a list of byte orders. + +```javascript +var out = byteOrders(); +// e.g., returns [ 'little-endian', 'big-endian' ] +``` + +The output array contains the following orders: + +- **little-endian**: bytes are ordered from least-to-most significant byte. +- **big-endian**: bytes are ordered from most-to-least significant byte. + +
+ + + + + +
+ +
+ + + + + +
+ +## Examples + + + +```javascript +var contains = require( '@stdlib/array/base/assert/contains' ).factory; +var byteOrders = require( '@stdlib/array/byte-orders' ); + +var isByteOrder = contains( byteOrders() ); + +var bool = isByteOrder( 'little-endian' ); +// returns true + +bool = isByteOrder( 'big-endian' ); +// returns true + +bool = isByteOrder( 'beep' ); +// returns false +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/array/byte-orders/benchmark/benchmark.js b/lib/node_modules/@stdlib/array/byte-orders/benchmark/benchmark.js new file mode 100644 index 00000000000..d965e8bbc9a --- /dev/null +++ b/lib/node_modules/@stdlib/array/byte-orders/benchmark/benchmark.js @@ -0,0 +1,48 @@ +/** +* @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 isStringArray = require( '@stdlib/assert/is-string-array' ).primitives; +var pkg = require( './../package.json' ).name; +var byteOrders = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = byteOrders(); + if ( out.length !== 2 ) { + b.fail( 'should return an array of length 2' ); + } + } + b.toc(); + if ( !isStringArray( out ) ) { + b.fail( 'should return an array of strings' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/byte-orders/docs/repl.txt b/lib/node_modules/@stdlib/array/byte-orders/docs/repl.txt new file mode 100644 index 00000000000..4cbbb3a6e2b --- /dev/null +++ b/lib/node_modules/@stdlib/array/byte-orders/docs/repl.txt @@ -0,0 +1,22 @@ + +{{alias}}() + Returns a list of byte orders. + + The output array contains the following orders: + + - little-endian: bytes are ordered from least-to-most significant byte. + - big-endian: bytes are ordered from most-to-least significant byte. + + Returns + ------- + out: Array + List of byte orders. + + Examples + -------- + > var out = {{alias}}() + [...] + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/array/byte-orders/docs/types/index.d.ts b/lib/node_modules/@stdlib/array/byte-orders/docs/types/index.d.ts new file mode 100644 index 00000000000..939a7d5d993 --- /dev/null +++ b/lib/node_modules/@stdlib/array/byte-orders/docs/types/index.d.ts @@ -0,0 +1,42 @@ +/* +* @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 + +/** +* Returns a list of byte orders. +* +* ## Notes +* +* - The output array contains the following orders: +* +* - little-endian: bytes are ordered from least-to-most significant byte. +* - big-endian: bytes are ordered from most-to-least significant byte. +* +* @returns list of byte orders +* +* @example +* var list = byteOrders(); +* // e.g., returns [ 'little-endian', 'big-endian' ] +*/ +declare function byteOrders(): Array; + + +// EXPORTS // + +export = byteOrders; diff --git a/lib/node_modules/@stdlib/array/byte-orders/docs/types/test.ts b/lib/node_modules/@stdlib/array/byte-orders/docs/types/test.ts new file mode 100644 index 00000000000..7a90a2a1716 --- /dev/null +++ b/lib/node_modules/@stdlib/array/byte-orders/docs/types/test.ts @@ -0,0 +1,32 @@ +/* +* @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 byteOrders = require( './index' ); + + +// TESTS // + +// The function returns an array of strings... +{ + byteOrders(); // $ExpectType string[] +} + +// The compiler throws an error if the function is provided any arguments... +{ + byteOrders( 9 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/array/byte-orders/examples/index.js b/lib/node_modules/@stdlib/array/byte-orders/examples/index.js new file mode 100644 index 00000000000..56164dfe444 --- /dev/null +++ b/lib/node_modules/@stdlib/array/byte-orders/examples/index.js @@ -0,0 +1,36 @@ +/** +* @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 contains = require( '@stdlib/array/base/assert/contains' ).factory; +var byteOrders = require( './../lib' ); + +var isByteOrder = contains( byteOrders() ); + +var bool = isByteOrder( 'little-endian' ); +console.log( bool ); +// => true + +bool = isByteOrder( 'big-endian' ); +console.log( bool ); +// => true + +bool = isByteOrder( 'beep' ); +console.log( bool ); +// => false diff --git a/lib/node_modules/@stdlib/array/byte-orders/lib/index.js b/lib/node_modules/@stdlib/array/byte-orders/lib/index.js new file mode 100644 index 00000000000..9969e2f7afb --- /dev/null +++ b/lib/node_modules/@stdlib/array/byte-orders/lib/index.js @@ -0,0 +1,40 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Return a list of byte orders. +* +* @module @stdlib/array/byte-orders +* +* @example +* var orders = require( '@stdlib/array/byte-orders' ); +* +* var list = orders(); +* // e.g., returns [ 'little-endian', 'big-endian' ] +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/array/byte-orders/lib/main.js b/lib/node_modules/@stdlib/array/byte-orders/lib/main.js new file mode 100644 index 00000000000..09d60ff1a4b --- /dev/null +++ b/lib/node_modules/@stdlib/array/byte-orders/lib/main.js @@ -0,0 +1,44 @@ +/** +* @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 ORDERS = require( './orders.json' ); + + +// MAIN // + +/** +* Returns a list of byte orders. +* +* @returns {StringArray} list of byte orders +* +* @example +* var list = orders(); +* // e.g., returns [ 'little-endian', 'big-endian' ] +*/ +function orders() { + return ORDERS.slice(); +} + + +// EXPORTS // + +module.exports = orders; diff --git a/lib/node_modules/@stdlib/array/byte-orders/lib/orders.json b/lib/node_modules/@stdlib/array/byte-orders/lib/orders.json new file mode 100644 index 00000000000..b5a7be4e1a9 --- /dev/null +++ b/lib/node_modules/@stdlib/array/byte-orders/lib/orders.json @@ -0,0 +1,4 @@ +[ + "little-endian", + "big-endian" +] diff --git a/lib/node_modules/@stdlib/array/byte-orders/package.json b/lib/node_modules/@stdlib/array/byte-orders/package.json new file mode 100644 index 00000000000..2ed9d5dfea7 --- /dev/null +++ b/lib/node_modules/@stdlib/array/byte-orders/package.json @@ -0,0 +1,68 @@ +{ + "name": "@stdlib/array/byte-orders", + "version": "0.0.0", + "description": "List of byte orders.", + "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", + "include": "./include", + "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", + "stdtypes", + "types", + "array", + "order", + "little-endian", + "big-endian", + "layout", + "memory", + "utilities", + "utility", + "utils", + "util" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/array/byte-orders/test/test.js b/lib/node_modules/@stdlib/array/byte-orders/test/test.js new file mode 100644 index 00000000000..15f4a90ea35 --- /dev/null +++ b/lib/node_modules/@stdlib/array/byte-orders/test/test.js @@ -0,0 +1,47 @@ +/** +* @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 orders = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof orders, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns a list of byte orders', function test( t ) { + var expected; + var actual; + + expected = [ + 'little-endian', + 'big-endian' + ]; + actual = orders(); + + t.deepEqual( actual, expected, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/array/complex128/benchmark/benchmark.index_of.js b/lib/node_modules/@stdlib/array/complex128/benchmark/benchmark.index_of.js index 3b532b50d2e..62188c7b1a7 100644 --- a/lib/node_modules/@stdlib/array/complex128/benchmark/benchmark.index_of.js +++ b/lib/node_modules/@stdlib/array/complex128/benchmark/benchmark.index_of.js @@ -22,7 +22,7 @@ var bench = require( '@stdlib/bench' ); var Complex128 = require( '@stdlib/complex/float64/ctor' ); -var isInteger = require('@stdlib/assert/is-integer' ).isPrimitive; +var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive; var pkg = require( './../package.json' ).name; var Complex128Array = require( './../lib' ); diff --git a/lib/node_modules/@stdlib/array/complex128/benchmark/benchmark.index_of.length.js b/lib/node_modules/@stdlib/array/complex128/benchmark/benchmark.index_of.length.js index bd7c0ae8354..4101e78f515 100644 --- a/lib/node_modules/@stdlib/array/complex128/benchmark/benchmark.index_of.length.js +++ b/lib/node_modules/@stdlib/array/complex128/benchmark/benchmark.index_of.length.js @@ -23,7 +23,7 @@ var bench = require( '@stdlib/bench' ); var pow = require( '@stdlib/math/base/special/pow' ); var Complex128 = require( '@stdlib/complex/float64/ctor' ); -var isInteger = require('@stdlib/assert/is-integer' ).isPrimitive; +var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive; var pkg = require( './../package.json' ).name; var Complex128Array = require( './../lib' ); diff --git a/lib/node_modules/@stdlib/array/complex128/benchmark/benchmark.last_index_of.js b/lib/node_modules/@stdlib/array/complex128/benchmark/benchmark.last_index_of.js index bbad202a937..069b17deaac 100644 --- a/lib/node_modules/@stdlib/array/complex128/benchmark/benchmark.last_index_of.js +++ b/lib/node_modules/@stdlib/array/complex128/benchmark/benchmark.last_index_of.js @@ -22,7 +22,7 @@ var bench = require( '@stdlib/bench' ); var Complex128 = require( '@stdlib/complex/float64/ctor' ); -var isInteger = require('@stdlib/assert/is-integer' ).isPrimitive; +var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive; var pkg = require( './../package.json' ).name; var Complex128Array = require( './../lib' ); diff --git a/lib/node_modules/@stdlib/array/complex128/benchmark/benchmark.last_index_of.length.js b/lib/node_modules/@stdlib/array/complex128/benchmark/benchmark.last_index_of.length.js index 2d508813c29..56f650dd56a 100644 --- a/lib/node_modules/@stdlib/array/complex128/benchmark/benchmark.last_index_of.length.js +++ b/lib/node_modules/@stdlib/array/complex128/benchmark/benchmark.last_index_of.length.js @@ -23,7 +23,7 @@ var bench = require( '@stdlib/bench' ); var pow = require( '@stdlib/math/base/special/pow' ); var Complex128 = require( '@stdlib/complex/float64/ctor' ); -var isInteger = require('@stdlib/assert/is-integer' ).isPrimitive; +var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive; var pkg = require( './../package.json' ).name; var Complex128Array = require( './../lib' ); diff --git a/lib/node_modules/@stdlib/array/complex128/benchmark/benchmark.reduce.js b/lib/node_modules/@stdlib/array/complex128/benchmark/benchmark.reduce.js index 24125cbbbb6..9e727dd4cc6 100644 --- a/lib/node_modules/@stdlib/array/complex128/benchmark/benchmark.reduce.js +++ b/lib/node_modules/@stdlib/array/complex128/benchmark/benchmark.reduce.js @@ -22,7 +22,7 @@ var bench = require( '@stdlib/bench' ); var cadd = require( '@stdlib/complex/float64/base/add' ); -var isComplexLike = require('@stdlib/assert/is-complex-like' ); +var isComplexLike = require( '@stdlib/assert/is-complex-like' ); var pkg = require( './../package.json' ).name; var Complex128Array = require( './../lib' ); diff --git a/lib/node_modules/@stdlib/array/complex128/benchmark/benchmark.reduce.length.js b/lib/node_modules/@stdlib/array/complex128/benchmark/benchmark.reduce.length.js index d531f89bf92..8c552664bb4 100644 --- a/lib/node_modules/@stdlib/array/complex128/benchmark/benchmark.reduce.length.js +++ b/lib/node_modules/@stdlib/array/complex128/benchmark/benchmark.reduce.length.js @@ -23,7 +23,7 @@ var bench = require( '@stdlib/bench' ); var pow = require( '@stdlib/math/base/special/pow' ); var cadd = require( '@stdlib/complex/float64/base/add' ); -var isComplexLike = require('@stdlib/assert/is-complex-like' ); +var isComplexLike = require( '@stdlib/assert/is-complex-like' ); var Complex128 = require( '@stdlib/complex/float64/ctor' ); var pkg = require( './../package.json' ).name; var Complex128Array = require( './../lib' ); diff --git a/lib/node_modules/@stdlib/array/complex128/benchmark/benchmark.reduce_right.js b/lib/node_modules/@stdlib/array/complex128/benchmark/benchmark.reduce_right.js index bed428480e1..ad6bca179cc 100644 --- a/lib/node_modules/@stdlib/array/complex128/benchmark/benchmark.reduce_right.js +++ b/lib/node_modules/@stdlib/array/complex128/benchmark/benchmark.reduce_right.js @@ -22,7 +22,7 @@ var bench = require( '@stdlib/bench' ); var cadd = require( '@stdlib/complex/float64/base/add' ); -var isComplexLike = require('@stdlib/assert/is-complex-like' ); +var isComplexLike = require( '@stdlib/assert/is-complex-like' ); var pkg = require( './../package.json' ).name; var Complex128Array = require( './../lib' ); diff --git a/lib/node_modules/@stdlib/array/complex128/benchmark/benchmark.reduce_right.length.js b/lib/node_modules/@stdlib/array/complex128/benchmark/benchmark.reduce_right.length.js index f07ec3ee336..6afa19f3ad0 100644 --- a/lib/node_modules/@stdlib/array/complex128/benchmark/benchmark.reduce_right.length.js +++ b/lib/node_modules/@stdlib/array/complex128/benchmark/benchmark.reduce_right.length.js @@ -23,7 +23,7 @@ var bench = require( '@stdlib/bench' ); var pow = require( '@stdlib/math/base/special/pow' ); var cadd = require( '@stdlib/complex/float64/base/add' ); -var isComplexLike = require('@stdlib/assert/is-complex-like' ); +var isComplexLike = require( '@stdlib/assert/is-complex-like' ); var Complex128 = require( '@stdlib/complex/float64/ctor' ); var pkg = require( './../package.json' ).name; var Complex128Array = require( './../lib' ); diff --git a/lib/node_modules/@stdlib/array/complex128/benchmark/benchmark.with.length.js b/lib/node_modules/@stdlib/array/complex128/benchmark/benchmark.with.length.js index acbf6e283bc..304edad9327 100644 --- a/lib/node_modules/@stdlib/array/complex128/benchmark/benchmark.with.length.js +++ b/lib/node_modules/@stdlib/array/complex128/benchmark/benchmark.with.length.js @@ -23,7 +23,7 @@ var bench = require( '@stdlib/bench' ); var pow = require( '@stdlib/math/base/special/pow' ); var Complex128 = require( '@stdlib/complex/float64/ctor' ); -var isComplex128Array = require('@stdlib/assert/is-complex128array' ); +var isComplex128Array = require( '@stdlib/assert/is-complex128array' ); var pkg = require( './../package.json' ).name; var Complex128Array = require( './../lib' ); diff --git a/lib/node_modules/@stdlib/array/complex128/lib/index.js b/lib/node_modules/@stdlib/array/complex128/lib/index.js index 0e040a2d035..90dee3a4685 100644 --- a/lib/node_modules/@stdlib/array/complex128/lib/index.js +++ b/lib/node_modules/@stdlib/array/complex128/lib/index.js @@ -70,7 +70,7 @@ * // returns * * var len = arr.length; -* // returns 2 +* // returns 1 * * @example * var ArrayBuffer = require( '@stdlib/array/buffer' ); diff --git a/lib/node_modules/@stdlib/array/complex64/benchmark/benchmark.index_of.js b/lib/node_modules/@stdlib/array/complex64/benchmark/benchmark.index_of.js index cd2d0043018..185d3fb8041 100644 --- a/lib/node_modules/@stdlib/array/complex64/benchmark/benchmark.index_of.js +++ b/lib/node_modules/@stdlib/array/complex64/benchmark/benchmark.index_of.js @@ -22,7 +22,7 @@ var bench = require( '@stdlib/bench' ); var Complex64 = require( '@stdlib/complex/float32/ctor' ); -var isInteger = require('@stdlib/assert/is-integer' ).isPrimitive; +var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive; var pkg = require( './../package.json' ).name; var Complex64Array = require( './../lib' ); diff --git a/lib/node_modules/@stdlib/array/complex64/benchmark/benchmark.index_of.length.js b/lib/node_modules/@stdlib/array/complex64/benchmark/benchmark.index_of.length.js index bc1ef87908d..7d6dceb67e4 100644 --- a/lib/node_modules/@stdlib/array/complex64/benchmark/benchmark.index_of.length.js +++ b/lib/node_modules/@stdlib/array/complex64/benchmark/benchmark.index_of.length.js @@ -23,7 +23,7 @@ var bench = require( '@stdlib/bench' ); var pow = require( '@stdlib/math/base/special/pow' ); var Complex64 = require( '@stdlib/complex/float32/ctor' ); -var isInteger = require('@stdlib/assert/is-integer' ).isPrimitive; +var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive; var pkg = require( './../package.json' ).name; var Complex64Array = require( './../lib' ); diff --git a/lib/node_modules/@stdlib/array/complex64/benchmark/benchmark.last_index_of.js b/lib/node_modules/@stdlib/array/complex64/benchmark/benchmark.last_index_of.js index 2014e68c01f..dede9f2b5bc 100644 --- a/lib/node_modules/@stdlib/array/complex64/benchmark/benchmark.last_index_of.js +++ b/lib/node_modules/@stdlib/array/complex64/benchmark/benchmark.last_index_of.js @@ -22,7 +22,7 @@ var bench = require( '@stdlib/bench' ); var Complex64 = require( '@stdlib/complex/float32/ctor' ); -var isInteger = require('@stdlib/assert/is-integer' ).isPrimitive; +var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive; var pkg = require( './../package.json' ).name; var Complex64Array = require( './../lib' ); diff --git a/lib/node_modules/@stdlib/array/complex64/benchmark/benchmark.last_index_of.length.js b/lib/node_modules/@stdlib/array/complex64/benchmark/benchmark.last_index_of.length.js index 322473671af..f540a28fe80 100644 --- a/lib/node_modules/@stdlib/array/complex64/benchmark/benchmark.last_index_of.length.js +++ b/lib/node_modules/@stdlib/array/complex64/benchmark/benchmark.last_index_of.length.js @@ -23,7 +23,7 @@ var bench = require( '@stdlib/bench' ); var pow = require( '@stdlib/math/base/special/pow' ); var Complex64 = require( '@stdlib/complex/float32/ctor' ); -var isInteger = require('@stdlib/assert/is-integer' ).isPrimitive; +var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive; var pkg = require( './../package.json' ).name; var Complex64Array = require( './../lib' ); diff --git a/lib/node_modules/@stdlib/array/complex64/benchmark/benchmark.with.length.js b/lib/node_modules/@stdlib/array/complex64/benchmark/benchmark.with.length.js index 7fca12e0734..385ee21218d 100644 --- a/lib/node_modules/@stdlib/array/complex64/benchmark/benchmark.with.length.js +++ b/lib/node_modules/@stdlib/array/complex64/benchmark/benchmark.with.length.js @@ -23,7 +23,7 @@ var bench = require( '@stdlib/bench' ); var pow = require( '@stdlib/math/base/special/pow' ); var Complex64 = require( '@stdlib/complex/float32/ctor' ); -var isComplex64Array = require('@stdlib/assert/is-complex64array' ); +var isComplex64Array = require( '@stdlib/assert/is-complex64array' ); var pkg = require( './../package.json' ).name; var Complex64Array = require( './../lib' ); diff --git a/lib/node_modules/@stdlib/array/complex64/lib/index.js b/lib/node_modules/@stdlib/array/complex64/lib/index.js index 232abcc3103..1e9841f31ff 100644 --- a/lib/node_modules/@stdlib/array/complex64/lib/index.js +++ b/lib/node_modules/@stdlib/array/complex64/lib/index.js @@ -59,7 +59,7 @@ * // returns * * var len = arr.length; -* // returns 2 +* // returns 1 * * @example * var ArrayBuffer = require( '@stdlib/array/buffer' ); diff --git a/lib/node_modules/@stdlib/array/fixed-endian-factory/README.md b/lib/node_modules/@stdlib/array/fixed-endian-factory/README.md new file mode 100644 index 00000000000..afdb85cd8f8 --- /dev/null +++ b/lib/node_modules/@stdlib/array/fixed-endian-factory/README.md @@ -0,0 +1,503 @@ + + +# fixedEndianFactory + +> Return a typed array constructor for creating typed arrays having a specified byte order. + + + +
+ +In contrast to built-in typed array constructors which store values according to the host platform byte order, the typed array constructors returned by the factory function allow enforcing a specific byte order. Such enforcement can be particularly advantageous when working with memory buffers which do not necessarily follow host platform byte order, such as [WebAssembly memory][@stdlib/wasm/memory]. + +
+ + + + + +
+ +## Usage + +```javascript +var fixedEndianFactory = require( '@stdlib/array/fixed-endian-factory' ); +``` + +#### fixedEndianFactory( dtype ) + +Returns a typed array constructor for creating typed arrays having a specified [data type][@stdlib/array/typed-dtypes] and byte order. + +```javascript +var Float64ArrayFE = fixedEndianFactory( 'float64' ); +// returns + +var Float32ArrayFE = fixedEndianFactory( 'float32' ); +// returns +``` + +* * * + +### Typed Array Constructor + +#### TypedArrayFE( endianness ) + +A typed array constructor which returns a typed array representing values stored in a specified byte order. + +```javascript +var Float64ArrayFE = fixedEndianFactory( 'float64' ); + +var arr = new Float64ArrayFE( 'little-endian' ); +// returns +``` + +#### TypedArrayFE( endianness, length ) + +Returns a typed array having a specified length and byte order. + +```javascript +var Float64ArrayFE = fixedEndianFactory( 'float64' ); + +var arr = new Float64ArrayFE( 'little-endian', 5 ); +// returns +``` + +#### TypedArrayFE( endianness, typedarray ) + +Creates a typed array from another typed array. + +```javascript +var Float32Array = require( '@stdlib/array/float32' ); + +var Float64ArrayFE = fixedEndianFactory( 'float64' ); + +var arr1 = new Float32Array( [ 0.5, 0.5, 0.5 ] ); +var arr2 = new Float64ArrayFE( 'little-endian', arr1 ); +// returns + +var v = arr2.get( 0 ); +// returns 0.5 +``` + +#### TypedArrayFE( endianness, obj ) + +Creates a typed array from an array-like object or iterable. + +```javascript +var Float64ArrayFE = fixedEndianFactory( 'float64' ); + +var arr = new Float64ArrayFE( 'little-endian', [ 0.5, 0.5, 0.5 ] ); +// returns + +var v = arr.get( 0 ); +// returns 0.5 +``` + +#### TypedArrayFE( endianness, buffer\[, byteOffset\[, length]] ) + +Returns a typed array view of an [`ArrayBuffer`][@stdlib/array/buffer]. + +```javascript +var ArrayBuffer = require( '@stdlib/array/buffer' ); + +var Float64ArrayFE = fixedEndianFactory( 'float64' ); + +var buf = new ArrayBuffer( 32 ); +var arr = new Float64ArrayFE( 'little-endian', buf, 0, 4 ); +// returns +``` + +* * * + +### Typed Array Properties + + + +#### TypedArrayFE.BYTES_PER_ELEMENT + +Number of bytes per view element. + +```javascript +var Float64ArrayFE = fixedEndianFactory( 'float64' ); + +var nbytes = Float64ArrayFE.BYTES_PER_ELEMENT; +// returns 8 +``` + + + +#### TypedArrayFE.name + +Typed array constructor name. + +```javascript +var Float64ArrayFE = fixedEndianFactory( 'float64' ); + +var str = Float64ArrayFE.name; +// returns 'Float64ArrayFE' +``` + + + +#### TypedArrayFE.prototype.buffer + +**Read-only** property which returns the [`ArrayBuffer`][@stdlib/array/buffer] referenced by the typed array. + +```javascript +var Float64ArrayFE = fixedEndianFactory( 'float64' ); + +var arr = new Float64ArrayFE( 'little-endian', 5 ); +var buf = arr.buffer; +// returns +``` + + + +#### TypedArrayFE.prototype.byteLength + +**Read-only** property which returns the length (in bytes) of the typed array. + +```javascript +var Float64ArrayFE = fixedEndianFactory( 'float64' ); + +var arr = new Float64ArrayFE( 'little-endian', 5 ); +var byteLength = arr.byteLength; +// returns 40 +``` + + + +#### TypedArrayFE.prototype.byteOffset + +**Read-only** property which returns the offset (in bytes) of the typed array from the start of its [`ArrayBuffer`][@stdlib/array/buffer]. + +```javascript +var Float64ArrayFE = fixedEndianFactory( 'float64' ); + +var arr = new Float64ArrayFE( 'little-endian', 5 ); +var byteOffset = arr.byteOffset; +// returns 0 +``` + + + +#### TypedArrayFE.prototype.BYTES_PER_ELEMENT + +Number of bytes per view element. + +```javascript +var Float64ArrayFE = fixedEndianFactory( 'float64' ); + +var arr = new Float64ArrayFE( 'little-endian', 5 ); +var nbytes = arr.BYTES_PER_ELEMENT; +// returns 8 +``` + + + +#### TypedArrayFE.prototype.length + +**Read-only** property which returns the number of view elements. + +```javascript +var Float64ArrayFE = fixedEndianFactory( 'float64' ); + +var arr = new Float64ArrayFE( 'little-endian', 5 ); +var len = arr.length; +// returns 5 +``` + +* * * + +### Typed Array Methods + + + +#### TypedArrayFE.from( endianness, src\[, map\[, thisArg]] ) + +Creates a new typed array from an array-like object or an iterable. + +```javascript +var Float64ArrayFE = fixedEndianFactory( 'float64' ); + +var arr = Float64ArrayFE.from( 'little-endian', [ 1.0, -1.0 ] ); +// returns + +var v = arr.get( 0 ); +// returns 1.0 +``` + +To invoke a function for each `src` value, provide a callback function. + +```javascript +function mapFcn( v ) { + return v * 2.0; +} + +var Float64ArrayFE = fixedEndianFactory( 'float64' ); + +var arr = Float64ArrayFE.from( 'little-endian', [ 1.0, -1.0 ], mapFcn ); +// returns + +var v = arr.get( 0 ); +// returns 2.0 +``` + +A callback function is provided two arguments: + +- **value**: source value. +- **index**: source index. + +To set the callback execution context, provide a `thisArg`. + +```javascript +function mapFcn( v ) { + this.count += 1; + return v * 2.0; +} + +var Float64ArrayFE = fixedEndianFactory( 'float64' ); + +var ctx = { + 'count': 0 +}; + +var arr = Float64ArrayFE.from( 'little-endian', [ 1.0, -1.0 ], mapFcn, ctx ); +// returns + +var v = arr.get( 0 ); +// returns 2.0 + +var n = ctx.count; +// returns 2 +``` + + + +#### TypedArrayFE.of( endianness, element0\[, element1\[, ...elementN]] ) + +Creates a new typed array from a variable number of arguments. + +```javascript +var Float64ArrayFE = fixedEndianFactory( 'float64' ); + +var arr = Float64ArrayFE.of( 'little-endian', 1.0, -1.0 ); +// returns + +var v = arr.get( 0 ); +// returns 1.0 +``` + + + +#### TypedArrayFE.prototype.get( i ) + +Returns an array element located at a nonnegative integer position (index) `i`. + +```javascript +var Float64ArrayFE = fixedEndianFactory( 'float64' ); + +var arr = new Float64ArrayFE( 'little-endian', 10 ); + +// Set the first element: +arr.set( 1.0, 0 ); + +// Get the first element: +var v = arr.get( 0 ); +// returns 1.0 +``` + +If provided an out-of-bounds index, the method returns `undefined`. + +```javascript +var Float64ArrayFE = fixedEndianFactory( 'float64' ); + +var arr = new Float64ArrayFE( 'little-endian', 10 ); + +var v = arr.get( 100 ); +// returns undefined +``` + + + +#### TypedArrayFE.prototype.set( arr\[, offset] ) + +Sets array elements. + +```javascript +var Float64ArrayFE = fixedEndianFactory( 'float64' ); + +var arr = new Float64ArrayFE( 'little-endian', [ 1.0, 2.0, 3.0 ] ); +// returns + +var v = arr.get( 0 ); +// returns 1.0 + +v = arr.get( 1 ); +// returns 2.0 + +// Set the first two array elements: +arr.set( [ 4.0, 5.0 ] ); + +v = arr.get( 0 ); +// returns 4.0 + +v = arr.get( 1 ); +// returns 5.0 +``` + +By default, the method starts writing values at the first array index. To specify an alternative index, provide an index `offset`. + +```javascript +var Float64ArrayFE = fixedEndianFactory( 'float64' ); + +var arr = new Float64ArrayFE( 'little-endian', [ 1.0, 2.0, 3.0 ] ); +// returns + +// Set the last two array elements: +arr.set( [ 4.0, 5.0 ], 1 ); + +var v = arr.get( 1 ); +// returns 4.0 + +v = arr.get( 2 ); +// returns 5.0 +``` + +A few notes: + +- If `i` is out-of-bounds, the method throws an error. +- If a target array cannot accommodate all values (i.e., the length of source array plus `i` exceeds the target array length), the method throws an error. +- If provided a typed array which shares an [`ArrayBuffer`][@stdlib/array/buffer] with the target array, the method will intelligently copy the source range to the destination range. + + + +#### TypedArrayFE.prototype.toString() + +Serializes an array as a string. + +```javascript +var Float64ArrayFE = fixedEndianFactory( 'float64' ); + +var arr = new Float64ArrayFE( 'little-endian', [ 1.0, 2.0, 3.0 ] ); + +var str = arr.toString(); +// returns '1,2,3' +``` + +
+ + + + + +
+ +* * * + +## Notes + +- A returned constructor supports the following byte orders: + + - **little-endian**: store values such that bytes are stored from least-to-most significant bytes. This is the dominant ordering for processor architectures and their associated memory. This is also the ordering for [WebAssembly memory][@stdlib/wasm/memory]. + - **big-endian**: store values such that bytes are stored from most-to-least significant bytes. This is the dominant ordering in network protocols. + +- While returned constructors _strive_ to maintain (but do not **guarantee**) consistency with [typed arrays][@stdlib/array/typed], significant deviations from ECMAScript-defined [typed array][@stdlib/array/typed] behavior are as follows: + + - Constructors do **not** require the `new` operator. + - Accessing array elements using bracket syntax (e.g., `X[i]`) is **not** supported. Instead, one **must** use the `.get()` method. + +
+ + + + + +
+ +* * * + +## Examples + + + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); +var logEach = require( '@stdlib/console/log-each' ); +var fixedEndianFactory = require( '@stdlib/array/fixed-endian-factory' ); + +var Float64ArrayFE = fixedEndianFactory( 'float64' ); + +// Create a typed array by specifying a length: +var out = new Float64ArrayFE( 'little-endian', 3 ); +logEach( '%s', out ); + +// Create a typed array from an array: +var arr = [ 1.0, -1.0, -3.14, 3.14, 0.5, 0.5 ]; +out = new Float64ArrayFE( 'big-endian', arr ); +logEach( '%s', out ); + +// Create a typed array from an array buffer: +arr = new Float64Array( [ 1.0, -1.0, -3.14, 3.14, 0.5, 0.5 ] ); // host byte order +out = new Float64ArrayFE( 'little-endian', arr.buffer ); +logEach( '%s', out ); + +// Create a typed array from an array buffer view: +arr = new Float64Array( [ 1.0, -1.0, -3.14, 3.14, 0.5, 0.5 ] ); // host byte order +out = new Float64ArrayFE( 'big-endian', arr.buffer, 8, 2 ); +logEach( '%s', out ); +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/array/fixed-endian-factory/benchmark/benchmark.from.js b/lib/node_modules/@stdlib/array/fixed-endian-factory/benchmark/benchmark.from.js new file mode 100644 index 00000000000..353b7f6ac7e --- /dev/null +++ b/lib/node_modules/@stdlib/array/fixed-endian-factory/benchmark/benchmark.from.js @@ -0,0 +1,311 @@ +/** +* @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 Float64Array = require( '@stdlib/array/float64' ); +var ITERATOR_SYMBOL = require( '@stdlib/symbol/iterator' ); +var pkg = require( './../package.json' ).name; +var factory = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': ( ITERATOR_SYMBOL === null ) +}; +var Float64ArrayFE = factory( 'float64' ); + + +// MAIN // + +bench( pkg+'::typed_array:from', function benchmark( b ) { + var buf; + var arr; + var i; + + buf = new Float64Array( 0 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = Float64ArrayFE.from( 'little-endian', buf ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayFE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::typed_array:from:len=5', function benchmark( b ) { + var buf; + var arr; + var i; + + buf = new Float64Array( 5 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = Float64ArrayFE.from( 'little-endian', buf ); + if ( arr.length !== 5 ) { + b.fail( 'should have length 5' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayFE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::typed_array,clbk:from:len=5', function benchmark( b ) { + var buf; + var arr; + var i; + + buf = new Float64Array( 5 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = Float64ArrayFE.from( 'little-endian', buf, clbk ); + if ( arr.length !== 5 ) { + b.fail( 'should have length 5' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayFE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function clbk( v ) { + return v * 2.0; + } +}); + +bench( pkg+'::array:from', function benchmark( b ) { + var buf; + var arr; + var i; + + buf = []; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = Float64ArrayFE.from( 'little-endian', buf ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayFE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::array:from:len=5', function benchmark( b ) { + var buf; + var arr; + var i; + + buf = [ 1.0, 1.0, 1.0, 1.0, 1.0 ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = Float64ArrayFE.from( 'little-endian', buf ); + if ( arr.length !== 5 ) { + b.fail( 'should have length 5' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayFE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::array,clbk:from:len=5', function benchmark( b ) { + var buf; + var arr; + var i; + + buf = [ 1.0, 1.0, 1.0, 1.0, 1.0 ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = Float64ArrayFE.from( 'little-endian', buf, clbk ); + if ( arr.length !== 5 ) { + b.fail( 'should have length 5' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayFE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function clbk( v ) { + return v * 2.0; + } +}); + +bench( pkg+'::iterable:from', opts, function benchmark( b ) { + var arr; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = Float64ArrayFE.from( 'little-endian', createIterable() ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayFE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function createIterable() { + var out = {}; + out[ ITERATOR_SYMBOL ] = iterator; + return out; + + function iterator() { + return { + 'next': next + }; + } + + function next() { + return { + 'done': true + }; + } + } +}); + +bench( pkg+'::iterable:from:len=5', opts, function benchmark( b ) { + var arr; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = Float64ArrayFE.from( 'little-endian', createIterable() ); + if ( arr.length !== 5 ) { + b.fail( 'should have length 5' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayFE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function createIterable() { + var out = {}; + out[ ITERATOR_SYMBOL ] = iterator; + return out; + + function iterator() { + var it = { + 'next': next, + 'i': 0, + 'N': 5 + }; + return it; + + function next() { + it.i += 1; + if ( it.i <= it.N ) { + return { + 'value': 1.0 + }; + } + return { + 'done': true + }; + } + } + } +}); + +bench( pkg+'::iterable,clbk:from:len=5', opts, function benchmark( b ) { + var arr; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = Float64ArrayFE.from( 'little-endian', createIterable(), clbk ); + if ( arr.length !== 5 ) { + b.fail( 'should have length 5' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayFE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function createIterable() { + var out = {}; + out[ ITERATOR_SYMBOL ] = iterator; + return out; + + function iterator() { + var it = { + 'next': next, + 'i': 0, + 'N': 5 + }; + return it; + + function next() { + it.i += 1; + if ( it.i <= it.N ) { + return { + 'value': 1.0 + }; + } + return { + 'done': true + }; + } + } + } + + function clbk( v ) { + return v * 2.0; + } +}); diff --git a/lib/node_modules/@stdlib/array/fixed-endian-factory/benchmark/benchmark.get.js b/lib/node_modules/@stdlib/array/fixed-endian-factory/benchmark/benchmark.get.js new file mode 100644 index 00000000000..92da9fe66ed --- /dev/null +++ b/lib/node_modules/@stdlib/array/fixed-endian-factory/benchmark/benchmark.get.js @@ -0,0 +1,90 @@ +/** +* @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 isNumber = require( '@stdlib/assert/is-number' ).isPrimitive; +var pkg = require( './../package.json' ).name; +var factory = require( './../lib' ); + + +// VARIABLES // + +var Float64ArrayFE = factory( 'float64' ); + + +// MAIN // + +bench( pkg+':get:endianness=little-endian', function benchmark( b ) { + var arr; + var N; + var v; + var i; + + arr = []; + for ( i = 0; i < 10; i++ ) { + arr.push( i ); + } + arr = new Float64ArrayFE( 'little-endian', arr ); + N = arr.length; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = arr.get( i%N ); + if ( typeof v !== 'number' ) { + b.fail( 'should return a number' ); + } + } + b.toc(); + if ( !isNumber( v ) ) { + b.fail( 'should return a number' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+':get:endianness=big-endian', function benchmark( b ) { + var arr; + var N; + var v; + var i; + + arr = []; + for ( i = 0; i < 10; i++ ) { + arr.push( i ); + } + arr = new Float64ArrayFE( 'big-endian', arr ); + N = arr.length; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = arr.get( i%N ); + if ( typeof v !== 'number' ) { + b.fail( 'should return a number' ); + } + } + b.toc(); + if ( !isNumber( v ) ) { + b.fail( 'should return a number' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/fixed-endian-factory/benchmark/benchmark.instantiation.js b/lib/node_modules/@stdlib/array/fixed-endian-factory/benchmark/benchmark.instantiation.js new file mode 100644 index 00000000000..70386eaf35d --- /dev/null +++ b/lib/node_modules/@stdlib/array/fixed-endian-factory/benchmark/benchmark.instantiation.js @@ -0,0 +1,440 @@ +/** +* @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 ArrayBuffer = require( '@stdlib/array/buffer' ); +var Float64Array = require( '@stdlib/array/float64' ); +var ITERATOR_SYMBOL = require( '@stdlib/symbol/iterator' ); +var pkg = require( './../package.json' ).name; +var factory = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': ( ITERATOR_SYMBOL === null ) +}; +var Float64ArrayFE = factory( 'float64' ); + + +// FUNCTIONS // + +/** +* Returns an "iterable" object. +* +* @private +* @returns {Object} iterable object +*/ +function createIterable() { + var out = {}; + out[ ITERATOR_SYMBOL ] = iterator; + return out; + + function iterator() { + return { + 'next': next + }; + } + + function next() { + return { + 'done': true + }; + } +} + + +// MAIN // + +bench( pkg+'::instantiation,new:endianness=little-endian', function benchmark( b ) { + var arr; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = new Float64ArrayFE( 'little-endian' ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayFE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::instantiation,new:endianness=big-endian', function benchmark( b ) { + var arr; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = new Float64ArrayFE( 'big-endian' ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayFE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::instantiation,no_new:endianness=little-endian', function benchmark( b ) { + var ctor; + var arr; + var i; + + ctor = Float64ArrayFE; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = ctor( 'little-endian' ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayFE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::instantiation,no_new:endianness=big-endian', function benchmark( b ) { + var ctor; + var arr; + var i; + + ctor = Float64ArrayFE; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = ctor( 'big-endian' ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayFE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::instantiation,length:endianness=little-endian', function benchmark( b ) { + var arr; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = new Float64ArrayFE( 'little-endian', 0 ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayFE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::instantiation,length:endianness=big-endian', function benchmark( b ) { + var arr; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = new Float64ArrayFE( 'big-endian', 0 ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayFE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::instantiation,typed_array:endianness=little-endian', function benchmark( b ) { + var buf; + var arr; + var i; + + buf = new Float64Array( 0 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = new Float64ArrayFE( 'little-endian', buf ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayFE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::instantiation,typed_array:endianness=big-endian', function benchmark( b ) { + var buf; + var arr; + var i; + + buf = new Float64Array( 0 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = new Float64ArrayFE( 'big-endian', buf ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayFE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::instantiation,array:endianness=little-endian', function benchmark( b ) { + var buf; + var arr; + var i; + + buf = []; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = new Float64ArrayFE( 'little-endian', buf ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayFE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::instantiation,array:endianness=big-endian', function benchmark( b ) { + var buf; + var arr; + var i; + + buf = []; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = new Float64ArrayFE( 'big-endian', buf ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayFE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::instantiation,iterable:endianness=little-endian', opts, function benchmark( b ) { + var arr; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = new Float64ArrayFE( 'little-endian', createIterable() ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayFE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::instantiation,iterable:endianness=big-endian', opts, function benchmark( b ) { + var arr; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = new Float64ArrayFE( 'big-endian', createIterable() ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayFE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::instantiation,arraybuffer:endianness=little-endian', function benchmark( b ) { + var buf; + var arr; + var i; + + buf = new ArrayBuffer( 0 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = new Float64ArrayFE( 'little-endian', buf ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayFE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::instantiation,arraybuffer:endianness=big-endian', function benchmark( b ) { + var buf; + var arr; + var i; + + buf = new ArrayBuffer( 0 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = new Float64ArrayFE( 'big-endian', buf ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayFE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::instantiation,arraybuffer,byte_offset:endianness=little-endian', function benchmark( b ) { + var buf; + var arr; + var i; + + buf = new ArrayBuffer( 8 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = new Float64ArrayFE( 'little-endian', buf, 8 ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayFE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::instantiation,arraybuffer,byte_offset:endianness=big-endian', function benchmark( b ) { + var buf; + var arr; + var i; + + buf = new ArrayBuffer( 8 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = new Float64ArrayFE( 'big-endian', buf, 8 ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayFE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::instantiation,arraybuffer,byte_offset,length:endianness=little-endian', function benchmark( b ) { + var buf; + var arr; + var i; + + buf = new ArrayBuffer( 8 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = new Float64ArrayFE( 'little-endian', buf, 8, 0 ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayFE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::instantiation,arraybuffer,byte_offset,length:endianness=big-endian', function benchmark( b ) { + var buf; + var arr; + var i; + + buf = new ArrayBuffer( 8 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = new Float64ArrayFE( 'big-endian', buf, 8, 0 ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayFE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/fixed-endian-factory/benchmark/benchmark.js b/lib/node_modules/@stdlib/array/fixed-endian-factory/benchmark/benchmark.js new file mode 100644 index 00000000000..619c1f968f4 --- /dev/null +++ b/lib/node_modules/@stdlib/array/fixed-endian-factory/benchmark/benchmark.js @@ -0,0 +1,48 @@ +/** +* @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 isFunction = require( '@stdlib/assert/is-function' ); +var pkg = require( './../package.json' ).name; +var factory = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = factory( 'float64' ); + if ( typeof v !== 'function' ) { + b.fail( 'should return a function' ); + } + } + b.toc(); + if ( !isFunction( v ) ) { + b.fail( 'should return a function' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/fixed-endian-factory/benchmark/benchmark.of.js b/lib/node_modules/@stdlib/array/fixed-endian-factory/benchmark/benchmark.of.js new file mode 100644 index 00000000000..273c669ae6c --- /dev/null +++ b/lib/node_modules/@stdlib/array/fixed-endian-factory/benchmark/benchmark.of.js @@ -0,0 +1,74 @@ +/** +* @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 pkg = require( './../package.json' ).name; +var factory = require( './../lib' ); + + +// VARIABLES // + +var Float64ArrayFE = factory( 'float64' ); + + +// MAIN // + +bench( pkg+':of', function benchmark( b ) { + var arr; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = Float64ArrayFE.of( 'little-endian' ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayFE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+':len=5', function benchmark( b ) { + var buf; + var arr; + var i; + + buf = [ 'little-endian', 1.0, 1.0, 1.0, 1.0, 1.0 ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = Float64ArrayFE.of.apply( Float64ArrayFE, buf ); + if ( arr.length !== 5 ) { + b.fail( 'should have length 5' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayFE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/fixed-endian-factory/benchmark/benchmark.property_access.js b/lib/node_modules/@stdlib/array/fixed-endian-factory/benchmark/benchmark.property_access.js new file mode 100644 index 00000000000..e3f26a0feb9 --- /dev/null +++ b/lib/node_modules/@stdlib/array/fixed-endian-factory/benchmark/benchmark.property_access.js @@ -0,0 +1,127 @@ +/** +* @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 isArrayBuffer = require( '@stdlib/assert/is-arraybuffer' ); +var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).isPrimitive; +var pkg = require( './../package.json' ).name; +var factory = require( './../lib' ); + + +// VARIABLES // + +var Float64ArrayFE = factory( 'float64' ); + + +// MAIN // + +bench( pkg+'::get:buffer', function benchmark( b ) { + var arr; + var v; + var i; + + arr = new Float64ArrayFE( 'little-endian' ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + // Note: the following may be optimized away due to loop invariant code motion and/or other compiler optimizations, rendering this benchmark meaningless... + v = arr.buffer; + if ( typeof v !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isArrayBuffer( v ) ) { + b.fail( 'should return an ArrayBuffer' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::get:byteLength', function benchmark( b ) { + var arr; + var v; + var i; + + arr = new Float64ArrayFE( 'little-endian' ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + // Note: the following may be optimized away due to loop invariant code motion and/or other compiler optimizations, rendering this benchmark meaningless... + v = arr.byteLength; + if ( v !== v ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( !isNonNegativeInteger( v ) ) { + b.fail( 'should return a nonnegative integer' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::get:byteOffset', function benchmark( b ) { + var arr; + var v; + var i; + + arr = new Float64ArrayFE( 'little-endian' ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + // Note: the following may be optimized away due to loop invariant code motion and/or other compiler optimizations, rendering this benchmark meaningless... + v = arr.byteOffset; + if ( v !== v ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( !isNonNegativeInteger( v ) ) { + b.fail( 'should return a nonnegative integer' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::get:length', function benchmark( b ) { + var arr; + var v; + var i; + + arr = new Float64ArrayFE( 'little-endian' ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + // Note: the following may be optimized away due to loop invariant code motion and/or other compiler optimizations, rendering this benchmark meaningless... + v = arr.length; + if ( v !== v ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( !isNonNegativeInteger( v ) ) { + b.fail( 'should return a nonnegative integer' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/fixed-endian-factory/benchmark/benchmark.set.js b/lib/node_modules/@stdlib/array/fixed-endian-factory/benchmark/benchmark.set.js new file mode 100644 index 00000000000..95ff079d7ca --- /dev/null +++ b/lib/node_modules/@stdlib/array/fixed-endian-factory/benchmark/benchmark.set.js @@ -0,0 +1,214 @@ +/** +* @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 Float64Array = require( '@stdlib/array/float64' ); +var pkg = require( './../package.json' ).name; +var factory = require( './../lib' ); + + +// VARIABLES // + +var Float64ArrayFE = factory( 'float64' ); + + +// MAIN // + +bench( pkg+'::number:set:endianness=little-endian', function benchmark( b ) { + var values; + var arr; + var N; + var v; + var i; + + values = []; + for ( i = 0; i < 10; i++ ) { + values.push( i ); + } + arr = new Float64ArrayFE( 'little-endian', values ); + N = arr.length; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = arr.set( values[ (i+1)%N ] ); + if ( typeof v !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + } + b.toc(); + if ( typeof v !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::number:set:endianness=big-endian', function benchmark( b ) { + var values; + var arr; + var N; + var v; + var i; + + values = []; + for ( i = 0; i < 10; i++ ) { + values.push( i ); + } + arr = new Float64ArrayFE( 'big-endian', values ); + N = arr.length; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = arr.set( values[ (i+1)%N ] ); + if ( typeof v !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + } + b.toc(); + if ( typeof v !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::array:set:endianness=little-endian', function benchmark( b ) { + var values; + var arr; + var N; + var v; + var i; + + values = []; + for ( i = 0; i < 10; i++ ) { + values.push( i ); + } + arr = new Float64ArrayFE( 'little-endian', values ); + N = arr.length; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = arr.set( [ values[ (i+1)%N ] ] ); + if ( typeof v !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + } + b.toc(); + if ( typeof v !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::array:set:endianness=big-endian', function benchmark( b ) { + var values; + var arr; + var N; + var v; + var i; + + values = []; + for ( i = 0; i < 10; i++ ) { + values.push( i ); + } + arr = new Float64ArrayFE( 'big-endian', values ); + N = arr.length; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = arr.set( [ values[ (i+1)%N ] ] ); + if ( typeof v !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + } + b.toc(); + if ( typeof v !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::typed_array:set:endianness=little-endian', function benchmark( b ) { + var values; + var arr; + var buf; + var N; + var v; + var i; + + values = new Float64Array( 20 ); + N = values.length; + for ( i = 0; i < N; i++ ) { + values[ i ] = i; + } + arr = new Float64ArrayFE( 'little-endian', values ); + buf = new Float64Array( 1 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + buf[ 0 ] = values[ i%N ]; + v = arr.set( buf ); + if ( typeof v !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + } + b.toc(); + if ( typeof v !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::typed_array:set:endianness=big-endian', function benchmark( b ) { + var values; + var arr; + var buf; + var N; + var v; + var i; + + values = new Float64Array( 20 ); + N = values.length; + for ( i = 0; i < N; i++ ) { + values[ i ] = i; + } + arr = new Float64ArrayFE( 'big-endian', values ); + buf = new Float64Array( 1 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + buf[ 0 ] = values[ i%N ]; + v = arr.set( buf ); + if ( typeof v !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + } + b.toc(); + if ( typeof v !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/fixed-endian-factory/benchmark/benchmark.set.length.js b/lib/node_modules/@stdlib/array/fixed-endian-factory/benchmark/benchmark.set.length.js new file mode 100644 index 00000000000..c459e9559c6 --- /dev/null +++ b/lib/node_modules/@stdlib/array/fixed-endian-factory/benchmark/benchmark.set.length.js @@ -0,0 +1,115 @@ +/** +* @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 pow = require( '@stdlib/math/base/special/pow' ); +var randu = require( '@stdlib/random/array/randu' ); +var pkg = require( './../package.json' ).name; +var factory = require( './../lib' ); + + +// VARIABLES // + +var Float64ArrayFE = factory( 'float64' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var values; + var arr1; + var arr2; + var arr3; + var N; + + arr1 = randu( len ); + arr2 = randu( len ); + arr3 = randu( len ); + arr1 = new Float64ArrayFE( 'little-endian', arr1 ); + + values = [ + new Float64ArrayFE( 'little-endian', arr2 ), + new Float64ArrayFE( 'big-endian', arr3 ) + ]; + N = values.length; + + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = arr1.set( values[ i%N ] ); + if ( typeof v !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + } + b.toc(); + if ( typeof v !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':set:len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/fixed-endian-factory/benchmark/benchmark.to_string.js b/lib/node_modules/@stdlib/array/fixed-endian-factory/benchmark/benchmark.to_string.js new file mode 100644 index 00000000000..47494aa76e3 --- /dev/null +++ b/lib/node_modules/@stdlib/array/fixed-endian-factory/benchmark/benchmark.to_string.js @@ -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. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var pkg = require( './../package.json' ).name; +var factory = require( './../lib' ); + + +// VARIABLES // + +var Float64ArrayFE = factory( 'float64' ); + + +// MAIN // + +bench( pkg+':toString', function benchmark( b ) { + var out; + var arr; + var i; + + arr = new Float64ArrayFE( 'little-endian', [ 1.0, 2.0, 2.0, 1.0 ] ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.toString(); + if ( typeof out !== 'string' ) { + b.fail( 'should return a string' ); + } + } + b.toc(); + if ( typeof out !== 'string' ) { + b.fail( 'should return a string' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/fixed-endian-factory/benchmark/benchmark.to_string.length.js b/lib/node_modules/@stdlib/array/fixed-endian-factory/benchmark/benchmark.to_string.length.js new file mode 100644 index 00000000000..4378a5c9909 --- /dev/null +++ b/lib/node_modules/@stdlib/array/fixed-endian-factory/benchmark/benchmark.to_string.length.js @@ -0,0 +1,99 @@ +/** +* @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 pow = require( '@stdlib/math/base/special/pow' ); +var zeroTo = require( '@stdlib/array/zero-to' ); +var pkg = require( './../package.json' ).name; +var factory = require( './../lib' ); + + +// VARIABLES // + +var Float64ArrayFE = factory( 'float64' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var arr = new Float64ArrayFE( 'little-endian', zeroTo( len ) ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.toString(); + if ( typeof out !== 'string' ) { + b.fail( 'should return a string' ); + } + } + b.toc(); + if ( typeof out !== 'string' ) { + b.fail( 'should return a string' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':toString:len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/fixed-endian-factory/examples/index.js b/lib/node_modules/@stdlib/array/fixed-endian-factory/examples/index.js new file mode 100644 index 00000000000..f0aa9e3f8c7 --- /dev/null +++ b/lib/node_modules/@stdlib/array/fixed-endian-factory/examples/index.js @@ -0,0 +1,44 @@ +/** +* @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 Float64Array = require( '@stdlib/array/float64' ); +var logEach = require( '@stdlib/console/log-each' ); +var factory = require( './../lib' ); + +var Float64ArrayFE = factory( 'float64' ); + +// Create a typed array by specifying a length: +var out = new Float64ArrayFE( 'little-endian', 3 ); +logEach( '%s', out ); + +// Create a typed array from an array: +var arr = [ 1.0, -1.0, -3.14, 3.14, 0.5, 0.5 ]; +out = new Float64ArrayFE( 'big-endian', arr ); +logEach( '%s', out ); + +// Create a typed array from an array buffer: +arr = new Float64Array( [ 1.0, -1.0, -3.14, 3.14, 0.5, 0.5 ] ); // host byte order +out = new Float64ArrayFE( 'little-endian', arr.buffer ); +logEach( '%s', out ); + +// Create a typed array from an array buffer view: +arr = new Float64Array( [ 1.0, -1.0, -3.14, 3.14, 0.5, 0.5 ] ); // host byte order +out = new Float64ArrayFE( 'big-endian', arr.buffer, 8, 2 ); +logEach( '%s', out ); diff --git a/lib/node_modules/@stdlib/array/fixed-endian-factory/lib/from_iterator.js b/lib/node_modules/@stdlib/array/fixed-endian-factory/lib/from_iterator.js new file mode 100644 index 00000000000..c1adb5d9a18 --- /dev/null +++ b/lib/node_modules/@stdlib/array/fixed-endian-factory/lib/from_iterator.js @@ -0,0 +1,48 @@ +/** +* @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'; + +// MAIN // + +/** +* Returns an array of iterated values. +* +* @private +* @param {Object} it - iterator +* @returns {Array} output array +*/ +function fromIterator( it ) { + var out; + var v; + + out = []; + while ( true ) { + v = it.next(); + if ( v.done ) { + break; + } + out.push( v.value ); + } + return out; +} + + +// EXPORTS // + +module.exports = fromIterator; diff --git a/lib/node_modules/@stdlib/array/fixed-endian-factory/lib/from_iterator_map.js b/lib/node_modules/@stdlib/array/fixed-endian-factory/lib/from_iterator_map.js new file mode 100644 index 00000000000..9a6e354eb8a --- /dev/null +++ b/lib/node_modules/@stdlib/array/fixed-endian-factory/lib/from_iterator_map.js @@ -0,0 +1,53 @@ +/** +* @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'; + +// MAIN // + +/** +* Returns an array of iterated values. +* +* @private +* @param {Object} it - iterator +* @param {Function} clbk - callback to invoke for each iterated value +* @param {*} thisArg - invocation context +* @returns {Array} output array +*/ +function fromIteratorMap( it, clbk, thisArg ) { + var out; + var v; + var i; + + out = []; + i = -1; + while ( true ) { + v = it.next(); + if ( v.done ) { + break; + } + i += 1; + out.push( clbk.call( thisArg, v.value, i ) ); + } + return out; +} + + +// EXPORTS // + +module.exports = fromIteratorMap; diff --git a/lib/node_modules/@stdlib/array/fixed-endian-factory/lib/index.js b/lib/node_modules/@stdlib/array/fixed-endian-factory/lib/index.js new file mode 100644 index 00000000000..0183dad6719 --- /dev/null +++ b/lib/node_modules/@stdlib/array/fixed-endian-factory/lib/index.js @@ -0,0 +1,106 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Return a typed array constructor for creating typed arrays having a specified byte order. +* +* @module @stdlib/array/fixed-endian-factory +* +* @example +* var factory = require( '@stdlib/array/fixed-endian-factory' ); +* +* var Float64ArrayFE = factory( 'float64' ); +* +* var arr = new Float64ArrayFE( 'little-endian' ); +* // returns +* +* var len = arr.length; +* // returns 0 +* +* @example +* var factory = require( '@stdlib/array/fixed-endian-factory' ); +* +* var Float64ArrayFE = factory( 'float64' ); +* +* var arr = new Float64ArrayFE( 'little-endian', 2 ); +* // returns +* +* var len = arr.length; +* // returns 2 +* +* @example +* var factory = require( '@stdlib/array/fixed-endian-factory' ); +* +* var Float64ArrayFE = factory( 'float64' ); +* +* var arr = new Float64ArrayFE( 'little-endian', [ 1.0 ] ); +* // returns +* +* var len = arr.length; +* // returns 1 +* +* @example +* var ArrayBuffer = require( '@stdlib/array/buffer' ); +* var factory = require( '@stdlib/array/fixed-endian-factory' ); +* +* var Float64ArrayFE = factory( 'float64' ); +* +* var buf = new ArrayBuffer( 16 ); +* var arr = new Float64ArrayFE( 'little-endian', buf ); +* // returns +* +* var len = arr.length; +* // returns 2 +* +* @example +* var ArrayBuffer = require( '@stdlib/array/buffer' ); +* var factory = require( '@stdlib/array/fixed-endian-factory' ); +* +* var Float64ArrayFE = factory( 'float64' ); +* +* var buf = new ArrayBuffer( 16 ); +* var arr = new Float64ArrayFE( 'little-endian', buf, 8 ); +* // returns +* +* var len = arr.length; +* // returns 1 +* +* @example +* var ArrayBuffer = require( '@stdlib/array/buffer' ); +* var factory = require( '@stdlib/array/fixed-endian-factory' ); +* +* var Float64ArrayFE = factory( 'float64' ); +* +* var buf = new ArrayBuffer( 32 ); +* var arr = new Float64ArrayFE( 'little-endian', buf, 8, 2 ); +* // returns +* +* var len = arr.length; +* // returns 2 +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/array/fixed-endian-factory/lib/main.js b/lib/node_modules/@stdlib/array/fixed-endian-factory/lib/main.js new file mode 100644 index 00000000000..70f36fa4eee --- /dev/null +++ b/lib/node_modules/@stdlib/array/fixed-endian-factory/lib/main.js @@ -0,0 +1,730 @@ +/** +* @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. +*/ + +/* eslint-disable max-len, no-restricted-syntax, no-invalid-this, max-lines */ + +'use strict'; + +// MODULES // + +var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).isPrimitive; +var isCollection = require( '@stdlib/assert/is-collection' ); +var isArrayBuffer = require( '@stdlib/assert/is-arraybuffer' ); +var isObject = require( '@stdlib/assert/is-object' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var isString = require( '@stdlib/assert/is-string' ).isPrimitive; +var isByteOrder = require( '@stdlib/array/base/assert/is-byte-order' ); +var lowercase = require( '@stdlib/string/base/lowercase' ); +var hasIteratorSymbolSupport = require( '@stdlib/assert/has-iterator-symbol-support' ); +var ITERATOR_SYMBOL = require( '@stdlib/symbol/iterator' ); +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var isPrototypeOf = require( '@stdlib/assert/is-prototype-of' ); // eslint-disable-line stdlib/no-redeclare +var setReadOnlyAccessor = require( '@stdlib/utils/define-nonenumerable-read-only-accessor' ); +var ArrayBuffer = require( '@stdlib/array/buffer' ); +var DataView = require( '@stdlib/array/dataview' ); +var getter = require( '@stdlib/array/base/getter' ); +var accessorGetter = require( '@stdlib/array/base/accessor-getter' ); +var contains = require( '@stdlib/array/base/assert/contains' ).factory; +var bytesPerElement = require( '@stdlib/ndarray/base/bytes-per-element' ); +var capitalize = require( '@stdlib/string/base/capitalize' ); +var format = require( '@stdlib/string/format' ); +var fromIterator = require( './from_iterator.js' ); +var fromIteratorMap = require( './from_iterator_map.js' ); + + +// VARIABLES // + +var HAS_ITERATOR_SYMBOL = hasIteratorSymbolSupport(); +var DTYPES = [ 'float64', 'float32', 'int32', 'int16', 'uint32', 'uint16' ]; +var DTYPE2SET = { + 'float64': 'setFloat64', + 'float32': 'setFloat32', + 'int32': 'setInt32', + 'int16': 'setInt16', + 'uint32': 'setUint32', + 'uint16': 'setUint16' +}; +var DTYPE2GET = { + 'float64': 'getFloat64', + 'float32': 'getFloat32', + 'int32': 'getInt32', + 'int16': 'getInt16', + 'uint32': 'getUint32', + 'uint16': 'getUint16' +}; +var CHAR2ARTICLE = { + 'c': 'a', + 'f': 'a', + 'i': 'an', + 'u': 'a', + 'b': 'a' +}; +var isDataType = contains( DTYPES ); + + +// FUNCTIONS // + +/** +* Normalizes a byte order value. +* +* @private +* @param {*} value - byte order +* @returns {(string|null)} normalized byte order +*/ +function byteOrder( value ) { + return ( isString( value ) ) ? lowercase( value ) : null; +} + +/** +* Tests whether a provided byte order is little-endian byte order. +* +* @private +* @param {string} value - byte order +* @returns {boolean} boolean indicating whether a byte order is little-endian byte order +*/ +function isLittleEndian( value ) { + return ( value === 'little-endian' ); +} + +/** +* Converts a data type string to a constructor name. +* +* @private +* @param {string} dtype - data type +* @returns {string} constructor name +* +* @example +* var n = dtype2ctor( 'float64' ); +* // returns 'Float64ArrayFE' +* +* @example +* var n = dtype2ctor( 'int32' ); +* // returns 'Int32ArrayFE' +*/ +function dtype2ctor( dtype ) { + return capitalize( dtype ) + 'ArrayFE'; +} + + +// MAIN // + +/** +* Returns a typed array constructor for creating typed arrays having a specified byte order. +* +* @param {string} dtype - typed array data type +* @throws {TypeError} first argument must be a supported data type +* @returns {Function} typed array constructor +* +* @example +* var Float64ArrayFE = factory( 'float64' ); +* +* var arr = new Float64ArrayFE( 'little-endian' ); +* // returns +* +* var len = arr.length; +* // returns 0 +* +* @example +* var Float64ArrayFE = factory( 'float64' ); +* +* var arr = new Float64ArrayFE( 'little-endian', 2 ); +* // returns +* +* var len = arr.length; +* // returns 2 +* +* @example +* var Float64ArrayFE = factory( 'float64' ); +* +* var arr = new Float64ArrayFE( 'little-endian', [ 1.0, 2.0 ] ); +* // returns +* +* var len = arr.length; +* // returns 2 +* +* @example +* var ArrayBuffer = require( '@stdlib/array/buffer' ); +* +* var Float64ArrayFE = factory( 'float64' ); +* +* var buf = new ArrayBuffer( 16 ); +* var arr = new Float64ArrayFE( 'little-endian', buf ); +* // returns +* +* var len = arr.length; +* // returns 2 +* +* @example +* var ArrayBuffer = require( '@stdlib/array/buffer' ); +* +* var Float64ArrayFE = factory( 'float64' ); +* +* var buf = new ArrayBuffer( 16 ); +* var arr = new Float64ArrayFE( 'little-endian', buf, 8 ); +* // returns +* +* var len = arr.length; +* // returns 1 +* +* @example +* var ArrayBuffer = require( '@stdlib/array/buffer' ); +* +* var Float64ArrayFE = factory( 'float64' ); +* +* var buf = new ArrayBuffer( 32 ); +* var arr = new Float64ArrayFE( 'little-endian', buf, 8, 2 ); +* // returns +* +* var len = arr.length; +* // returns 2 +*/ +function factory( dtype ) { // eslint-disable-line max-lines-per-function, stdlib/jsdoc-require-throws-tags + var BYTES_PER_ELEMENT; + var CTOR_NAME; + var GETTER; + var SETTER; + + if ( !isDataType( dtype ) ) { + throw new TypeError( format( 'invalid argument. First argument must be a supported data type. Value: `%s`.', dtype ) ); + } + BYTES_PER_ELEMENT = bytesPerElement( dtype ); + CTOR_NAME = dtype2ctor( dtype ); + GETTER = DTYPE2GET[ dtype ]; + SETTER = DTYPE2SET[ dtype ]; + + /** + * Typed array constructor which returns a typed array representing an array of values in a specified byte order. + * + * @private + * @constructor + * @param {string} endianness - byte order + * @param {(NonNegativeInteger|Collection|ArrayBuffer|Iterable)} [arg] - length, typed array, array-like object, buffer, or an iterable + * @param {NonNegativeInteger} [byteOffset=0] - byte offset + * @param {NonNegativeInteger} [length] - view length + * @throws {TypeError} first argument must be a supported byte order + * @throws {TypeError} if provided only two arguments, the second argument must be a valid argument + * @throws {TypeError} byte offset must be a nonnegative integer + * @throws {RangeError} must provide sufficient memory to accommodate byte offset and view length requirements + * @returns {TypedArray} typed array instance + */ + function TypedArray() { + var byteOffset; + var endianness; + var nargs; + var isLE; + var buf; + var len; + var arg; + var tmp; + + nargs = arguments.length; + if ( !(this instanceof TypedArray) ) { + if ( nargs < 2 ) { + return new TypedArray( arguments[0] ); + } + if ( nargs === 2 ) { + return new TypedArray( arguments[0], arguments[1] ); + } + if ( nargs === 3 ) { + return new TypedArray( arguments[0], arguments[1], arguments[2] ); + } + return new TypedArray( arguments[0], arguments[1], arguments[2], arguments[3] ); + } + endianness = byteOrder( arguments[ 0 ] ); + if ( endianness === null || !isByteOrder( endianness ) ) { + throw new TypeError( format( 'invalid argument. First argument must be a supported byte order. Value: `%s`.', arguments[ 0 ] ) ); + } + isLE = isLittleEndian( endianness ); + + nargs -= 1; + + // Create the underlying data buffer... + if ( nargs === 0 ) { + buf = new DataView( new ArrayBuffer( 0 ) ); // backward-compatibility + } else if ( nargs === 1 ) { + arg = arguments[ nargs ]; + if ( isNonNegativeInteger( arg ) ) { + buf = new DataView( new ArrayBuffer( arg*BYTES_PER_ELEMENT ) ); + } else if ( isCollection( arg ) ) { + buf = fromArray( new DataView( new ArrayBuffer( arg.length*BYTES_PER_ELEMENT ) ), arg, isLE ); + } else if ( isArrayBuffer( arg ) ) { + buf = new DataView( arg ); + } else if ( isObject( arg ) ) { + if ( HAS_ITERATOR_SYMBOL === false ) { + throw new TypeError( format( 'invalid argument. Environment lacks Symbol.iterator support. Must provide a length, ArrayBuffer, typed array, or array-like object. Value: `%s`.', arg ) ); + } + if ( !isFunction( arg[ ITERATOR_SYMBOL ] ) ) { + throw new TypeError( format( 'invalid argument. Must provide a length, ArrayBuffer, typed array, array-like object, or an iterable. Value: `%s`.', arg ) ); + } + buf = arg[ ITERATOR_SYMBOL ](); + if ( !isFunction( buf.next ) ) { + throw new TypeError( format( 'invalid argument. Must provide a length, ArrayBuffer, typed array, array-like object, or an iterable. Value: `%s`.', arg ) ); + } + tmp = fromIterator( buf ); + buf = fromArray( new DataView( new ArrayBuffer( tmp.length*BYTES_PER_ELEMENT ) ), tmp, isLE ); + } else { + throw new TypeError( format( 'invalid argument. Must provide a length, ArrayBuffer, typed array, array-like object, or an iterable. Value: `%s`.', arg ) ); + } + } else { + buf = arguments[ 1 ]; + if ( !isArrayBuffer( buf ) ) { + throw new TypeError( format( 'invalid argument. Must provide an ArrayBuffer. Value: `%s`.', buf ) ); + } + byteOffset = arguments[ 2 ]; + if ( !isNonNegativeInteger( byteOffset ) ) { + throw new TypeError( format( 'invalid argument. Byte offset must be a nonnegative integer. Value: `%s`.', byteOffset ) ); + } + if ( nargs === 2 ) { + buf = new DataView( buf, byteOffset ); + } else { + len = arguments[ 3 ]; + if ( !isNonNegativeInteger( len ) ) { + throw new TypeError( format( 'invalid argument. Length must be a nonnegative integer. Value: `%s`.', len ) ); + } + len *= BYTES_PER_ELEMENT; + if ( len > (buf.byteLength-byteOffset) ) { + throw new RangeError( format( 'invalid arguments. ArrayBuffer has insufficient capacity. Either decrease the array length or provide a bigger buffer. Minimum capacity: `%u`.', len ) ); + } + buf = new DataView( buf, byteOffset, len ); + } + } + setReadOnly( this, '_buffer', buf ); + setReadOnly( this, '_length', buf.byteLength/BYTES_PER_ELEMENT ); + setReadOnly( this, '_isLE', isLE ); + + return this; + } + + /** + * Size (in bytes) of each array element. + * + * @private + * @name BYTES_PER_ELEMENT + * @memberof TypedArray + * @readonly + * @type {PositiveInteger} + */ + setReadOnly( TypedArray, 'BYTES_PER_ELEMENT', BYTES_PER_ELEMENT ); + + /** + * Constructor name. + * + * @private + * @name name + * @memberof TypedArray + * @readonly + * @type {string} + */ + setReadOnly( TypedArray, 'name', CTOR_NAME ); + + /** + * Creates a new typed array from an array-like object or an iterable. + * + * @private + * @name from + * @memberof TypedArray + * @type {Function} + * @param {string} endianness - byte order + * @param {(Collection|Iterable)} src - array-like object or iterable + * @param {Function} [clbk] - callback to invoke for each source element + * @param {*} [thisArg] - context + * @throws {TypeError} `this` context must be a constructor + * @throws {TypeError} `this` must be a typed array constructor + * @throws {TypeError} first argument must be a supported byte order + * @throws {TypeError} second argument must be an array-like object or an iterable + * @throws {TypeError} third argument must be a function + * @returns {TypedArray} typed array instance + */ + setReadOnly( TypedArray, 'from', function from( endianness, src ) { + var thisArg; + var order; + var nargs; + var clbk; + var isLE; + var out; + var buf; + var tmp; + var get; + var len; + var i; + if ( !isFunction( this ) ) { + throw new TypeError( 'invalid invocation. `this` context must be a constructor.' ); + } + if ( !isTypedArrayConstructor( this ) ) { + throw new TypeError( format( 'invalid invocation. `this` is not %s %s.', CHAR2ARTICLE[ dtype[0] ], CTOR_NAME ) ); + } + order = byteOrder( endianness ); + if ( order === null || !isByteOrder( order ) ) { + throw new TypeError( format( 'invalid argument. First argument must be a supported byte order. Value: `%s`.', endianness ) ); + } + isLE = isLittleEndian( order ); + + nargs = arguments.length; + if ( nargs > 2 ) { + clbk = arguments[ 2 ]; + if ( !isFunction( clbk ) ) { + throw new TypeError( format( 'invalid argument. Third argument must be a function. Value: `%s`.', clbk ) ); + } + if ( nargs > 3 ) { + thisArg = arguments[ 3 ]; + } + } + if ( isCollection( src ) ) { + if ( clbk ) { + len = src.length; + if ( src.get && src.set ) { + get = accessorGetter( 'default' ); + } else { + get = getter( 'default' ); + } + out = new this( order, len ); + buf = out._buffer; // eslint-disable-line no-underscore-dangle + for ( i = 0; i < len; i++ ) { + buf[ SETTER ]( i*BYTES_PER_ELEMENT, clbk.call( thisArg, get( src, i ), i ), isLE ); + } + return out; + } + return new this( order, src ); + } + if ( isObject( src ) && HAS_ITERATOR_SYMBOL && isFunction( src[ ITERATOR_SYMBOL ] ) ) { + buf = src[ ITERATOR_SYMBOL ](); + if ( !isFunction( buf.next ) ) { + throw new TypeError( format( 'invalid argument. Second argument must be an array-like object or an iterable. Value: `%s`.', src ) ); + } + if ( clbk ) { + tmp = fromIteratorMap( buf, clbk, thisArg ); + } else { + tmp = fromIterator( buf ); + } + len = tmp.length; + out = new this( order, len ); + buf = out._buffer; // eslint-disable-line no-underscore-dangle + for ( i = 0; i < len; i++ ) { + buf[ SETTER ]( i*BYTES_PER_ELEMENT, tmp[ i ], isLE ); + } + return out; + } + throw new TypeError( format( 'invalid argument. Second argument must be an array-like object or an iterable. Value: `%s`.', src ) ); + }); + + /** + * Creates a new typed array from a variable number of arguments. + * + * @private + * @name of + * @memberof TypedArray + * @type {Function} + * @param {string} endianness - byte order + * @param {...*} element - array elements + * @throws {TypeError} `this` context must be a constructor + * @throws {TypeError} `this` must be a typed array constructor + * @throws {TypeError} first argument must be a supported byte order + * @returns {TypedArray} typed array instance + */ + setReadOnly( TypedArray, 'of', function of( endianness ) { + var order; + var args; + var i; + if ( !isFunction( this ) ) { + throw new TypeError( 'invalid invocation. `this` context must be a constructor.' ); + } + if ( !isTypedArrayConstructor( this ) ) { + throw new TypeError( format( 'invalid invocation. `this` is not %s %s.', CHAR2ARTICLE[ dtype[0] ], CTOR_NAME ) ); + } + order = byteOrder( endianness ); + if ( order === null || !isByteOrder( order ) ) { + throw new TypeError( format( 'invalid argument. First argument must be a supported byte order. Value: `%s`.', endianness ) ); + } + args = []; + for ( i = 1; i < arguments.length; i++ ) { + args.push( arguments[ i ] ); + } + return new this( order, args ); + }); + + /** + * Pointer to the underlying data buffer. + * + * @private + * @name buffer + * @memberof TypedArray.prototype + * @readonly + * @type {ArrayBuffer} + */ + setReadOnlyAccessor( TypedArray.prototype, 'buffer', function get() { + return this._buffer.buffer; + }); + + /** + * Size (in bytes) of the array. + * + * @private + * @name byteLength + * @memberof TypedArray.prototype + * @readonly + * @type {NonNegativeInteger} + */ + setReadOnlyAccessor( TypedArray.prototype, 'byteLength', function get() { + return this._buffer.byteLength; + }); + + /** + * Offset (in bytes) of the array from the start of its underlying `ArrayBuffer`. + * + * @private + * @name byteOffset + * @memberof TypedArray.prototype + * @readonly + * @type {NonNegativeInteger} + */ + setReadOnlyAccessor( TypedArray.prototype, 'byteOffset', function get() { + return this._buffer.byteOffset; + }); + + /** + * Size (in bytes) of each array element. + * + * @private + * @name BYTES_PER_ELEMENT + * @memberof TypedArray.prototype + * @readonly + * @type {PositiveInteger} + */ + setReadOnly( TypedArray.prototype, 'BYTES_PER_ELEMENT', TypedArray.BYTES_PER_ELEMENT ); + + /** + * Returns an array element. + * + * @private + * @name get + * @memberof TypedArray.prototype + * @type {Function} + * @param {NonNegativeInteger} idx - element index + * @throws {TypeError} `this` must be a typed array instance + * @throws {TypeError} must provide a nonnegative integer + * @returns {(*|void)} array element + */ + setReadOnly( TypedArray.prototype, 'get', function get( idx ) { + if ( !isTypedArray( this ) ) { + throw new TypeError( format( 'invalid invocation. `this` is not %s %s.', CHAR2ARTICLE[ dtype[0] ], CTOR_NAME ) ); + } + if ( !isNonNegativeInteger( idx ) ) { + throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', idx ) ); + } + if ( idx >= this._length ) { + return; + } + return this._buffer[ GETTER ]( idx*BYTES_PER_ELEMENT, this._isLE ); + }); + + /** + * Number of array elements. + * + * @private + * @name length + * @memberof TypedArray.prototype + * @readonly + * @type {NonNegativeInteger} + */ + setReadOnlyAccessor( TypedArray.prototype, 'length', function get() { + return this._length; + }); + + /** + * Sets an array element. + * + * ## Notes + * + * - When provided a typed array, we must check whether the source array shares the same buffer as the target array and whether the underlying memory overlaps. In particular, we are concerned with the following scenario: + * + * ```text + * buf: --------------------- + * src: --------------------- + * ``` + * + * In the above, as we copy values from `src`, we will overwrite values in the `src` view, resulting in duplicated values copied into the end of `buf`, which is not intended. Hence, to avoid overwriting source values, we must **copy** source values to a temporary array. + * + * In the other overlapping scenario, + * + * ```text + * buf: --------------------- + * src: --------------------- + * ``` + * + * by the time we begin copying into the overlapping region, we are copying from the end of `src`, a non-overlapping region, which means we don't run the risk of copying copied values, rather than the original `src` values, as intended. + * + * @private + * @name set + * @memberof TypedArray.prototype + * @type {Function} + * @param {(Collection|TypedArray|*)} value - value(s) + * @param {NonNegativeInteger} [i=0] - element index at which to start writing values + * @throws {TypeError} `this` must be a typed array instance + * @throws {TypeError} index argument must be a nonnegative integer + * @throws {RangeError} index argument is out-of-bounds + * @throws {RangeError} target array lacks sufficient storage to accommodate source values + * @returns {void} + */ + setReadOnly( TypedArray.prototype, 'set', function set( value ) { + var sbuf; + var idx; + var buf; + var tmp; + var get; + var N; + var i; + var j; + if ( !isTypedArray( this ) ) { + throw new TypeError( format( 'invalid invocation. `this` is not %s %s.', CHAR2ARTICLE[ dtype[0] ], CTOR_NAME ) ); + } + buf = this._buffer; + if ( arguments.length > 1 ) { + idx = arguments[ 1 ]; + if ( !isNonNegativeInteger( idx ) ) { + throw new TypeError( format( 'invalid argument. Index argument must be a nonnegative integer. Value: `%s`.', idx ) ); + } + } else { + idx = 0; + } + if ( isCollection( value ) ) { + N = value.length; + if ( idx+N > this._length ) { + throw new RangeError( 'invalid arguments. Target array lacks sufficient storage to accommodate source values.' ); + } + sbuf = value; + if ( sbuf.get && sbuf.set ) { + get = accessorGetter( 'default' ); + } else { + get = getter( 'default' ); + } + // Check for overlapping memory... + j = buf.byteOffset + (idx*BYTES_PER_ELEMENT); + if ( + sbuf.buffer === buf.buffer && + ( + sbuf.byteOffset < j && + sbuf.byteOffset+sbuf.byteLength > j + ) + ) { + // We need to copy source values... + tmp = []; + for ( i = 0; i < value.length; i++ ) { + tmp.push( get( value, i ) ); + } + sbuf = tmp; + get = getter( 'default' ); + } + for ( i = 0; i < N; idx++, i++ ) { + buf[ SETTER ]( idx*BYTES_PER_ELEMENT, get( sbuf, i ), this._isLE ); + } + return; + } + if ( idx >= this._length ) { + throw new RangeError( format( 'invalid argument. Index argument is out-of-bounds. Value: `%u`.', idx ) ); + } + buf[ SETTER ]( idx*BYTES_PER_ELEMENT, value, this._isLE ); + }); + + /** + * Serializes an array as a string. + * + * @private + * @name toString + * @memberof TypedArray.prototype + * @type {Function} + * @throws {TypeError} `this` must be a typed array instance + * @returns {string} string representation + */ + setReadOnly( TypedArray.prototype, 'toString', function toString() { + var out; + var buf; + var i; + if ( !isTypedArray( this ) ) { + throw new TypeError( format( 'invalid invocation. `this` is not %s %s.', CHAR2ARTICLE[ dtype[0] ], CTOR_NAME ) ); + } + out = []; + buf = this._buffer; + for ( i = 0; i < this._length; i++ ) { + out.push( buf[ GETTER ]( i*BYTES_PER_ELEMENT, this._isLE ) ); + } + return out.join( ',' ); + }); + + return TypedArray; + + /** + * Returns a boolean indicating if a value is a typed array constructor. + * + * @private + * @param {*} value - value to test + * @returns {boolean} boolean indicating if a value is a typed array constructor + */ + function isTypedArrayConstructor( value ) { + return ( value === TypedArray ); + } + + /** + * Returns a boolean indicating if a value is a typed array. + * + * @private + * @param {*} value - value to test + * @returns {boolean} boolean indicating if a value is a typed array + */ + function isTypedArray( value ) { + return ( + typeof value === 'object' && + value !== null && + ( + value.constructor.name === CTOR_NAME || + isPrototypeOf( value, TypedArray.prototype ) + ) && + value.BYTES_PER_ELEMENT === BYTES_PER_ELEMENT + ); + } + + /** + * Fills an output DataView with array values. + * + * @private + * @param {DataView} view - output data view + * @param {Array} arr - input array + * @param {boolean} isLE - boolean indicating whether to store values in little-endian byte order + * @returns {DataView} output data view + */ + function fromArray( view, arr, isLE ) { + var len; + var get; + var i; + + len = arr.length; + if ( arr.get && arr.set ) { + get = accessorGetter( 'default' ); + } else { + get = getter( 'default' ); + } + for ( i = 0; i < len; i++ ) { + view[ SETTER ]( i*BYTES_PER_ELEMENT, get( arr, i ), isLE ); + } + return view; + } +} + + +// EXPORTS // + +module.exports = factory; diff --git a/lib/node_modules/@stdlib/array/fixed-endian-factory/package.json b/lib/node_modules/@stdlib/array/fixed-endian-factory/package.json new file mode 100644 index 00000000000..26450528999 --- /dev/null +++ b/lib/node_modules/@stdlib/array/fixed-endian-factory/package.json @@ -0,0 +1,66 @@ +{ + "name": "@stdlib/array/fixed-endian-factory", + "version": "0.0.0", + "description": "Return a typed array constructor for creating typed arrays having a specified byte order.", + "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", + "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", + "stdtypes", + "types", + "data", + "structure", + "array", + "typed", + "typed array", + "typed-array", + "factory", + "endian", + "little-endian", + "big-endian", + "byte-order" + ] +} diff --git a/lib/node_modules/@stdlib/array/fixed-endian-factory/test/test.js b/lib/node_modules/@stdlib/array/fixed-endian-factory/test/test.js new file mode 100644 index 00000000000..99d011d0b56 --- /dev/null +++ b/lib/node_modules/@stdlib/array/fixed-endian-factory/test/test.js @@ -0,0 +1,35 @@ +/** +* @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 factory = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof factory, 'function', 'main export is a function' ); + t.end(); +}); + +// TODO: add tests diff --git a/lib/node_modules/@stdlib/array/fixed-endian-float64/README.md b/lib/node_modules/@stdlib/array/fixed-endian-float64/README.md new file mode 100644 index 00000000000..15f6b978c5e --- /dev/null +++ b/lib/node_modules/@stdlib/array/fixed-endian-float64/README.md @@ -0,0 +1,443 @@ + + +# Float64ArrayFE + +> Typed array constructor which returns a typed array representing an array of double-precision floating-point numbers in a specified byte order. + + + +
+ +In contrast to the [`Float64Array`][@stdlib/array/float64] typed array constructor which stores values according to the host platform byte order, the `Float64ArrayFE` constructor allows enforcing a specific byte order. Such enforcement can be particularly advantageous when working with memory buffers which do not necessarily follow host platform byte order, such as [WebAssembly memory][@stdlib/wasm/memory]. + +
+ + + + + +
+ +## Usage + +```javascript +var Float64ArrayFE = require( '@stdlib/array/fixed-endian-float64' ); +``` + +#### Float64ArrayFE( endianness ) + +A typed array constructor which returns a typed array representing an array of double-precision floating-point numbers in a specified byte order. + +```javascript +var arr = new Float64ArrayFE( 'little-endian' ); +// returns +``` + +#### Float64ArrayFE( endianness, length ) + +Returns a typed array having a specified length and byte order. + +```javascript +var arr = new Float64ArrayFE( 'little-endian', 5 ); +// returns +``` + +#### Float64ArrayFE( endianness, typedarray ) + +Creates a typed array from another typed array. + +```javascript +var Float32Array = require( '@stdlib/array/float32' ); + +var arr1 = new Float32Array( [ 0.5, 0.5, 0.5 ] ); +var arr2 = new Float64ArrayFE( 'little-endian', arr1 ); +// returns + +var v = arr2.get( 0 ); +// returns 0.5 +``` + +#### Float64ArrayFE( endianness, obj ) + +Creates a typed array from an array-like object or iterable. + +```javascript +var arr = new Float64ArrayFE( 'little-endian', [ 0.5, 0.5, 0.5 ] ); +// returns + +var v = arr.get( 0 ); +// returns 0.5 +``` + +#### Float64ArrayFE( endianness, buffer\[, byteOffset\[, length]] ) + +Returns a typed array view of an [`ArrayBuffer`][@stdlib/array/buffer]. + +```javascript +var ArrayBuffer = require( '@stdlib/array/buffer' ); + +var buf = new ArrayBuffer( 32 ); +var arr = new Float64ArrayFE( 'little-endian', buf, 0, 4 ); +// returns +``` + +* * * + +### Properties + + + +#### Float64ArrayFE.BYTES_PER_ELEMENT + +Number of bytes per view element. + +```javascript +var nbytes = Float64ArrayFE.BYTES_PER_ELEMENT; +// returns 8 +``` + + + +#### Float64ArrayFE.name + +Typed array constructor name. + +```javascript +var str = Float64ArrayFE.name; +// returns 'Float64ArrayFE' +``` + + + +#### Float64ArrayFE.prototype.buffer + +**Read-only** property which returns the [`ArrayBuffer`][@stdlib/array/buffer] referenced by the typed array. + +```javascript +var arr = new Float64ArrayFE( 'little-endian', 5 ); +var buf = arr.buffer; +// returns +``` + + + +#### Float64ArrayFE.prototype.byteLength + +**Read-only** property which returns the length (in bytes) of the typed array. + +```javascript +var arr = new Float64ArrayFE( 'little-endian', 5 ); +var byteLength = arr.byteLength; +// returns 40 +``` + + + +#### Float64ArrayFE.prototype.byteOffset + +**Read-only** property which returns the offset (in bytes) of the typed array from the start of its [`ArrayBuffer`][@stdlib/array/buffer]. + +```javascript +var arr = new Float64ArrayFE( 'little-endian', 5 ); +var byteOffset = arr.byteOffset; +// returns 0 +``` + + + +#### Float64ArrayFE.prototype.BYTES_PER_ELEMENT + +Number of bytes per view element. + +```javascript +var arr = new Float64ArrayFE( 'little-endian', 5 ); +var nbytes = arr.BYTES_PER_ELEMENT; +// returns 8 +``` + + + +#### Float64ArrayFE.prototype.length + +**Read-only** property which returns the number of view elements. + +```javascript +var arr = new Float64ArrayFE( 'little-endian', 5 ); +var len = arr.length; +// returns 5 +``` + +* * * + +### Methods + + + +#### Float64ArrayFE.from( endianness, src\[, map\[, thisArg]] ) + +Creates a new typed array from an array-like object or an iterable. + +```javascript +var arr = Float64ArrayFE.from( 'little-endian', [ 1.0, -1.0 ] ); +// returns + +var v = arr.get( 0 ); +// returns 1.0 +``` + +To invoke a function for each `src` value, provide a callback function. + +```javascript +function mapFcn( v ) { + return v * 2.0; +} + +var arr = Float64ArrayFE.from( 'little-endian', [ 1.0, -1.0 ], mapFcn ); +// returns + +var v = arr.get( 0 ); +// returns 2.0 +``` + +A callback function is provided two arguments: + +- **value**: source value. +- **index**: source index. + +To set the callback execution context, provide a `thisArg`. + +```javascript +function mapFcn( v ) { + this.count += 1; + return v * 2.0; +} + +var ctx = { + 'count': 0 +}; + +var arr = Float64ArrayFE.from( 'little-endian', [ 1.0, -1.0 ], mapFcn, ctx ); +// returns + +var v = arr.get( 0 ); +// returns 2.0 + +var n = ctx.count; +// returns 2 +``` + + + +#### Float64ArrayFE.of( endianness, element0\[, element1\[, ...elementN]] ) + +Creates a new typed array from a variable number of arguments. + +```javascript +var arr = Float64ArrayFE.of( 'little-endian', 1.0, -1.0 ); +// returns + +var v = arr.get( 0 ); +// returns 1.0 +``` + + + +#### Float64ArrayFE.prototype.get( i ) + +Returns an array element located at a nonnegative integer position (index) `i`. + +```javascript +var arr = new Float64ArrayFE( 'little-endian', 10 ); + +// Set the first element: +arr.set( 1.0, 0 ); + +// Get the first element: +var v = arr.get( 0 ); +// returns 1.0 +``` + +If provided an out-of-bounds index, the method returns `undefined`. + +```javascript +var arr = new Float64ArrayFE( 'little-endian', 10 ); + +var v = arr.get( 100 ); +// returns undefined +``` + + + +#### Float64ArrayFE.prototype.set( arr\[, offset] ) + +Sets array elements. + +```javascript +var arr = new Float64ArrayFE( 'little-endian', [ 1.0, 2.0, 3.0 ] ); +// returns + +var v = arr.get( 0 ); +// returns 1.0 + +v = arr.get( 1 ); +// returns 2.0 + +// Set the first two array elements: +arr.set( [ 4.0, 5.0 ] ); + +v = arr.get( 0 ); +// returns 4.0 + +v = arr.get( 1 ); +// returns 5.0 +``` + +By default, the method starts writing values at the first array index. To specify an alternative index, provide an index `offset`. + +```javascript +var arr = new Float64ArrayFE( 'little-endian', [ 1.0, 2.0, 3.0 ] ); +// returns + +// Set the last two array elements: +arr.set( [ 4.0, 5.0 ], 1 ); + +var v = arr.get( 1 ); +// returns 4.0 + +v = arr.get( 2 ); +// returns 5.0 +``` + +A few notes: + +- If `i` is out-of-bounds, the method throws an error. +- If a target array cannot accommodate all values (i.e., the length of source array plus `i` exceeds the target array length), the method throws an error. +- If provided a typed array which shares an [`ArrayBuffer`][@stdlib/array/buffer] with the target array, the method will intelligently copy the source range to the destination range. + + + +#### Float64ArrayFE.prototype.toString() + +Serializes an array as a string. + +```javascript +var arr = new Float64ArrayFE( 'little-endian', [ 1.0, 2.0, 3.0 ] ); + +var str = arr.toString(); +// returns '1,2,3' +``` + +
+ + + + + +
+ +* * * + +## Notes + +- The constructor supports the following byte orders: + + - **little-endian**: store values such that bytes are stored from least-to-most significant bytes. This is the dominant ordering for processor architectures and their associated memory. This is also the ordering for [WebAssembly memory][@stdlib/wasm/memory]. + - **big-endian**: store values such that bytes are stored from most-to-least significant bytes. This is the dominant ordering in network protocols. + +- While a `Float64ArrayFE` _strives_ to maintain (but does not **guarantee**) consistency with [typed arrays][@stdlib/array/typed], significant deviations from ECMAScript-defined [typed array][@stdlib/array/typed] behavior are as follows: + + - The constructor does **not** require the `new` operator. + - Accessing array elements using bracket syntax (e.g., `X[i]`) is **not** supported. Instead, one **must** use the `.get()` method. + +
+ + + + + +
+ +* * * + +## Examples + + + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); +var logEach = require( '@stdlib/console/log-each' ); +var Float64ArrayFE = require( '@stdlib/array/fixed-endian-float64' ); + +// Create a typed array by specifying a length: +var out = new Float64ArrayFE( 'little-endian', 3 ); +logEach( '%s', out ); + +// Create a typed array from an array: +var arr = [ 1.0, -1.0, -3.14, 3.14, 0.5, 0.5 ]; +out = new Float64ArrayFE( 'big-endian', arr ); +logEach( '%s', out ); + +// Create a typed array from an array buffer: +arr = new Float64Array( [ 1.0, -1.0, -3.14, 3.14, 0.5, 0.5 ] ); // host byte order +out = new Float64ArrayFE( 'little-endian', arr.buffer ); +logEach( '%s', out ); + +// Create a typed array from an array buffer view: +arr = new Float64Array( [ 1.0, -1.0, -3.14, 3.14, 0.5, 0.5 ] ); // host byte order +out = new Float64ArrayFE( 'big-endian', arr.buffer, 8, 2 ); +logEach( '%s', out ); +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/array/fixed-endian-float64/benchmark/benchmark.from.js b/lib/node_modules/@stdlib/array/fixed-endian-float64/benchmark/benchmark.from.js new file mode 100644 index 00000000000..14aa3d2c4bb --- /dev/null +++ b/lib/node_modules/@stdlib/array/fixed-endian-float64/benchmark/benchmark.from.js @@ -0,0 +1,310 @@ +/** +* @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 Float64Array = require( '@stdlib/array/float64' ); +var ITERATOR_SYMBOL = require( '@stdlib/symbol/iterator' ); +var pkg = require( './../package.json' ).name; +var Float64ArrayFE = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': ( ITERATOR_SYMBOL === null ) +}; + + +// MAIN // + +bench( pkg+'::typed_array:from', function benchmark( b ) { + var buf; + var arr; + var i; + + buf = new Float64Array( 0 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = Float64ArrayFE.from( 'little-endian', buf ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayFE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::typed_array:from:len=5', function benchmark( b ) { + var buf; + var arr; + var i; + + buf = new Float64Array( 5 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = Float64ArrayFE.from( 'little-endian', buf ); + if ( arr.length !== 5 ) { + b.fail( 'should have length 5' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayFE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::typed_array,clbk:from:len=5', function benchmark( b ) { + var buf; + var arr; + var i; + + buf = new Float64Array( 5 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = Float64ArrayFE.from( 'little-endian', buf, clbk ); + if ( arr.length !== 5 ) { + b.fail( 'should have length 5' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayFE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function clbk( v ) { + return v * 2.0; + } +}); + +bench( pkg+'::array:from', function benchmark( b ) { + var buf; + var arr; + var i; + + buf = []; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = Float64ArrayFE.from( 'little-endian', buf ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayFE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::array:from:len=5', function benchmark( b ) { + var buf; + var arr; + var i; + + buf = [ 1.0, 1.0, 1.0, 1.0, 1.0 ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = Float64ArrayFE.from( 'little-endian', buf ); + if ( arr.length !== 5 ) { + b.fail( 'should have length 5' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayFE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::array,clbk:from:len=5', function benchmark( b ) { + var buf; + var arr; + var i; + + buf = [ 1.0, 1.0, 1.0, 1.0, 1.0 ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = Float64ArrayFE.from( 'little-endian', buf, clbk ); + if ( arr.length !== 5 ) { + b.fail( 'should have length 5' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayFE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function clbk( v ) { + return v * 2.0; + } +}); + +bench( pkg+'::iterable:from', opts, function benchmark( b ) { + var arr; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = Float64ArrayFE.from( 'little-endian', createIterable() ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayFE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function createIterable() { + var out = {}; + out[ ITERATOR_SYMBOL ] = iterator; + return out; + + function iterator() { + return { + 'next': next + }; + } + + function next() { + return { + 'done': true + }; + } + } +}); + +bench( pkg+'::iterable:from:len=5', opts, function benchmark( b ) { + var arr; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = Float64ArrayFE.from( 'little-endian', createIterable() ); + if ( arr.length !== 5 ) { + b.fail( 'should have length 5' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayFE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function createIterable() { + var out = {}; + out[ ITERATOR_SYMBOL ] = iterator; + return out; + + function iterator() { + var it = { + 'next': next, + 'i': 0, + 'N': 5 + }; + return it; + + function next() { + it.i += 1; + if ( it.i <= it.N ) { + return { + 'value': 1.0 + }; + } + return { + 'done': true + }; + } + } + } +}); + +bench( pkg+'::iterable,clbk:from:len=5', opts, function benchmark( b ) { + var arr; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = Float64ArrayFE.from( 'little-endian', createIterable(), clbk ); + if ( arr.length !== 5 ) { + b.fail( 'should have length 5' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayFE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function createIterable() { + var out = {}; + out[ ITERATOR_SYMBOL ] = iterator; + return out; + + function iterator() { + var it = { + 'next': next, + 'i': 0, + 'N': 5 + }; + return it; + + function next() { + it.i += 1; + if ( it.i <= it.N ) { + return { + 'value': 1.0 + }; + } + return { + 'done': true + }; + } + } + } + + function clbk( v ) { + return v * 2.0; + } +}); diff --git a/lib/node_modules/@stdlib/array/fixed-endian-float64/benchmark/benchmark.get.js b/lib/node_modules/@stdlib/array/fixed-endian-float64/benchmark/benchmark.get.js new file mode 100644 index 00000000000..5ac1002f579 --- /dev/null +++ b/lib/node_modules/@stdlib/array/fixed-endian-float64/benchmark/benchmark.get.js @@ -0,0 +1,85 @@ +/** +* @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 isNumber = require( '@stdlib/assert/is-number' ).isPrimitive; +var pkg = require( './../package.json' ).name; +var Float64ArrayFE = require( './../lib' ); + + +// MAIN // + +bench( pkg+':get:endianness=little-endian', function benchmark( b ) { + var arr; + var N; + var v; + var i; + + arr = []; + for ( i = 0; i < 10; i++ ) { + arr.push( i ); + } + arr = new Float64ArrayFE( 'little-endian', arr ); + N = arr.length; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = arr.get( i%N ); + if ( typeof v !== 'number' ) { + b.fail( 'should return a number' ); + } + } + b.toc(); + if ( !isNumber( v ) ) { + b.fail( 'should return a number' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+':get:endianness=big-endian', function benchmark( b ) { + var arr; + var N; + var v; + var i; + + arr = []; + for ( i = 0; i < 10; i++ ) { + arr.push( i ); + } + arr = new Float64ArrayFE( 'big-endian', arr ); + N = arr.length; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = arr.get( i%N ); + if ( typeof v !== 'number' ) { + b.fail( 'should return a number' ); + } + } + b.toc(); + if ( !isNumber( v ) ) { + b.fail( 'should return a number' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/fixed-endian-float64/benchmark/benchmark.js b/lib/node_modules/@stdlib/array/fixed-endian-float64/benchmark/benchmark.js new file mode 100644 index 00000000000..93628839988 --- /dev/null +++ b/lib/node_modules/@stdlib/array/fixed-endian-float64/benchmark/benchmark.js @@ -0,0 +1,533 @@ +/** +* @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 ArrayBuffer = require( '@stdlib/array/buffer' ); +var Float64Array = require( '@stdlib/array/float64' ); +var isArrayBuffer = require( '@stdlib/assert/is-arraybuffer' ); +var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).isPrimitive; +var ITERATOR_SYMBOL = require( '@stdlib/symbol/iterator' ); +var pkg = require( './../package.json' ).name; +var Float64ArrayFE = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': ( ITERATOR_SYMBOL === null ) +}; + + +// FUNCTIONS // + +/** +* Returns an "iterable" object. +* +* @private +* @returns {Object} iterable object +*/ +function createIterable() { + var out = {}; + out[ ITERATOR_SYMBOL ] = iterator; + return out; + + function iterator() { + return { + 'next': next + }; + } + + function next() { + return { + 'done': true + }; + } +} + + +// MAIN // + +bench( pkg+'::instantiation,new:endianness=little-endian', function benchmark( b ) { + var arr; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = new Float64ArrayFE( 'little-endian' ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayFE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::instantiation,new:endianness=big-endian', function benchmark( b ) { + var arr; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = new Float64ArrayFE( 'big-endian' ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayFE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::instantiation,no_new:endianness=little-endian', function benchmark( b ) { + var ctor; + var arr; + var i; + + ctor = Float64ArrayFE; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = ctor( 'little-endian' ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayFE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::instantiation,no_new:endianness=big-endian', function benchmark( b ) { + var ctor; + var arr; + var i; + + ctor = Float64ArrayFE; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = ctor( 'big-endian' ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayFE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::instantiation,length:endianness=little-endian', function benchmark( b ) { + var arr; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = new Float64ArrayFE( 'little-endian', 0 ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayFE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::instantiation,length:endianness=big-endian', function benchmark( b ) { + var arr; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = new Float64ArrayFE( 'big-endian', 0 ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayFE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::instantiation,typed_array:endianness=little-endian', function benchmark( b ) { + var buf; + var arr; + var i; + + buf = new Float64Array( 0 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = new Float64ArrayFE( 'little-endian', buf ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayFE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::instantiation,typed_array:endianness=big-endian', function benchmark( b ) { + var buf; + var arr; + var i; + + buf = new Float64Array( 0 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = new Float64ArrayFE( 'big-endian', buf ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayFE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::instantiation,array:endianness=little-endian', function benchmark( b ) { + var buf; + var arr; + var i; + + buf = []; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = new Float64ArrayFE( 'little-endian', buf ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayFE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::instantiation,array:endianness=big-endian', function benchmark( b ) { + var buf; + var arr; + var i; + + buf = []; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = new Float64ArrayFE( 'big-endian', buf ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayFE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::instantiation,iterable:endianness=little-endian', opts, function benchmark( b ) { + var arr; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = new Float64ArrayFE( 'little-endian', createIterable() ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayFE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::instantiation,iterable:endianness=big-endian', opts, function benchmark( b ) { + var arr; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = new Float64ArrayFE( 'big-endian', createIterable() ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayFE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::instantiation,arraybuffer:endianness=little-endian', function benchmark( b ) { + var buf; + var arr; + var i; + + buf = new ArrayBuffer( 0 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = new Float64ArrayFE( 'little-endian', buf ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayFE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::instantiation,arraybuffer:endianness=big-endian', function benchmark( b ) { + var buf; + var arr; + var i; + + buf = new ArrayBuffer( 0 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = new Float64ArrayFE( 'big-endian', buf ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayFE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::instantiation,arraybuffer,byte_offset:endianness=little-endian', function benchmark( b ) { + var buf; + var arr; + var i; + + buf = new ArrayBuffer( 8 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = new Float64ArrayFE( 'little-endian', buf, 8 ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayFE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::instantiation,arraybuffer,byte_offset:endianness=big-endian', function benchmark( b ) { + var buf; + var arr; + var i; + + buf = new ArrayBuffer( 8 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = new Float64ArrayFE( 'big-endian', buf, 8 ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayFE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::instantiation,arraybuffer,byte_offset,length:endianness=little-endian', function benchmark( b ) { + var buf; + var arr; + var i; + + buf = new ArrayBuffer( 8 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = new Float64ArrayFE( 'little-endian', buf, 8, 0 ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayFE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::instantiation,arraybuffer,byte_offset,length:endianness=big-endian', function benchmark( b ) { + var buf; + var arr; + var i; + + buf = new ArrayBuffer( 8 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = new Float64ArrayFE( 'big-endian', buf, 8, 0 ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayFE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::get:buffer', function benchmark( b ) { + var arr; + var v; + var i; + + arr = new Float64ArrayFE( 'little-endian' ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + // Note: the following may be optimized away due to loop invariant code motion and/or other compiler optimizations, rendering this benchmark meaningless... + v = arr.buffer; + if ( typeof v !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isArrayBuffer( v ) ) { + b.fail( 'should return an ArrayBuffer' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::get:byteLength', function benchmark( b ) { + var arr; + var v; + var i; + + arr = new Float64ArrayFE( 'little-endian' ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + // Note: the following may be optimized away due to loop invariant code motion and/or other compiler optimizations, rendering this benchmark meaningless... + v = arr.byteLength; + if ( v !== v ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( !isNonNegativeInteger( v ) ) { + b.fail( 'should return a nonnegative integer' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::get:byteOffset', function benchmark( b ) { + var arr; + var v; + var i; + + arr = new Float64ArrayFE( 'little-endian' ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + // Note: the following may be optimized away due to loop invariant code motion and/or other compiler optimizations, rendering this benchmark meaningless... + v = arr.byteOffset; + if ( v !== v ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( !isNonNegativeInteger( v ) ) { + b.fail( 'should return a nonnegative integer' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::get:length', function benchmark( b ) { + var arr; + var v; + var i; + + arr = new Float64ArrayFE( 'little-endian' ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + // Note: the following may be optimized away due to loop invariant code motion and/or other compiler optimizations, rendering this benchmark meaningless... + v = arr.length; + if ( v !== v ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( !isNonNegativeInteger( v ) ) { + b.fail( 'should return a nonnegative integer' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/fixed-endian-float64/benchmark/benchmark.of.js b/lib/node_modules/@stdlib/array/fixed-endian-float64/benchmark/benchmark.of.js new file mode 100644 index 00000000000..2222d5c8230 --- /dev/null +++ b/lib/node_modules/@stdlib/array/fixed-endian-float64/benchmark/benchmark.of.js @@ -0,0 +1,69 @@ +/** +* @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 pkg = require( './../package.json' ).name; +var Float64ArrayFE = require( './../lib' ); + + +// MAIN // + +bench( pkg+':of', function benchmark( b ) { + var arr; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = Float64ArrayFE.of( 'little-endian' ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayFE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+':len=5', function benchmark( b ) { + var buf; + var arr; + var i; + + buf = [ 'little-endian', 1.0, 1.0, 1.0, 1.0, 1.0 ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = Float64ArrayFE.of.apply( Float64ArrayFE, buf ); + if ( arr.length !== 5 ) { + b.fail( 'should have length 5' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayFE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/fixed-endian-float64/benchmark/benchmark.set.js b/lib/node_modules/@stdlib/array/fixed-endian-float64/benchmark/benchmark.set.js new file mode 100644 index 00000000000..0ec66f557b9 --- /dev/null +++ b/lib/node_modules/@stdlib/array/fixed-endian-float64/benchmark/benchmark.set.js @@ -0,0 +1,209 @@ +/** +* @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 Float64Array = require( '@stdlib/array/float64' ); +var pkg = require( './../package.json' ).name; +var Float64ArrayFE = require( './../lib' ); + + +// MAIN // + +bench( pkg+'::number:set:endianness=little-endian', function benchmark( b ) { + var values; + var arr; + var N; + var v; + var i; + + values = []; + for ( i = 0; i < 10; i++ ) { + values.push( i ); + } + arr = new Float64ArrayFE( 'little-endian', values ); + N = arr.length; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = arr.set( values[ (i+1)%N ] ); + if ( typeof v !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + } + b.toc(); + if ( typeof v !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::number:set:endianness=big-endian', function benchmark( b ) { + var values; + var arr; + var N; + var v; + var i; + + values = []; + for ( i = 0; i < 10; i++ ) { + values.push( i ); + } + arr = new Float64ArrayFE( 'big-endian', values ); + N = arr.length; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = arr.set( values[ (i+1)%N ] ); + if ( typeof v !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + } + b.toc(); + if ( typeof v !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::array:set:endianness=little-endian', function benchmark( b ) { + var values; + var arr; + var N; + var v; + var i; + + values = []; + for ( i = 0; i < 10; i++ ) { + values.push( i ); + } + arr = new Float64ArrayFE( 'little-endian', values ); + N = arr.length; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = arr.set( [ values[ (i+1)%N ] ] ); + if ( typeof v !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + } + b.toc(); + if ( typeof v !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::array:set:endianness=big-endian', function benchmark( b ) { + var values; + var arr; + var N; + var v; + var i; + + values = []; + for ( i = 0; i < 10; i++ ) { + values.push( i ); + } + arr = new Float64ArrayFE( 'big-endian', values ); + N = arr.length; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = arr.set( [ values[ (i+1)%N ] ] ); + if ( typeof v !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + } + b.toc(); + if ( typeof v !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::typed_array:set:endianness=little-endian', function benchmark( b ) { + var values; + var arr; + var buf; + var N; + var v; + var i; + + values = new Float64Array( 20 ); + N = values.length; + for ( i = 0; i < N; i++ ) { + values[ i ] = i; + } + arr = new Float64ArrayFE( 'little-endian', values ); + buf = new Float64Array( 1 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + buf[ 0 ] = values[ i%N ]; + v = arr.set( buf ); + if ( typeof v !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + } + b.toc(); + if ( typeof v !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::typed_array:set:endianness=big-endian', function benchmark( b ) { + var values; + var arr; + var buf; + var N; + var v; + var i; + + values = new Float64Array( 20 ); + N = values.length; + for ( i = 0; i < N; i++ ) { + values[ i ] = i; + } + arr = new Float64ArrayFE( 'big-endian', values ); + buf = new Float64Array( 1 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + buf[ 0 ] = values[ i%N ]; + v = arr.set( buf ); + if ( typeof v !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + } + b.toc(); + if ( typeof v !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/fixed-endian-float64/benchmark/benchmark.set.length.js b/lib/node_modules/@stdlib/array/fixed-endian-float64/benchmark/benchmark.set.length.js new file mode 100644 index 00000000000..5848832e7f0 --- /dev/null +++ b/lib/node_modules/@stdlib/array/fixed-endian-float64/benchmark/benchmark.set.length.js @@ -0,0 +1,110 @@ +/** +* @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 pow = require( '@stdlib/math/base/special/pow' ); +var randu = require( '@stdlib/random/array/randu' ); +var pkg = require( './../package.json' ).name; +var Float64ArrayFE = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var values; + var arr1; + var arr2; + var arr3; + var N; + + arr1 = randu( len ); + arr2 = randu( len ); + arr3 = randu( len ); + arr1 = new Float64ArrayFE( 'little-endian', arr1 ); + + values = [ + new Float64ArrayFE( 'little-endian', arr2 ), + new Float64ArrayFE( 'big-endian', arr3 ) + ]; + N = values.length; + + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = arr1.set( values[ i%N ] ); + if ( typeof v !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + } + b.toc(); + if ( typeof v !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':set:len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/fixed-endian-float64/benchmark/benchmark.to_string.js b/lib/node_modules/@stdlib/array/fixed-endian-float64/benchmark/benchmark.to_string.js new file mode 100644 index 00000000000..f042a11e1d9 --- /dev/null +++ b/lib/node_modules/@stdlib/array/fixed-endian-float64/benchmark/benchmark.to_string.js @@ -0,0 +1,50 @@ +/** +* @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 pkg = require( './../package.json' ).name; +var Float64ArrayFE = require( './../lib' ); + + +// MAIN // + +bench( pkg+':toString', function benchmark( b ) { + var out; + var arr; + var i; + + arr = new Float64ArrayFE( 'little-endian', [ 1.0, 2.0, 2.0, 1.0 ] ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.toString(); + if ( typeof out !== 'string' ) { + b.fail( 'should return a string' ); + } + } + b.toc(); + if ( typeof out !== 'string' ) { + b.fail( 'should return a string' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/fixed-endian-float64/benchmark/benchmark.to_string.length.js b/lib/node_modules/@stdlib/array/fixed-endian-float64/benchmark/benchmark.to_string.length.js new file mode 100644 index 00000000000..799a3351ef7 --- /dev/null +++ b/lib/node_modules/@stdlib/array/fixed-endian-float64/benchmark/benchmark.to_string.length.js @@ -0,0 +1,94 @@ +/** +* @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 pow = require( '@stdlib/math/base/special/pow' ); +var zeroTo = require( '@stdlib/array/zero-to' ); +var pkg = require( './../package.json' ).name; +var Float64ArrayFE = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var arr = new Float64ArrayFE( 'little-endian', zeroTo( len ) ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.toString(); + if ( typeof out !== 'string' ) { + b.fail( 'should return a string' ); + } + } + b.toc(); + if ( typeof out !== 'string' ) { + b.fail( 'should return a string' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':toString:len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/fixed-endian-float64/examples/index.js b/lib/node_modules/@stdlib/array/fixed-endian-float64/examples/index.js new file mode 100644 index 00000000000..5b4601ff938 --- /dev/null +++ b/lib/node_modules/@stdlib/array/fixed-endian-float64/examples/index.js @@ -0,0 +1,42 @@ +/** +* @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 Float64Array = require( '@stdlib/array/float64' ); +var logEach = require( '@stdlib/console/log-each' ); +var Float64ArrayFE = require( './../lib' ); + +// Create a typed array by specifying a length: +var out = new Float64ArrayFE( 'little-endian', 3 ); +logEach( '%s', out ); + +// Create a typed array from an array: +var arr = [ 1.0, -1.0, -3.14, 3.14, 0.5, 0.5 ]; +out = new Float64ArrayFE( 'big-endian', arr ); +logEach( '%s', out ); + +// Create a typed array from an array buffer: +arr = new Float64Array( [ 1.0, -1.0, -3.14, 3.14, 0.5, 0.5 ] ); // host byte order +out = new Float64ArrayFE( 'little-endian', arr.buffer ); +logEach( '%s', out ); + +// Create a typed array from an array buffer view: +arr = new Float64Array( [ 1.0, -1.0, -3.14, 3.14, 0.5, 0.5 ] ); // host byte order +out = new Float64ArrayFE( 'big-endian', arr.buffer, 8, 2 ); +logEach( '%s', out ); diff --git a/lib/node_modules/@stdlib/array/fixed-endian-float64/lib/index.js b/lib/node_modules/@stdlib/array/fixed-endian-float64/lib/index.js new file mode 100644 index 00000000000..a4841f91938 --- /dev/null +++ b/lib/node_modules/@stdlib/array/fixed-endian-float64/lib/index.js @@ -0,0 +1,94 @@ +/** +* @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'; + +/** +* Typed array constructor which returns a typed array representing an array of double-precision floating-point numbers in a specified byte order. +* +* @module @stdlib/array/fixed-endian-float64 +* +* @example +* var Float64ArrayFE = require( '@stdlib/array/fixed-endian-float64' ); +* +* var arr = new Float64ArrayFE( 'little-endian' ); +* // returns +* +* var len = arr.length; +* // returns 0 +* +* @example +* var Float64ArrayFE = require( '@stdlib/array/fixed-endian-float64' ); +* +* var arr = new Float64ArrayFE( 'little-endian', 2 ); +* // returns +* +* var len = arr.length; +* // returns 2 +* +* @example +* var Float64ArrayFE = require( '@stdlib/array/fixed-endian-float64' ); +* +* var arr = new Float64ArrayFE( 'little-endian', [ 1.0 ] ); +* // returns +* +* var len = arr.length; +* // returns 1 +* +* @example +* var ArrayBuffer = require( '@stdlib/array/buffer' ); +* var Float64ArrayFE = require( '@stdlib/array/fixed-endian-float64' ); +* +* var buf = new ArrayBuffer( 16 ); +* var arr = new Float64ArrayFE( 'little-endian', buf ); +* // returns +* +* var len = arr.length; +* // returns 2 +* +* @example +* var ArrayBuffer = require( '@stdlib/array/buffer' ); +* var Float64ArrayFE = require( '@stdlib/array/fixed-endian-float64' ); +* +* var buf = new ArrayBuffer( 16 ); +* var arr = new Float64ArrayFE( 'little-endian', buf, 8 ); +* // returns +* +* var len = arr.length; +* // returns 1 +* +* @example +* var ArrayBuffer = require( '@stdlib/array/buffer' ); +* var Float64ArrayFE = require( '@stdlib/array/fixed-endian-float64' ); +* +* var buf = new ArrayBuffer( 32 ); +* var arr = new Float64ArrayFE( 'little-endian', buf, 8, 2 ); +* // returns +* +* var len = arr.length; +* // returns 2 +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/array/fixed-endian-float64/lib/main.js b/lib/node_modules/@stdlib/array/fixed-endian-float64/lib/main.js new file mode 100644 index 00000000000..0ee39323116 --- /dev/null +++ b/lib/node_modules/@stdlib/array/fixed-endian-float64/lib/main.js @@ -0,0 +1,100 @@ +/** +* @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 factory = require( '@stdlib/array/fixed-endian-factory' ); + + +// MAIN // + +/** +* Typed array constructor which returns a typed array representing an array of double-precision floating-point numbers in a specified byte order. +* +* @name Float64ArrayFE +* @constructor +* @type {Function} +* @param {string} endianness - byte order +* @param {(NonNegativeInteger|Collection|ArrayBuffer|Iterable)} [arg] - length, typed array, array-like object, buffer, or an iterable +* @param {NonNegativeInteger} [byteOffset=0] - byte offset +* @param {NonNegativeInteger} [length] - view length +* @throws {TypeError} first argument must be a supported byte order +* @throws {TypeError} if provided only two arguments, the second argument must be a valid argument +* @throws {TypeError} byte offset must be a nonnegative integer +* @throws {RangeError} must provide sufficient memory to accommodate byte offset and view length requirements +* @returns {Float64ArrayFE} typed array instance +* +* @example +* var arr = new Float64ArrayFE( 'little-endian' ); +* // returns +* +* var len = arr.length; +* // returns 0 +* +* @example +* var arr = new Float64ArrayFE( 'little-endian', 2 ); +* // returns +* +* var len = arr.length; +* // returns 2 +* +* @example +* var arr = new Float64ArrayFE( 'little-endian', [ 1.0, 2.0 ] ); +* // returns +* +* var len = arr.length; +* // returns 2 +* +* @example +* var ArrayBuffer = require( '@stdlib/array/buffer' ); +* +* var buf = new ArrayBuffer( 16 ); +* var arr = new Float64ArrayFE( 'little-endian', buf ); +* // returns +* +* var len = arr.length; +* // returns 2 +* +* @example +* var ArrayBuffer = require( '@stdlib/array/buffer' ); +* +* var buf = new ArrayBuffer( 16 ); +* var arr = new Float64ArrayFE( 'little-endian', buf, 8 ); +* // returns +* +* var len = arr.length; +* // returns 1 +* +* @example +* var ArrayBuffer = require( '@stdlib/array/buffer' ); +* +* var buf = new ArrayBuffer( 32 ); +* var arr = new Float64ArrayFE( 'little-endian', buf, 8, 2 ); +* // returns +* +* var len = arr.length; +* // returns 2 +*/ +var Float64ArrayFE = factory( 'float64' ); + + +// EXPORTS // + +module.exports = Float64ArrayFE; diff --git a/lib/node_modules/@stdlib/array/fixed-endian-float64/package.json b/lib/node_modules/@stdlib/array/fixed-endian-float64/package.json new file mode 100644 index 00000000000..3d453855cfd --- /dev/null +++ b/lib/node_modules/@stdlib/array/fixed-endian-float64/package.json @@ -0,0 +1,70 @@ +{ + "name": "@stdlib/array/fixed-endian-float64", + "version": "0.0.0", + "description": "Float64Array having a specified byte order.", + "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", + "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", + "stdtypes", + "types", + "data", + "structure", + "array", + "typed", + "typed array", + "typed-array", + "float64array", + "float64", + "double", + "double-precision", + "ieee754", + "endian", + "little-endian", + "big-endian", + "byte-order" + ] +} diff --git a/lib/node_modules/@stdlib/array/fixed-endian-float64/test/test.js b/lib/node_modules/@stdlib/array/fixed-endian-float64/test/test.js new file mode 100644 index 00000000000..fc72bbf8822 --- /dev/null +++ b/lib/node_modules/@stdlib/array/fixed-endian-float64/test/test.js @@ -0,0 +1,35 @@ +/** +* @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 ctor = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof ctor, 'function', 'main export is a function' ); + t.end(); +}); + +// TODO: add tests diff --git a/lib/node_modules/@stdlib/array/from-iterator/docs/repl.txt b/lib/node_modules/@stdlib/array/from-iterator/docs/repl.txt index 7813ee590fd..9b949e48b27 100644 --- a/lib/node_modules/@stdlib/array/from-iterator/docs/repl.txt +++ b/lib/node_modules/@stdlib/array/from-iterator/docs/repl.txt @@ -4,8 +4,8 @@ When invoked, an input function is provided two arguments: - - value: iterated value - - index: iterated value index (zero-based) + - value: iterated value. + - index: iterated value index (zero-based). If provided an output array, the function fills the output array with iterated values. diff --git a/lib/node_modules/@stdlib/array/lib/index.js b/lib/node_modules/@stdlib/array/lib/index.js index 6a17249284c..4471b9af047 100644 --- a/lib/node_modules/@stdlib/array/lib/index.js +++ b/lib/node_modules/@stdlib/array/lib/index.js @@ -67,6 +67,15 @@ setReadOnly( ns, 'BooleanArray', require( '@stdlib/array/bool' ) ); */ setReadOnly( ns, 'ArrayBuffer', require( '@stdlib/array/buffer' ) ); +/** +* @name byteOrders +* @memberof ns +* @readonly +* @constructor +* @see {@link module:@stdlib/array/byte-orders} +*/ +setReadOnly( ns, 'byteOrders', require( '@stdlib/array/byte-orders' ) ); + /** * @name cartesianPower * @memberof ns @@ -220,6 +229,24 @@ setReadOnly( ns, 'filled', require( '@stdlib/array/filled' ) ); */ setReadOnly( ns, 'filledBy', require( '@stdlib/array/filled-by' ) ); +/** +* @name fixedEndianFactory +* @memberof ns +* @readonly +* @constructor +* @see {@link module:@stdlib/array/fixed-endian-factory} +*/ +setReadOnly( ns, 'fixedEndianFactory', require( '@stdlib/array/fixed-endian-factory' ) ); + +/** +* @name Float64ArrayFE +* @memberof ns +* @readonly +* @constructor +* @see {@link module:@stdlib/array/fixed-endian-float64} +*/ +setReadOnly( ns, 'Float64ArrayFE', require( '@stdlib/array/fixed-endian-float64' ) ); + /** * @name Float32Array * @memberof ns @@ -328,6 +355,24 @@ setReadOnly( ns, 'Int32Array', require( '@stdlib/array/int32' ) ); */ setReadOnly( ns, 'linspace', require( '@stdlib/array/linspace' ) ); +/** +* @name littleEndianFactory +* @memberof ns +* @readonly +* @constructor +* @see {@link module:@stdlib/array/little-endian-factory} +*/ +setReadOnly( ns, 'littleEndianFactory', require( '@stdlib/array/little-endian-factory' ) ); + +/** +* @name Float64ArrayLE +* @memberof ns +* @readonly +* @constructor +* @see {@link module:@stdlib/array/little-endian-float64} +*/ +setReadOnly( ns, 'Float64ArrayLE', require( '@stdlib/array/little-endian-float64' ) ); + /** * @name logspace * @memberof ns diff --git a/lib/node_modules/@stdlib/array/little-endian-factory/README.md b/lib/node_modules/@stdlib/array/little-endian-factory/README.md new file mode 100644 index 00000000000..12ab8ec7b80 --- /dev/null +++ b/lib/node_modules/@stdlib/array/little-endian-factory/README.md @@ -0,0 +1,498 @@ + + +# littleEndianFactory + +> Return a typed array constructor for creating typed arrays stored in little-endian byte order. + + + +
+ +In contrast to the built-in typed array constructors which store values according to the host platform byte order, the typed array constructors returned by the factory function always access elements in little-endian byte order. Such enforcement can be particularly advantageous when working with memory buffers which do not necessarily follow host platform byte order, such as [WebAssembly memory][@stdlib/wasm/memory]. + +
+ + + + + +
+ +## Usage + +```javascript +var littleEndianFactory = require( '@stdlib/array/little-endian-factory' ); +``` + +#### littleEndianFactory( dtype ) + +Returns a typed array constructor for creating typed arrays having a specified [data type][@stdlib/array/typed-dtypes] and stored in little-endian byte order. + +```javascript +var Float64ArrayLE = littleEndianFactory( 'float64' ); +// returns + +var Float32ArrayLE = littleEndianFactory( 'float32' ); +// returns +``` + +* * * + +### Typed Array Constructor + +#### TypedArrayLE() + +A typed array constructor which returns a typed array representing an array of values in little-endian byte order. + +```javascript +var Float64ArrayLE = littleEndianFactory( 'float64' ); + +var arr = new Float64ArrayLE(); +// returns +``` + +#### TypedArrayLE( length ) + +Returns a typed array having a specified length. + +```javascript +var Float64ArrayLE = littleEndianFactory( 'float64' ); + +var arr = new Float64ArrayLE( 5 ); +// returns +``` + +#### TypedArrayLE( typedarray ) + +Creates a typed array from another typed array. + +```javascript +var Float32Array = require( '@stdlib/array/float32' ); + +var Float64ArrayLE = littleEndianFactory( 'float64' ); + +var arr1 = new Float32Array( [ 0.5, 0.5, 0.5 ] ); +var arr2 = new Float64ArrayLE( arr1 ); +// returns + +var v = arr2.get( 0 ); +// returns 0.5 +``` + +#### TypedArrayLE( obj ) + +Creates a typed array from an array-like object or iterable. + +```javascript +var Float64ArrayLE = littleEndianFactory( 'float64' ); + +var arr = new Float64ArrayLE( [ 0.5, 0.5, 0.5 ] ); +// returns + +var v = arr.get( 0 ); +// returns 0.5 +``` + +#### TypedArrayLE( buffer\[, byteOffset\[, length]] ) + +Returns a typed array view of an [`ArrayBuffer`][@stdlib/array/buffer]. + +```javascript +var ArrayBuffer = require( '@stdlib/array/buffer' ); + +var Float64ArrayLE = littleEndianFactory( 'float64' ); + +var buf = new ArrayBuffer( 32 ); +var arr = new Float64ArrayLE( buf, 0, 4 ); +// returns +``` + +* * * + +### Typed Array Properties + + + +#### TypedArrayLE.BYTES_PER_ELEMENT + +Number of bytes per view element. + +```javascript +var Float64ArrayLE = littleEndianFactory( 'float64' ); + +var nbytes = Float64ArrayLE.BYTES_PER_ELEMENT; +// returns 8 +``` + + + +#### TypedArrayLE.name + +Typed array constructor name. + +```javascript +var Float64ArrayLE = littleEndianFactory( 'float64' ); + +var str = Float64ArrayLE.name; +// returns 'Float64ArrayLE' +``` + + + +#### TypedArrayLE.prototype.buffer + +**Read-only** property which returns the [`ArrayBuffer`][@stdlib/array/buffer] referenced by the typed array. + +```javascript +var Float64ArrayLE = littleEndianFactory( 'float64' ); + +var arr = new Float64ArrayLE( 5 ); +var buf = arr.buffer; +// returns +``` + + + +#### TypedArrayLE.prototype.byteLength + +**Read-only** property which returns the length (in bytes) of the typed array. + +```javascript +var Float64ArrayLE = littleEndianFactory( 'float64' ); + +var arr = new Float64ArrayLE( 5 ); +var byteLength = arr.byteLength; +// returns 40 +``` + + + +#### TypedArrayLE.prototype.byteOffset + +**Read-only** property which returns the offset (in bytes) of the typed array from the start of its [`ArrayBuffer`][@stdlib/array/buffer]. + +```javascript +var Float64ArrayLE = littleEndianFactory( 'float64' ); + +var arr = new Float64ArrayLE( 5 ); +var byteOffset = arr.byteOffset; +// returns 0 +``` + + + +#### TypedArrayLE.prototype.BYTES_PER_ELEMENT + +Number of bytes per view element. + +```javascript +var Float64ArrayLE = littleEndianFactory( 'float64' ); + +var arr = new Float64ArrayLE( 5 ); +var nbytes = arr.BYTES_PER_ELEMENT; +// returns 8 +``` + + + +#### TypedArrayLE.prototype.length + +**Read-only** property which returns the number of view elements. + +```javascript +var Float64ArrayLE = littleEndianFactory( 'float64' ); + +var arr = new Float64ArrayLE( 5 ); +var len = arr.length; +// returns 5 +``` + +* * * + +### Typed Array Methods + + + +#### TypedArrayLE.from( src\[, map\[, thisArg]] ) + +Creates a new typed array from an array-like object or an iterable. + +```javascript +var Float64ArrayLE = littleEndianFactory( 'float64' ); + +var arr = Float64ArrayLE.from( [ 1.0, -1.0 ] ); +// returns + +var v = arr.get( 0 ); +// returns 1.0 +``` + +To invoke a function for each `src` value, provide a callback function. + +```javascript +function mapFcn( v ) { + return v * 2.0; +} + +var Float64ArrayLE = littleEndianFactory( 'float64' ); + +var arr = Float64ArrayLE.from( [ 1.0, -1.0 ], mapFcn ); +// returns + +var v = arr.get( 0 ); +// returns 2.0 +``` + +A callback function is provided two arguments: + +- **value**: source value. +- **index**: source index. + +To set the callback execution context, provide a `thisArg`. + +```javascript +function mapFcn( v ) { + this.count += 1; + return v * 2.0; +} + +var Float64ArrayLE = littleEndianFactory( 'float64' ); + +var ctx = { + 'count': 0 +}; + +var arr = Float64ArrayLE.from( [ 1.0, -1.0 ], mapFcn, ctx ); +// returns + +var v = arr.get( 0 ); +// returns 2.0 + +var n = ctx.count; +// returns 2 +``` + + + +#### TypedArrayLE.of( element0\[, element1\[, ...elementN]] ) + +Creates a new typed array from a variable number of arguments. + +```javascript +var Float64ArrayLE = littleEndianFactory( 'float64' ); + +var arr = Float64ArrayLE.of( 1.0, -1.0 ); +// returns + +var v = arr.get( 0 ); +// returns 1.0 +``` + + + +#### TypedArrayLE.prototype.get( i ) + +Returns an array element located at a nonnegative integer position (index) `i`. + +```javascript +var Float64ArrayLE = littleEndianFactory( 'float64' ); + +var arr = new Float64ArrayLE( 10 ); + +// Set the first element: +arr.set( 1.0, 0 ); + +// Get the first element: +var v = arr.get( 0 ); +// returns 1.0 +``` + +If provided an out-of-bounds index, the method returns `undefined`. + +```javascript +var Float64ArrayLE = littleEndianFactory( 'float64' ); + +var arr = new Float64ArrayLE( 10 ); + +var v = arr.get( 100 ); +// returns undefined +``` + + + +#### TypedArrayLE.prototype.set( arr\[, offset] ) + +Sets array elements. + +```javascript +var Float64ArrayLE = littleEndianFactory( 'float64' ); + +var arr = new Float64ArrayLE( [ 1.0, 2.0, 3.0 ] ); +// returns + +var v = arr.get( 0 ); +// returns 1.0 + +v = arr.get( 1 ); +// returns 2.0 + +// Set the first two array elements: +arr.set( [ 4.0, 5.0 ] ); + +v = arr.get( 0 ); +// returns 4.0 + +v = arr.get( 1 ); +// returns 5.0 +``` + +By default, the method starts writing values at the first array index. To specify an alternative index, provide an index `offset`. + +```javascript +var Float64ArrayLE = littleEndianFactory( 'float64' ); + +var arr = new Float64ArrayLE( [ 1.0, 2.0, 3.0 ] ); +// returns + +// Set the last two array elements: +arr.set( [ 4.0, 5.0 ], 1 ); + +var v = arr.get( 1 ); +// returns 4.0 + +v = arr.get( 2 ); +// returns 5.0 +``` + +A few notes: + +- If `i` is out-of-bounds, the method throws an error. +- If a target array cannot accommodate all values (i.e., the length of source array plus `i` exceeds the target array length), the method throws an error. +- If provided a typed array which shares an [`ArrayBuffer`][@stdlib/array/buffer] with the target array, the method will intelligently copy the source range to the destination range. + + + +#### TypedArrayLE.prototype.toString() + +Serializes an array as a string. + +```javascript +var Float64ArrayLE = littleEndianFactory( 'float64' ); + +var arr = new Float64ArrayLE( [ 1.0, 2.0, 3.0 ] ); + +var str = arr.toString(); +// returns '1,2,3' +``` + +
+ + + + + +
+ +* * * + +## Notes + +- While returned constructors _strive_ to maintain (but do not **guarantee**) consistency with [typed arrays][@stdlib/array/typed], significant deviations from ECMAScript-defined [typed array][@stdlib/array/typed] behavior are as follows: + + - Constructors **not** require the `new` operator. + - Accessing array elements using bracket syntax (e.g., `X[i]`) is **not** supported. Instead, one **must** use the `.get()` method. + +
+ + + + + +
+ +* * * + +## Examples + + + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); +var logEach = require( '@stdlib/console/log-each' ); +var littleEndianFactory = require( '@stdlib/array/little-endian-factory' ); + +var Float64ArrayLE = littleEndianFactory( 'float64' ); + +// Create a typed array by specifying a length: +var out = new Float64ArrayLE( 3 ); +logEach( '%s', out ); + +// Create a typed array from an array: +var arr = [ 1.0, -1.0, -3.14, 3.14, 0.5, 0.5 ]; +out = new Float64ArrayLE( arr ); +logEach( '%s', out ); + +// Create a typed array from an array buffer: +arr = new Float64Array( [ 1.0, -1.0, -3.14, 3.14, 0.5, 0.5 ] ); // host byte order +out = new Float64ArrayLE( arr.buffer ); +logEach( '%s', out ); + +// Create a typed array from an array buffer view: +arr = new Float64Array( [ 1.0, -1.0, -3.14, 3.14, 0.5, 0.5 ] ); // host byte order +out = new Float64ArrayLE( arr.buffer, 8, 2 ); +logEach( '%s', out ); +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/array/little-endian-factory/benchmark/benchmark.from.js b/lib/node_modules/@stdlib/array/little-endian-factory/benchmark/benchmark.from.js new file mode 100644 index 00000000000..8375c8dfdfd --- /dev/null +++ b/lib/node_modules/@stdlib/array/little-endian-factory/benchmark/benchmark.from.js @@ -0,0 +1,311 @@ +/** +* @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 Float64Array = require( '@stdlib/array/float64' ); +var ITERATOR_SYMBOL = require( '@stdlib/symbol/iterator' ); +var pkg = require( './../package.json' ).name; +var factory = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': ( ITERATOR_SYMBOL === null ) +}; +var Float64ArrayLE = factory( 'float64' ); + + +// MAIN // + +bench( pkg+'::typed_array:from', function benchmark( b ) { + var buf; + var arr; + var i; + + buf = new Float64Array( 0 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = Float64ArrayLE.from( buf ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayLE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::typed_array:from:len=5', function benchmark( b ) { + var buf; + var arr; + var i; + + buf = new Float64Array( 5 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = Float64ArrayLE.from( buf ); + if ( arr.length !== 5 ) { + b.fail( 'should have length 5' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayLE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::typed_array,clbk:from:len=5', function benchmark( b ) { + var buf; + var arr; + var i; + + buf = new Float64Array( 5 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = Float64ArrayLE.from( buf, clbk ); + if ( arr.length !== 5 ) { + b.fail( 'should have length 5' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayLE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function clbk( v ) { + return v * 2.0; + } +}); + +bench( pkg+'::array:from', function benchmark( b ) { + var buf; + var arr; + var i; + + buf = []; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = Float64ArrayLE.from( buf ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayLE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::array:from:len=5', function benchmark( b ) { + var buf; + var arr; + var i; + + buf = [ 1.0, 1.0, 1.0, 1.0, 1.0 ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = Float64ArrayLE.from( buf ); + if ( arr.length !== 5 ) { + b.fail( 'should have length 5' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayLE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::array,clbk:from:len=5', function benchmark( b ) { + var buf; + var arr; + var i; + + buf = [ 1.0, 1.0, 1.0, 1.0, 1.0 ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = Float64ArrayLE.from( buf, clbk ); + if ( arr.length !== 5 ) { + b.fail( 'should have length 5' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayLE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function clbk( v ) { + return v * 2.0; + } +}); + +bench( pkg+'::iterable:from', opts, function benchmark( b ) { + var arr; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = Float64ArrayLE.from( createIterable() ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayLE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function createIterable() { + var out = {}; + out[ ITERATOR_SYMBOL ] = iterator; + return out; + + function iterator() { + return { + 'next': next + }; + } + + function next() { + return { + 'done': true + }; + } + } +}); + +bench( pkg+'::iterable:from:len=5', opts, function benchmark( b ) { + var arr; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = Float64ArrayLE.from( createIterable() ); + if ( arr.length !== 5 ) { + b.fail( 'should have length 5' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayLE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function createIterable() { + var out = {}; + out[ ITERATOR_SYMBOL ] = iterator; + return out; + + function iterator() { + var it = { + 'next': next, + 'i': 0, + 'N': 5 + }; + return it; + + function next() { + it.i += 1; + if ( it.i <= it.N ) { + return { + 'value': 1.0 + }; + } + return { + 'done': true + }; + } + } + } +}); + +bench( pkg+'::iterable,clbk:from:len=5', opts, function benchmark( b ) { + var arr; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = Float64ArrayLE.from( createIterable(), clbk ); + if ( arr.length !== 5 ) { + b.fail( 'should have length 5' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayLE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function createIterable() { + var out = {}; + out[ ITERATOR_SYMBOL ] = iterator; + return out; + + function iterator() { + var it = { + 'next': next, + 'i': 0, + 'N': 5 + }; + return it; + + function next() { + it.i += 1; + if ( it.i <= it.N ) { + return { + 'value': 1.0 + }; + } + return { + 'done': true + }; + } + } + } + + function clbk( v ) { + return v * 2.0; + } +}); diff --git a/lib/node_modules/@stdlib/array/little-endian-factory/benchmark/benchmark.get.js b/lib/node_modules/@stdlib/array/little-endian-factory/benchmark/benchmark.get.js new file mode 100644 index 00000000000..7ceb453c900 --- /dev/null +++ b/lib/node_modules/@stdlib/array/little-endian-factory/benchmark/benchmark.get.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'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isNumber = require( '@stdlib/assert/is-number' ).isPrimitive; +var pkg = require( './../package.json' ).name; +var factory = require( './../lib' ); + + +// VARIABLES // + +var Float64ArrayLE = factory( 'float64' ); + + +// MAIN // + +bench( pkg+':get', function benchmark( b ) { + var arr; + var N; + var v; + var i; + + arr = []; + for ( i = 0; i < 10; i++ ) { + arr.push( i ); + } + arr = new Float64ArrayLE( arr ); + N = arr.length; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = arr.get( i%N ); + if ( typeof v !== 'number' ) { + b.fail( 'should return a number' ); + } + } + b.toc(); + if ( !isNumber( v ) ) { + b.fail( 'should return a number' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/little-endian-factory/benchmark/benchmark.instantiation.js b/lib/node_modules/@stdlib/array/little-endian-factory/benchmark/benchmark.instantiation.js new file mode 100644 index 00000000000..c55e2f3f393 --- /dev/null +++ b/lib/node_modules/@stdlib/array/little-endian-factory/benchmark/benchmark.instantiation.js @@ -0,0 +1,253 @@ +/** +* @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 ArrayBuffer = require( '@stdlib/array/buffer' ); +var Float64Array = require( '@stdlib/array/float64' ); +var ITERATOR_SYMBOL = require( '@stdlib/symbol/iterator' ); +var pkg = require( './../package.json' ).name; +var factory = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': ( ITERATOR_SYMBOL === null ) +}; +var Float64ArrayLE = factory( 'float64' ); + + +// FUNCTIONS // + +/** +* Returns an "iterable" object. +* +* @private +* @returns {Object} iterable object +*/ +function createIterable() { + var out = {}; + out[ ITERATOR_SYMBOL ] = iterator; + return out; + + function iterator() { + return { + 'next': next + }; + } + + function next() { + return { + 'done': true + }; + } +} + + +// MAIN // + +bench( pkg+'::instantiation,new', function benchmark( b ) { + var arr; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = new Float64ArrayLE(); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayLE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::instantiation,no_new', function benchmark( b ) { + var ctor; + var arr; + var i; + + ctor = Float64ArrayLE; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = ctor(); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayLE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::instantiation,length', function benchmark( b ) { + var arr; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = new Float64ArrayLE( 0 ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayLE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::instantiation,typed_array', function benchmark( b ) { + var buf; + var arr; + var i; + + buf = new Float64Array( 0 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = new Float64ArrayLE( buf ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayLE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::instantiation,array', function benchmark( b ) { + var buf; + var arr; + var i; + + buf = []; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = new Float64ArrayLE( buf ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayLE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::instantiation,iterable', opts, function benchmark( b ) { + var arr; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = new Float64ArrayLE( createIterable() ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayLE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::instantiation,arraybuffer', function benchmark( b ) { + var buf; + var arr; + var i; + + buf = new ArrayBuffer( 0 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = new Float64ArrayLE( buf ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayLE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::instantiation,arraybuffer,byte_offset', function benchmark( b ) { + var buf; + var arr; + var i; + + buf = new ArrayBuffer( 8 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = new Float64ArrayLE( buf, 8 ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayLE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::instantiation,arraybuffer,byte_offset,length', function benchmark( b ) { + var buf; + var arr; + var i; + + buf = new ArrayBuffer( 8 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = new Float64ArrayLE( buf, 8, 0 ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayLE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/little-endian-factory/benchmark/benchmark.js b/lib/node_modules/@stdlib/array/little-endian-factory/benchmark/benchmark.js new file mode 100644 index 00000000000..619c1f968f4 --- /dev/null +++ b/lib/node_modules/@stdlib/array/little-endian-factory/benchmark/benchmark.js @@ -0,0 +1,48 @@ +/** +* @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 isFunction = require( '@stdlib/assert/is-function' ); +var pkg = require( './../package.json' ).name; +var factory = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = factory( 'float64' ); + if ( typeof v !== 'function' ) { + b.fail( 'should return a function' ); + } + } + b.toc(); + if ( !isFunction( v ) ) { + b.fail( 'should return a function' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/little-endian-factory/benchmark/benchmark.of.js b/lib/node_modules/@stdlib/array/little-endian-factory/benchmark/benchmark.of.js new file mode 100644 index 00000000000..538e39a016f --- /dev/null +++ b/lib/node_modules/@stdlib/array/little-endian-factory/benchmark/benchmark.of.js @@ -0,0 +1,74 @@ +/** +* @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 pkg = require( './../package.json' ).name; +var factory = require( './../lib' ); + + +// VARIABLES // + +var Float64ArrayLE = factory( 'float64' ); + + +// MAIN // + +bench( pkg+':of', function benchmark( b ) { + var arr; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = Float64ArrayLE.of(); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayLE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+':len=5', function benchmark( b ) { + var buf; + var arr; + var i; + + buf = [ 1.0, 1.0, 1.0, 1.0, 1.0 ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = Float64ArrayLE.of.apply( Float64ArrayLE, buf ); + if ( arr.length !== 5 ) { + b.fail( 'should have length 5' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayLE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/little-endian-factory/benchmark/benchmark.property_access.js b/lib/node_modules/@stdlib/array/little-endian-factory/benchmark/benchmark.property_access.js new file mode 100644 index 00000000000..c0fea37c87f --- /dev/null +++ b/lib/node_modules/@stdlib/array/little-endian-factory/benchmark/benchmark.property_access.js @@ -0,0 +1,127 @@ +/** +* @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 isArrayBuffer = require( '@stdlib/assert/is-arraybuffer' ); +var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).isPrimitive; +var pkg = require( './../package.json' ).name; +var factory = require( './../lib' ); + + +// VARIABLES // + +var Float64ArrayLE = factory( 'float64' ); + + +// MAIN // + +bench( pkg+'::get:buffer', function benchmark( b ) { + var arr; + var v; + var i; + + arr = new Float64ArrayLE(); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + // Note: the following may be optimized away due to loop invariant code motion and/or other compiler optimizations, rendering this benchmark meaningless... + v = arr.buffer; + if ( typeof v !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isArrayBuffer( v ) ) { + b.fail( 'should return an ArrayBuffer' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::get:byteLength', function benchmark( b ) { + var arr; + var v; + var i; + + arr = new Float64ArrayLE(); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + // Note: the following may be optimized away due to loop invariant code motion and/or other compiler optimizations, rendering this benchmark meaningless... + v = arr.byteLength; + if ( v !== v ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( !isNonNegativeInteger( v ) ) { + b.fail( 'should return a nonnegative integer' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::get:byteOffset', function benchmark( b ) { + var arr; + var v; + var i; + + arr = new Float64ArrayLE(); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + // Note: the following may be optimized away due to loop invariant code motion and/or other compiler optimizations, rendering this benchmark meaningless... + v = arr.byteOffset; + if ( v !== v ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( !isNonNegativeInteger( v ) ) { + b.fail( 'should return a nonnegative integer' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::get:length', function benchmark( b ) { + var arr; + var v; + var i; + + arr = new Float64ArrayLE(); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + // Note: the following may be optimized away due to loop invariant code motion and/or other compiler optimizations, rendering this benchmark meaningless... + v = arr.length; + if ( v !== v ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( !isNonNegativeInteger( v ) ) { + b.fail( 'should return a nonnegative integer' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/little-endian-factory/benchmark/benchmark.set.js b/lib/node_modules/@stdlib/array/little-endian-factory/benchmark/benchmark.set.js new file mode 100644 index 00000000000..88c60c055df --- /dev/null +++ b/lib/node_modules/@stdlib/array/little-endian-factory/benchmark/benchmark.set.js @@ -0,0 +1,124 @@ +/** +* @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 Float64Array = require( '@stdlib/array/float64' ); +var pkg = require( './../package.json' ).name; +var factory = require( './../lib' ); + + +// VARIABLES // + +var Float64ArrayLE = factory( 'float64' ); + + +// MAIN // + +bench( pkg+'::number:set', function benchmark( b ) { + var values; + var arr; + var N; + var v; + var i; + + values = []; + for ( i = 0; i < 10; i++ ) { + values.push( i ); + } + arr = new Float64ArrayLE( values ); + N = arr.length; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = arr.set( values[ (i+1)%N ] ); + if ( typeof v !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + } + b.toc(); + if ( typeof v !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::array:set', function benchmark( b ) { + var values; + var arr; + var N; + var v; + var i; + + values = []; + for ( i = 0; i < 10; i++ ) { + values.push( i ); + } + arr = new Float64ArrayLE( values ); + N = arr.length; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = arr.set( [ values[ (i+1)%N ] ] ); + if ( typeof v !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + } + b.toc(); + if ( typeof v !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::typed_array:set', function benchmark( b ) { + var values; + var arr; + var buf; + var N; + var v; + var i; + + values = new Float64Array( 20 ); + N = values.length; + for ( i = 0; i < N; i++ ) { + values[ i ] = i; + } + arr = new Float64ArrayLE( values ); + buf = new Float64Array( 1 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + buf[ 0 ] = values[ i%N ]; + v = arr.set( buf ); + if ( typeof v !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + } + b.toc(); + if ( typeof v !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/little-endian-factory/benchmark/benchmark.set.length.js b/lib/node_modules/@stdlib/array/little-endian-factory/benchmark/benchmark.set.length.js new file mode 100644 index 00000000000..33a1322b64f --- /dev/null +++ b/lib/node_modules/@stdlib/array/little-endian-factory/benchmark/benchmark.set.length.js @@ -0,0 +1,115 @@ +/** +* @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 pow = require( '@stdlib/math/base/special/pow' ); +var randu = require( '@stdlib/random/array/randu' ); +var pkg = require( './../package.json' ).name; +var factory = require( './../lib' ); + + +// VARIABLES // + +var Float64ArrayLE = factory( 'float64' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var values; + var arr1; + var arr2; + var arr3; + var N; + + arr1 = randu( len ); + arr2 = randu( len ); + arr3 = randu( len ); + arr1 = new Float64ArrayLE( arr1 ); + + values = [ + new Float64ArrayLE( arr2 ), + new Float64ArrayLE( arr3 ) + ]; + N = values.length; + + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = arr1.set( values[ i%N ] ); + if ( typeof v !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + } + b.toc(); + if ( typeof v !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':set:len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/little-endian-factory/benchmark/benchmark.to_string.js b/lib/node_modules/@stdlib/array/little-endian-factory/benchmark/benchmark.to_string.js new file mode 100644 index 00000000000..dc823451c67 --- /dev/null +++ b/lib/node_modules/@stdlib/array/little-endian-factory/benchmark/benchmark.to_string.js @@ -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. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var pkg = require( './../package.json' ).name; +var factory = require( './../lib' ); + + +// VARIABLES // + +var Float64ArrayLE = factory( 'float64' ); + + +// MAIN // + +bench( pkg+':toString', function benchmark( b ) { + var out; + var arr; + var i; + + arr = new Float64ArrayLE( [ 1.0, 2.0, 2.0, 1.0 ] ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.toString(); + if ( typeof out !== 'string' ) { + b.fail( 'should return a string' ); + } + } + b.toc(); + if ( typeof out !== 'string' ) { + b.fail( 'should return a string' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/little-endian-factory/benchmark/benchmark.to_string.length.js b/lib/node_modules/@stdlib/array/little-endian-factory/benchmark/benchmark.to_string.length.js new file mode 100644 index 00000000000..c40fcd69f4c --- /dev/null +++ b/lib/node_modules/@stdlib/array/little-endian-factory/benchmark/benchmark.to_string.length.js @@ -0,0 +1,99 @@ +/** +* @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 pow = require( '@stdlib/math/base/special/pow' ); +var zeroTo = require( '@stdlib/array/zero-to' ); +var pkg = require( './../package.json' ).name; +var factory = require( './../lib' ); + + +// VARIABLES // + +var Float64ArrayLE = factory( 'float64' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var arr = new Float64ArrayLE( zeroTo( len ) ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.toString(); + if ( typeof out !== 'string' ) { + b.fail( 'should return a string' ); + } + } + b.toc(); + if ( typeof out !== 'string' ) { + b.fail( 'should return a string' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':toString:len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/little-endian-factory/examples/index.js b/lib/node_modules/@stdlib/array/little-endian-factory/examples/index.js new file mode 100644 index 00000000000..2c21b37616c --- /dev/null +++ b/lib/node_modules/@stdlib/array/little-endian-factory/examples/index.js @@ -0,0 +1,44 @@ +/** +* @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 Float64Array = require( '@stdlib/array/float64' ); +var logEach = require( '@stdlib/console/log-each' ); +var factory = require( './../lib' ); + +var Float64ArrayLE = factory( 'float64' ); + +// Create a typed array by specifying a length: +var out = new Float64ArrayLE( 3 ); +logEach( '%s', out ); + +// Create a typed array from an array: +var arr = [ 1.0, -1.0, -3.14, 3.14, 0.5, 0.5 ]; +out = new Float64ArrayLE( arr ); +logEach( '%s', out ); + +// Create a typed array from an array buffer: +arr = new Float64Array( [ 1.0, -1.0, -3.14, 3.14, 0.5, 0.5 ] ); // host byte order +out = new Float64ArrayLE( arr.buffer ); +logEach( '%s', out ); + +// Create a typed array from an array buffer view: +arr = new Float64Array( [ 1.0, -1.0, -3.14, 3.14, 0.5, 0.5 ] ); // host byte order +out = new Float64ArrayLE( arr.buffer, 8, 2 ); +logEach( '%s', out ); diff --git a/lib/node_modules/@stdlib/array/little-endian-factory/lib/from_iterator.js b/lib/node_modules/@stdlib/array/little-endian-factory/lib/from_iterator.js new file mode 100644 index 00000000000..c1adb5d9a18 --- /dev/null +++ b/lib/node_modules/@stdlib/array/little-endian-factory/lib/from_iterator.js @@ -0,0 +1,48 @@ +/** +* @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'; + +// MAIN // + +/** +* Returns an array of iterated values. +* +* @private +* @param {Object} it - iterator +* @returns {Array} output array +*/ +function fromIterator( it ) { + var out; + var v; + + out = []; + while ( true ) { + v = it.next(); + if ( v.done ) { + break; + } + out.push( v.value ); + } + return out; +} + + +// EXPORTS // + +module.exports = fromIterator; diff --git a/lib/node_modules/@stdlib/array/little-endian-factory/lib/from_iterator_map.js b/lib/node_modules/@stdlib/array/little-endian-factory/lib/from_iterator_map.js new file mode 100644 index 00000000000..9a6e354eb8a --- /dev/null +++ b/lib/node_modules/@stdlib/array/little-endian-factory/lib/from_iterator_map.js @@ -0,0 +1,53 @@ +/** +* @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'; + +// MAIN // + +/** +* Returns an array of iterated values. +* +* @private +* @param {Object} it - iterator +* @param {Function} clbk - callback to invoke for each iterated value +* @param {*} thisArg - invocation context +* @returns {Array} output array +*/ +function fromIteratorMap( it, clbk, thisArg ) { + var out; + var v; + var i; + + out = []; + i = -1; + while ( true ) { + v = it.next(); + if ( v.done ) { + break; + } + i += 1; + out.push( clbk.call( thisArg, v.value, i ) ); + } + return out; +} + + +// EXPORTS // + +module.exports = fromIteratorMap; diff --git a/lib/node_modules/@stdlib/array/little-endian-factory/lib/index.js b/lib/node_modules/@stdlib/array/little-endian-factory/lib/index.js new file mode 100644 index 00000000000..b01ede482d5 --- /dev/null +++ b/lib/node_modules/@stdlib/array/little-endian-factory/lib/index.js @@ -0,0 +1,106 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Return a typed array constructor for creating typed arrays stored in little-endian byte order. +* +* @module @stdlib/array/little-endian-factory +* +* @example +* var factory = require( '@stdlib/array/little-endian-factory' ); +* +* var Float64ArrayLE = factory( 'float64' ); +* +* var arr = new Float64ArrayLE(); +* // returns +* +* var len = arr.length; +* // returns 0 +* +* @example +* var factory = require( '@stdlib/array/little-endian-factory' ); +* +* var Float64ArrayLE = factory( 'float64' ); +* +* var arr = new Float64ArrayLE( 2 ); +* // returns +* +* var len = arr.length; +* // returns 2 +* +* @example +* var factory = require( '@stdlib/array/little-endian-factory' ); +* +* var Float64ArrayLE = factory( 'float64' ); +* +* var arr = new Float64ArrayLE( [ 1.0 ] ); +* // returns +* +* var len = arr.length; +* // returns 1 +* +* @example +* var ArrayBuffer = require( '@stdlib/array/buffer' ); +* var factory = require( '@stdlib/array/little-endian-factory' ); +* +* var Float64ArrayLE = factory( 'float64' ); +* +* var buf = new ArrayBuffer( 16 ); +* var arr = new Float64ArrayLE( buf ); +* // returns +* +* var len = arr.length; +* // returns 2 +* +* @example +* var ArrayBuffer = require( '@stdlib/array/buffer' ); +* var factory = require( '@stdlib/array/little-endian-factory' ); +* +* var Float64ArrayLE = factory( 'float64' ); +* +* var buf = new ArrayBuffer( 16 ); +* var arr = new Float64ArrayLE( buf, 8 ); +* // returns +* +* var len = arr.length; +* // returns 1 +* +* @example +* var ArrayBuffer = require( '@stdlib/array/buffer' ); +* var factory = require( '@stdlib/array/little-endian-factory' ); +* +* var Float64ArrayLE = factory( 'float64' ); +* +* var buf = new ArrayBuffer( 32 ); +* var arr = new Float64ArrayLE( buf, 8, 2 ); +* // returns +* +* var len = arr.length; +* // returns 2 +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/array/little-endian-factory/lib/main.js b/lib/node_modules/@stdlib/array/little-endian-factory/lib/main.js new file mode 100644 index 00000000000..ef4cb4e2965 --- /dev/null +++ b/lib/node_modules/@stdlib/array/little-endian-factory/lib/main.js @@ -0,0 +1,359 @@ +/** +* @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. +*/ + +/* eslint-disable max-len, no-restricted-syntax, no-invalid-this */ + +'use strict'; + +// MODULES // + +var isCollection = require( '@stdlib/assert/is-collection' ); +var isObject = require( '@stdlib/assert/is-object' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var hasIteratorSymbolSupport = require( '@stdlib/assert/has-iterator-symbol-support' ); +var ITERATOR_SYMBOL = require( '@stdlib/symbol/iterator' ); +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var getter = require( '@stdlib/array/base/getter' ); +var accessorGetter = require( '@stdlib/array/base/accessor-getter' ); +var inherits = require( '@stdlib/utils/inherit' ); +var fixedEndianFactory = require( '@stdlib/array/fixed-endian-factory' ); +var bytesPerElement = require( '@stdlib/ndarray/base/bytes-per-element' ); +var capitalize = require( '@stdlib/string/base/capitalize' ); +var format = require( '@stdlib/string/format' ); +var fromIterator = require( './from_iterator.js' ); +var fromIteratorMap = require( './from_iterator_map.js' ); + + +// VARIABLES // + +var HAS_ITERATOR_SYMBOL = hasIteratorSymbolSupport(); +var BYTE_ORDER = 'little-endian'; +var DTYPE2SET = { + 'float64': 'setFloat64', + 'float32': 'setFloat32', + 'int32': 'setInt32', + 'int16': 'setInt16', + 'uint32': 'setUint32', + 'uint16': 'setUint16' +}; +var CHAR2ARTICLE = { + 'c': 'a', + 'f': 'a', + 'i': 'an', + 'u': 'a', + 'b': 'a' +}; + + +// FUNCTIONS // + +/** +* Converts a data type string to a constructor name. +* +* @private +* @param {string} dtype - data type +* @returns {string} constructor name +* +* @example +* var n = dtype2ctor( 'float64' ); +* // returns 'Float64ArrayLE' +* +* @example +* var n = dtype2ctor( 'int32' ); +* // returns 'Int32ArrayLE' +*/ +function dtype2ctor( dtype ) { + return capitalize( dtype ) + 'ArrayLE'; +} + + +// MAIN // + +/** +* Returns a typed array constructor for creating typed arrays stored in little-endian byte order. +* +* @param {string} dtype - typed array data type +* @throws {TypeError} first argument must be a supported data type +* @returns {Function} typed array constructor +* +* @example +* var Float64ArrayLE = factory( 'float64' ); +* +* var arr = new Float64ArrayLE(); +* // returns +* +* var len = arr.length; +* // returns 0 +* +* @example +* var Float64ArrayLE = factory( 'float64' ); +* +* var arr = new Float64ArrayLE( 2 ); +* // returns +* +* var len = arr.length; +* // returns 2 +* +* @example +* var Float64ArrayLE = factory( 'float64' ); +* +* var arr = new Float64ArrayLE( [ 1.0, 2.0 ] ); +* // returns +* +* var len = arr.length; +* // returns 2 +* +* @example +* var ArrayBuffer = require( '@stdlib/array/buffer' ); +* +* var Float64ArrayLE = factory( 'float64' ); +* +* var buf = new ArrayBuffer( 16 ); +* var arr = new Float64ArrayLE( buf ); +* // returns +* +* var len = arr.length; +* // returns 2 +* +* @example +* var ArrayBuffer = require( '@stdlib/array/buffer' ); +* +* var Float64ArrayLE = factory( 'float64' ); +* +* var buf = new ArrayBuffer( 16 ); +* var arr = new Float64ArrayLE( buf, 8 ); +* // returns +* +* var len = arr.length; +* // returns 1 +* +* @example +* var ArrayBuffer = require( '@stdlib/array/buffer' ); +* +* var Float64ArrayLE = factory( 'float64' ); +* +* var buf = new ArrayBuffer( 32 ); +* var arr = new Float64ArrayLE( buf, 8, 2 ); +* // returns +* +* var len = arr.length; +* // returns 2 +*/ +function factory( dtype ) { + var BYTES_PER_ELEMENT; + var CTOR_NAME; + var SETTER; + var parent; + + // Defer `dtype` validation to `fixedEndianFactory`: + parent = fixedEndianFactory( dtype ); + + BYTES_PER_ELEMENT = bytesPerElement( dtype ); + CTOR_NAME = dtype2ctor( dtype ); + SETTER = DTYPE2SET[ dtype ]; + + /** + * Typed array constructor which returns a typed array representing an array of values in little-endian byte order. + * + * @private + * @constructor + * @param {(NonNegativeInteger|Collection|ArrayBuffer|Iterable)} [arg] - length, typed array, array-like object, buffer, or an iterable + * @param {NonNegativeInteger} [byteOffset=0] - byte offset + * @param {NonNegativeInteger} [length] - view length + * @throws {TypeError} if provided only one argument, the argument must be a valid argument + * @throws {TypeError} byte offset must be a nonnegative integer + * @throws {RangeError} must provide sufficient memory to accommodate byte offset and view length requirements + * @returns {TypedArray} typed array instance + */ + function TypedArray() { + var nargs = arguments.length; + if ( !(this instanceof TypedArray) ) { + if ( nargs === 0 ) { + return new TypedArray(); + } + if ( nargs === 1 ) { + return new TypedArray( arguments[0] ); + } + if ( nargs === 2 ) { + return new TypedArray( arguments[0], arguments[1] ); + } + return new TypedArray( arguments[0], arguments[1], arguments[2] ); + } + if ( nargs === 0 ) { + parent.call( this, BYTE_ORDER ); + } else if ( nargs === 1 ) { + parent.call( this, BYTE_ORDER, arguments[0] ); + } else if ( nargs === 2 ) { + parent.call( this, BYTE_ORDER, arguments[0], arguments[1] ); + } else if ( nargs === 3 ) { + parent.call( this, BYTE_ORDER, arguments[0], arguments[1], arguments[2] ); + } + return this; + } + + /** + * Size (in bytes) of each array element. + * + * @private + * @name BYTES_PER_ELEMENT + * @memberof TypedArray + * @readonly + * @type {PositiveInteger} + */ + setReadOnly( TypedArray, 'BYTES_PER_ELEMENT', BYTES_PER_ELEMENT ); + + /** + * Constructor name. + * + * @private + * @name name + * @memberof TypedArray + * @readonly + * @type {string} + */ + setReadOnly( TypedArray, 'name', CTOR_NAME ); + + /** + * Creates a new typed array from an array-like object or an iterable. + * + * @private + * @name from + * @memberof TypedArray + * @type {Function} + * @param {(Collection|Iterable)} src - array-like object or iterable + * @param {Function} [clbk] - callback to invoke for each source element + * @param {*} [thisArg] - context + * @throws {TypeError} `this` context must be a constructor + * @throws {TypeError} `this` must be a typed array constructor + * @throws {TypeError} first argument must be an array-like object or an iterable + * @throws {TypeError} second argument must be a function + * @returns {TypedArray} typed array instance + */ + setReadOnly( TypedArray, 'from', function from( src ) { + var thisArg; + var nargs; + var clbk; + var out; + var buf; + var tmp; + var get; + var len; + var i; + if ( !isFunction( this ) ) { + throw new TypeError( 'invalid invocation. `this` context must be a constructor.' ); + } + if ( !isTypedArrayConstructor( this ) ) { + throw new TypeError( format( 'invalid invocation. `this` is not %s %s.', CHAR2ARTICLE[ dtype[0] ], CTOR_NAME ) ); + } + nargs = arguments.length; + if ( nargs > 1 ) { + clbk = arguments[ 1 ]; + if ( !isFunction( clbk ) ) { + throw new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', clbk ) ); + } + if ( nargs > 2 ) { + thisArg = arguments[ 2 ]; + } + } + if ( isCollection( src ) ) { + if ( clbk ) { + len = src.length; + if ( src.get && src.set ) { + get = accessorGetter( 'default' ); + } else { + get = getter( 'default' ); + } + out = new this( len ); + buf = out._buffer; // eslint-disable-line no-underscore-dangle + for ( i = 0; i < len; i++ ) { + buf[ SETTER ]( i*BYTES_PER_ELEMENT, clbk.call( thisArg, get( src, i ), i ), true ); + } + return out; + } + return new this( src ); + } + if ( isObject( src ) && HAS_ITERATOR_SYMBOL && isFunction( src[ ITERATOR_SYMBOL ] ) ) { + buf = src[ ITERATOR_SYMBOL ](); + if ( !isFunction( buf.next ) ) { + throw new TypeError( format( 'invalid argument. First argument must be an array-like object or an iterable. Value: `%s`.', src ) ); + } + if ( clbk ) { + tmp = fromIteratorMap( buf, clbk, thisArg ); + } else { + tmp = fromIterator( buf ); + } + len = tmp.length; + out = new this( len ); + buf = out._buffer; // eslint-disable-line no-underscore-dangle + for ( i = 0; i < len; i++ ) { + buf[ SETTER ]( i*BYTES_PER_ELEMENT, tmp[ i ], true ); + } + return out; + } + throw new TypeError( format( 'invalid argument. First argument must be an array-like object or an iterable. Value: `%s`.', src ) ); + }); + + /** + * Creates a new typed array from a variable number of arguments. + * + * @private + * @name of + * @memberof TypedArray + * @type {Function} + * @param {...*} element - array elements + * @throws {TypeError} `this` context must be a constructor + * @throws {TypeError} `this` must be a typed array constructor + * @returns {TypedArray} typed array instance + */ + setReadOnly( TypedArray, 'of', function of() { + var args; + var i; + if ( !isFunction( this ) ) { + throw new TypeError( 'invalid invocation. `this` context must be a constructor.' ); + } + if ( !isTypedArrayConstructor( this ) ) { + throw new TypeError( format( 'invalid invocation. `this` is not %s %s.', CHAR2ARTICLE[ dtype[0] ], CTOR_NAME ) ); + } + args = []; + for ( i = 0; i < arguments.length; i++ ) { + args.push( arguments[ i ] ); + } + return new this( args ); + }); + + // Inherit from the parent constructor: + inherits( TypedArray, parent ); + + return TypedArray; + + /** + * Returns a boolean indicating if a value is a typed array constructor. + * + * @private + * @param {*} value - value to test + * @returns {boolean} boolean indicating if a value is a typed array constructor + */ + function isTypedArrayConstructor( value ) { + return ( value === TypedArray ); + } +} + + +// EXPORTS // + +module.exports = factory; diff --git a/lib/node_modules/@stdlib/array/little-endian-factory/package.json b/lib/node_modules/@stdlib/array/little-endian-factory/package.json new file mode 100644 index 00000000000..13e1aa59208 --- /dev/null +++ b/lib/node_modules/@stdlib/array/little-endian-factory/package.json @@ -0,0 +1,66 @@ +{ + "name": "@stdlib/array/little-endian-factory", + "version": "0.0.0", + "description": "Return a typed array constructor for creating typed arrays stored in little-endian byte order.", + "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", + "stdtypes", + "types", + "data", + "structure", + "array", + "typed", + "typed array", + "typed-array", + "factory", + "endian", + "little-endian", + "byte-order" + ] +} diff --git a/lib/node_modules/@stdlib/array/little-endian-factory/test/test.js b/lib/node_modules/@stdlib/array/little-endian-factory/test/test.js new file mode 100644 index 00000000000..99d011d0b56 --- /dev/null +++ b/lib/node_modules/@stdlib/array/little-endian-factory/test/test.js @@ -0,0 +1,35 @@ +/** +* @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 factory = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof factory, 'function', 'main export is a function' ); + t.end(); +}); + +// TODO: add tests diff --git a/lib/node_modules/@stdlib/array/little-endian-float64/README.md b/lib/node_modules/@stdlib/array/little-endian-float64/README.md new file mode 100644 index 00000000000..47578d01187 --- /dev/null +++ b/lib/node_modules/@stdlib/array/little-endian-float64/README.md @@ -0,0 +1,438 @@ + + +# Float64ArrayLE + +> Typed array constructor which returns a typed array representing an array of double-precision floating-point numbers in little-endian byte order. + + + +
+ +In contrast to the [`Float64Array`][@stdlib/array/float64] typed array constructor which stores values according to the host platform byte order, the `Float64ArrayLE` constructor always accesses elements in little-endian byte order. Such enforcement can be particularly advantageous when working with memory buffers which do not necessarily follow host platform byte order, such as [WebAssembly memory][@stdlib/wasm/memory]. + +
+ + + + + +
+ +## Usage + +```javascript +var Float64ArrayLE = require( '@stdlib/array/little-endian-float64' ); +``` + +#### Float64ArrayLE() + +A typed array constructor which returns a typed array representing an array of double-precision floating-point numbers in little-endian byte order. + +```javascript +var arr = new Float64ArrayLE(); +// returns +``` + +#### Float64ArrayLE( length ) + +Returns a typed array having a specified length. + +```javascript +var arr = new Float64ArrayLE( 5 ); +// returns +``` + +#### Float64ArrayLE( typedarray ) + +Creates a typed array from another typed array. + +```javascript +var Float32Array = require( '@stdlib/array/float32' ); + +var arr1 = new Float32Array( [ 0.5, 0.5, 0.5 ] ); +var arr2 = new Float64ArrayLE( arr1 ); +// returns + +var v = arr2.get( 0 ); +// returns 0.5 +``` + +#### Float64ArrayLE( obj ) + +Creates a typed array from an array-like object or iterable. + +```javascript +var arr = new Float64ArrayLE( [ 0.5, 0.5, 0.5 ] ); +// returns + +var v = arr.get( 0 ); +// returns 0.5 +``` + +#### Float64ArrayLE( buffer\[, byteOffset\[, length]] ) + +Returns a typed array view of an [`ArrayBuffer`][@stdlib/array/buffer]. + +```javascript +var ArrayBuffer = require( '@stdlib/array/buffer' ); + +var buf = new ArrayBuffer( 32 ); +var arr = new Float64ArrayLE( buf, 0, 4 ); +// returns +``` + +* * * + +### Properties + + + +#### Float64ArrayLE.BYTES_PER_ELEMENT + +Number of bytes per view element. + +```javascript +var nbytes = Float64ArrayLE.BYTES_PER_ELEMENT; +// returns 8 +``` + + + +#### Float64ArrayLE.name + +Typed array constructor name. + +```javascript +var str = Float64ArrayLE.name; +// returns 'Float64ArrayLE' +``` + + + +#### Float64ArrayLE.prototype.buffer + +**Read-only** property which returns the [`ArrayBuffer`][@stdlib/array/buffer] referenced by the typed array. + +```javascript +var arr = new Float64ArrayLE( 5 ); +var buf = arr.buffer; +// returns +``` + + + +#### Float64ArrayLE.prototype.byteLength + +**Read-only** property which returns the length (in bytes) of the typed array. + +```javascript +var arr = new Float64ArrayLE( 5 ); +var byteLength = arr.byteLength; +// returns 40 +``` + + + +#### Float64ArrayLE.prototype.byteOffset + +**Read-only** property which returns the offset (in bytes) of the typed array from the start of its [`ArrayBuffer`][@stdlib/array/buffer]. + +```javascript +var arr = new Float64ArrayLE( 5 ); +var byteOffset = arr.byteOffset; +// returns 0 +``` + + + +#### Float64ArrayLE.prototype.BYTES_PER_ELEMENT + +Number of bytes per view element. + +```javascript +var arr = new Float64ArrayLE( 5 ); +var nbytes = arr.BYTES_PER_ELEMENT; +// returns 8 +``` + + + +#### Float64ArrayLE.prototype.length + +**Read-only** property which returns the number of view elements. + +```javascript +var arr = new Float64ArrayLE( 5 ); +var len = arr.length; +// returns 5 +``` + +* * * + +### Methods + + + +#### Float64ArrayLE.from( src\[, map\[, thisArg]] ) + +Creates a new typed array from an array-like object or an iterable. + +```javascript +var arr = Float64ArrayLE.from( [ 1.0, -1.0 ] ); +// returns + +var v = arr.get( 0 ); +// returns 1.0 +``` + +To invoke a function for each `src` value, provide a callback function. + +```javascript +function mapFcn( v ) { + return v * 2.0; +} + +var arr = Float64ArrayLE.from( [ 1.0, -1.0 ], mapFcn ); +// returns + +var v = arr.get( 0 ); +// returns 2.0 +``` + +A callback function is provided two arguments: + +- **value**: source value. +- **index**: source index. + +To set the callback execution context, provide a `thisArg`. + +```javascript +function mapFcn( v ) { + this.count += 1; + return v * 2.0; +} + +var ctx = { + 'count': 0 +}; + +var arr = Float64ArrayLE.from( [ 1.0, -1.0 ], mapFcn, ctx ); +// returns + +var v = arr.get( 0 ); +// returns 2.0 + +var n = ctx.count; +// returns 2 +``` + + + +#### Float64ArrayLE.of( element0\[, element1\[, ...elementN]] ) + +Creates a new typed array from a variable number of arguments. + +```javascript +var arr = Float64ArrayLE.of( 1.0, -1.0 ); +// returns + +var v = arr.get( 0 ); +// returns 1.0 +``` + + + +#### Float64ArrayLE.prototype.get( i ) + +Returns an array element located at a nonnegative integer position (index) `i`. + +```javascript +var arr = new Float64ArrayLE( 10 ); + +// Set the first element: +arr.set( 1.0, 0 ); + +// Get the first element: +var v = arr.get( 0 ); +// returns 1.0 +``` + +If provided an out-of-bounds index, the method returns `undefined`. + +```javascript +var arr = new Float64ArrayLE( 10 ); + +var v = arr.get( 100 ); +// returns undefined +``` + + + +#### Float64ArrayLE.prototype.set( arr\[, offset] ) + +Sets array elements. + +```javascript +var arr = new Float64ArrayLE( [ 1.0, 2.0, 3.0 ] ); +// returns + +var v = arr.get( 0 ); +// returns 1.0 + +v = arr.get( 1 ); +// returns 2.0 + +// Set the first two array elements: +arr.set( [ 4.0, 5.0 ] ); + +v = arr.get( 0 ); +// returns 4.0 + +v = arr.get( 1 ); +// returns 5.0 +``` + +By default, the method starts writing values at the first array index. To specify an alternative index, provide an index `offset`. + +```javascript +var arr = new Float64ArrayLE( [ 1.0, 2.0, 3.0 ] ); +// returns + +// Set the last two array elements: +arr.set( [ 4.0, 5.0 ], 1 ); + +var v = arr.get( 1 ); +// returns 4.0 + +v = arr.get( 2 ); +// returns 5.0 +``` + +A few notes: + +- If `i` is out-of-bounds, the method throws an error. +- If a target array cannot accommodate all values (i.e., the length of source array plus `i` exceeds the target array length), the method throws an error. +- If provided a typed array which shares an [`ArrayBuffer`][@stdlib/array/buffer] with the target array, the method will intelligently copy the source range to the destination range. + + + +#### Float64ArrayLE.prototype.toString() + +Serializes an array as a string. + +```javascript +var arr = new Float64ArrayLE( [ 1.0, 2.0, 3.0 ] ); + +var str = arr.toString(); +// returns '1,2,3' +``` + +
+ + + + + +
+ +* * * + +## Notes + +- While a `Float64ArrayLE` _strives_ to maintain (but does not **guarantee**) consistency with [typed arrays][@stdlib/array/typed], significant deviations from ECMAScript-defined [typed array][@stdlib/array/typed] behavior are as follows: + + - The constructor does **not** require the `new` operator. + - Accessing array elements using bracket syntax (e.g., `X[i]`) is **not** supported. Instead, one **must** use the `.get()` method. + +
+ + + + + +
+ +* * * + +## Examples + + + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); +var logEach = require( '@stdlib/console/log-each' ); +var Float64ArrayLE = require( '@stdlib/array/little-endian-float64' ); + +// Create a typed array by specifying a length: +var out = new Float64ArrayLE( 3 ); +logEach( '%s', out ); + +// Create a typed array from an array: +var arr = [ 1.0, -1.0, -3.14, 3.14, 0.5, 0.5 ]; +out = new Float64ArrayLE( arr ); +logEach( '%s', out ); + +// Create a typed array from an array buffer: +arr = new Float64Array( [ 1.0, -1.0, -3.14, 3.14, 0.5, 0.5 ] ); // host byte order +out = new Float64ArrayLE( arr.buffer ); +logEach( '%s', out ); + +// Create a typed array from an array buffer view: +arr = new Float64Array( [ 1.0, -1.0, -3.14, 3.14, 0.5, 0.5 ] ); // host byte order +out = new Float64ArrayLE( arr.buffer, 8, 2 ); +logEach( '%s', out ); +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/array/little-endian-float64/benchmark/benchmark.from.js b/lib/node_modules/@stdlib/array/little-endian-float64/benchmark/benchmark.from.js new file mode 100644 index 00000000000..2cd64477a5b --- /dev/null +++ b/lib/node_modules/@stdlib/array/little-endian-float64/benchmark/benchmark.from.js @@ -0,0 +1,310 @@ +/** +* @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 Float64Array = require( '@stdlib/array/float64' ); +var ITERATOR_SYMBOL = require( '@stdlib/symbol/iterator' ); +var pkg = require( './../package.json' ).name; +var Float64ArrayLE = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': ( ITERATOR_SYMBOL === null ) +}; + + +// MAIN // + +bench( pkg+'::typed_array:from', function benchmark( b ) { + var buf; + var arr; + var i; + + buf = new Float64Array( 0 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = Float64ArrayLE.from( buf ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayLE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::typed_array:from:len=5', function benchmark( b ) { + var buf; + var arr; + var i; + + buf = new Float64Array( 5 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = Float64ArrayLE.from( buf ); + if ( arr.length !== 5 ) { + b.fail( 'should have length 5' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayLE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::typed_array,clbk:from:len=5', function benchmark( b ) { + var buf; + var arr; + var i; + + buf = new Float64Array( 5 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = Float64ArrayLE.from( buf, clbk ); + if ( arr.length !== 5 ) { + b.fail( 'should have length 5' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayLE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function clbk( v ) { + return v * 2.0; + } +}); + +bench( pkg+'::array:from', function benchmark( b ) { + var buf; + var arr; + var i; + + buf = []; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = Float64ArrayLE.from( buf ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayLE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::array:from:len=5', function benchmark( b ) { + var buf; + var arr; + var i; + + buf = [ 1.0, 1.0, 1.0, 1.0, 1.0 ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = Float64ArrayLE.from( buf ); + if ( arr.length !== 5 ) { + b.fail( 'should have length 5' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayLE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::array,clbk:from:len=5', function benchmark( b ) { + var buf; + var arr; + var i; + + buf = [ 1.0, 1.0, 1.0, 1.0, 1.0 ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = Float64ArrayLE.from( buf, clbk ); + if ( arr.length !== 5 ) { + b.fail( 'should have length 5' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayLE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function clbk( v ) { + return v * 2.0; + } +}); + +bench( pkg+'::iterable:from', opts, function benchmark( b ) { + var arr; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = Float64ArrayLE.from( createIterable() ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayLE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function createIterable() { + var out = {}; + out[ ITERATOR_SYMBOL ] = iterator; + return out; + + function iterator() { + return { + 'next': next + }; + } + + function next() { + return { + 'done': true + }; + } + } +}); + +bench( pkg+'::iterable:from:len=5', opts, function benchmark( b ) { + var arr; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = Float64ArrayLE.from( createIterable() ); + if ( arr.length !== 5 ) { + b.fail( 'should have length 5' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayLE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function createIterable() { + var out = {}; + out[ ITERATOR_SYMBOL ] = iterator; + return out; + + function iterator() { + var it = { + 'next': next, + 'i': 0, + 'N': 5 + }; + return it; + + function next() { + it.i += 1; + if ( it.i <= it.N ) { + return { + 'value': 1.0 + }; + } + return { + 'done': true + }; + } + } + } +}); + +bench( pkg+'::iterable,clbk:from:len=5', opts, function benchmark( b ) { + var arr; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = Float64ArrayLE.from( createIterable(), clbk ); + if ( arr.length !== 5 ) { + b.fail( 'should have length 5' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayLE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function createIterable() { + var out = {}; + out[ ITERATOR_SYMBOL ] = iterator; + return out; + + function iterator() { + var it = { + 'next': next, + 'i': 0, + 'N': 5 + }; + return it; + + function next() { + it.i += 1; + if ( it.i <= it.N ) { + return { + 'value': 1.0 + }; + } + return { + 'done': true + }; + } + } + } + + function clbk( v ) { + return v * 2.0; + } +}); diff --git a/lib/node_modules/@stdlib/array/little-endian-float64/benchmark/benchmark.get.js b/lib/node_modules/@stdlib/array/little-endian-float64/benchmark/benchmark.get.js new file mode 100644 index 00000000000..127c09523b3 --- /dev/null +++ b/lib/node_modules/@stdlib/array/little-endian-float64/benchmark/benchmark.get.js @@ -0,0 +1,57 @@ +/** +* @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 isNumber = require( '@stdlib/assert/is-number' ).isPrimitive; +var pkg = require( './../package.json' ).name; +var Float64ArrayLE = require( './../lib' ); + + +// MAIN // + +bench( pkg+':get', function benchmark( b ) { + var arr; + var N; + var v; + var i; + + arr = []; + for ( i = 0; i < 10; i++ ) { + arr.push( i ); + } + arr = new Float64ArrayLE( arr ); + N = arr.length; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = arr.get( i%N ); + if ( typeof v !== 'number' ) { + b.fail( 'should return a number' ); + } + } + b.toc(); + if ( !isNumber( v ) ) { + b.fail( 'should return a number' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/little-endian-float64/benchmark/benchmark.js b/lib/node_modules/@stdlib/array/little-endian-float64/benchmark/benchmark.js new file mode 100644 index 00000000000..51dababfb74 --- /dev/null +++ b/lib/node_modules/@stdlib/array/little-endian-float64/benchmark/benchmark.js @@ -0,0 +1,346 @@ +/** +* @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 ArrayBuffer = require( '@stdlib/array/buffer' ); +var Float64Array = require( '@stdlib/array/float64' ); +var isArrayBuffer = require( '@stdlib/assert/is-arraybuffer' ); +var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).isPrimitive; +var ITERATOR_SYMBOL = require( '@stdlib/symbol/iterator' ); +var pkg = require( './../package.json' ).name; +var Float64ArrayLE = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': ( ITERATOR_SYMBOL === null ) +}; + + +// FUNCTIONS // + +/** +* Returns an "iterable" object. +* +* @private +* @returns {Object} iterable object +*/ +function createIterable() { + var out = {}; + out[ ITERATOR_SYMBOL ] = iterator; + return out; + + function iterator() { + return { + 'next': next + }; + } + + function next() { + return { + 'done': true + }; + } +} + + +// MAIN // + +bench( pkg+'::instantiation,new', function benchmark( b ) { + var arr; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = new Float64ArrayLE(); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayLE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::instantiation,no_new', function benchmark( b ) { + var ctor; + var arr; + var i; + + ctor = Float64ArrayLE; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = ctor(); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayLE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::instantiation,length', function benchmark( b ) { + var arr; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = new Float64ArrayLE( 0 ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayLE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::instantiation,typed_array', function benchmark( b ) { + var buf; + var arr; + var i; + + buf = new Float64Array( 0 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = new Float64ArrayLE( buf ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayLE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::instantiation,array', function benchmark( b ) { + var buf; + var arr; + var i; + + buf = []; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = new Float64ArrayLE( buf ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayLE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::instantiation,iterable', opts, function benchmark( b ) { + var arr; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = new Float64ArrayLE( createIterable() ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayLE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::instantiation,arraybuffer', function benchmark( b ) { + var buf; + var arr; + var i; + + buf = new ArrayBuffer( 0 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = new Float64ArrayLE( buf ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayLE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::instantiation,arraybuffer,byte_offset', function benchmark( b ) { + var buf; + var arr; + var i; + + buf = new ArrayBuffer( 8 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = new Float64ArrayLE( buf, 8 ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayLE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::instantiation,arraybuffer,byte_offset,length', function benchmark( b ) { + var buf; + var arr; + var i; + + buf = new ArrayBuffer( 8 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = new Float64ArrayLE( buf, 8, 0 ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayLE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::get:buffer', function benchmark( b ) { + var arr; + var v; + var i; + + arr = new Float64ArrayLE(); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + // Note: the following may be optimized away due to loop invariant code motion and/or other compiler optimizations, rendering this benchmark meaningless... + v = arr.buffer; + if ( typeof v !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isArrayBuffer( v ) ) { + b.fail( 'should return an ArrayBuffer' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::get:byteLength', function benchmark( b ) { + var arr; + var v; + var i; + + arr = new Float64ArrayLE(); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + // Note: the following may be optimized away due to loop invariant code motion and/or other compiler optimizations, rendering this benchmark meaningless... + v = arr.byteLength; + if ( v !== v ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( !isNonNegativeInteger( v ) ) { + b.fail( 'should return a nonnegative integer' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::get:byteOffset', function benchmark( b ) { + var arr; + var v; + var i; + + arr = new Float64ArrayLE(); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + // Note: the following may be optimized away due to loop invariant code motion and/or other compiler optimizations, rendering this benchmark meaningless... + v = arr.byteOffset; + if ( v !== v ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( !isNonNegativeInteger( v ) ) { + b.fail( 'should return a nonnegative integer' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::get:length', function benchmark( b ) { + var arr; + var v; + var i; + + arr = new Float64ArrayLE(); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + // Note: the following may be optimized away due to loop invariant code motion and/or other compiler optimizations, rendering this benchmark meaningless... + v = arr.length; + if ( v !== v ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( !isNonNegativeInteger( v ) ) { + b.fail( 'should return a nonnegative integer' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/little-endian-float64/benchmark/benchmark.of.js b/lib/node_modules/@stdlib/array/little-endian-float64/benchmark/benchmark.of.js new file mode 100644 index 00000000000..ca9ef910707 --- /dev/null +++ b/lib/node_modules/@stdlib/array/little-endian-float64/benchmark/benchmark.of.js @@ -0,0 +1,69 @@ +/** +* @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 pkg = require( './../package.json' ).name; +var Float64ArrayLE = require( './../lib' ); + + +// MAIN // + +bench( pkg+':of', function benchmark( b ) { + var arr; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = Float64ArrayLE.of(); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayLE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+':len=5', function benchmark( b ) { + var buf; + var arr; + var i; + + buf = [ 1.0, 1.0, 1.0, 1.0, 1.0 ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = Float64ArrayLE.of.apply( Float64ArrayLE, buf ); + if ( arr.length !== 5 ) { + b.fail( 'should have length 5' ); + } + } + b.toc(); + if ( !(arr instanceof Float64ArrayLE) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/little-endian-float64/benchmark/benchmark.set.js b/lib/node_modules/@stdlib/array/little-endian-float64/benchmark/benchmark.set.js new file mode 100644 index 00000000000..d2f70532554 --- /dev/null +++ b/lib/node_modules/@stdlib/array/little-endian-float64/benchmark/benchmark.set.js @@ -0,0 +1,119 @@ +/** +* @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 Float64Array = require( '@stdlib/array/float64' ); +var pkg = require( './../package.json' ).name; +var Float64ArrayLE = require( './../lib' ); + + +// MAIN // + +bench( pkg+'::number:set', function benchmark( b ) { + var values; + var arr; + var N; + var v; + var i; + + values = []; + for ( i = 0; i < 10; i++ ) { + values.push( i ); + } + arr = new Float64ArrayLE( values ); + N = arr.length; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = arr.set( values[ (i+1)%N ] ); + if ( typeof v !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + } + b.toc(); + if ( typeof v !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::array:set', function benchmark( b ) { + var values; + var arr; + var N; + var v; + var i; + + values = []; + for ( i = 0; i < 10; i++ ) { + values.push( i ); + } + arr = new Float64ArrayLE( values ); + N = arr.length; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = arr.set( [ values[ (i+1)%N ] ] ); + if ( typeof v !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + } + b.toc(); + if ( typeof v !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::typed_array:set', function benchmark( b ) { + var values; + var arr; + var buf; + var N; + var v; + var i; + + values = new Float64Array( 20 ); + N = values.length; + for ( i = 0; i < N; i++ ) { + values[ i ] = i; + } + arr = new Float64ArrayLE( values ); + buf = new Float64Array( 1 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + buf[ 0 ] = values[ i%N ]; + v = arr.set( buf ); + if ( typeof v !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + } + b.toc(); + if ( typeof v !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/little-endian-float64/benchmark/benchmark.set.length.js b/lib/node_modules/@stdlib/array/little-endian-float64/benchmark/benchmark.set.length.js new file mode 100644 index 00000000000..885f756b4b8 --- /dev/null +++ b/lib/node_modules/@stdlib/array/little-endian-float64/benchmark/benchmark.set.length.js @@ -0,0 +1,110 @@ +/** +* @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 pow = require( '@stdlib/math/base/special/pow' ); +var randu = require( '@stdlib/random/array/randu' ); +var pkg = require( './../package.json' ).name; +var Float64ArrayLE = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var values; + var arr1; + var arr2; + var arr3; + var N; + + arr1 = randu( len ); + arr2 = randu( len ); + arr3 = randu( len ); + arr1 = new Float64ArrayLE( arr1 ); + + values = [ + new Float64ArrayLE( arr2 ), + new Float64ArrayLE( arr3 ) + ]; + N = values.length; + + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = arr1.set( values[ i%N ] ); + if ( typeof v !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + } + b.toc(); + if ( typeof v !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':set:len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/little-endian-float64/benchmark/benchmark.to_string.js b/lib/node_modules/@stdlib/array/little-endian-float64/benchmark/benchmark.to_string.js new file mode 100644 index 00000000000..c3ebf9c2839 --- /dev/null +++ b/lib/node_modules/@stdlib/array/little-endian-float64/benchmark/benchmark.to_string.js @@ -0,0 +1,50 @@ +/** +* @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 pkg = require( './../package.json' ).name; +var Float64ArrayLE = require( './../lib' ); + + +// MAIN // + +bench( pkg+':toString', function benchmark( b ) { + var out; + var arr; + var i; + + arr = new Float64ArrayLE( [ 1.0, 2.0, 2.0, 1.0 ] ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.toString(); + if ( typeof out !== 'string' ) { + b.fail( 'should return a string' ); + } + } + b.toc(); + if ( typeof out !== 'string' ) { + b.fail( 'should return a string' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/little-endian-float64/benchmark/benchmark.to_string.length.js b/lib/node_modules/@stdlib/array/little-endian-float64/benchmark/benchmark.to_string.length.js new file mode 100644 index 00000000000..10a65c56627 --- /dev/null +++ b/lib/node_modules/@stdlib/array/little-endian-float64/benchmark/benchmark.to_string.length.js @@ -0,0 +1,94 @@ +/** +* @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 pow = require( '@stdlib/math/base/special/pow' ); +var zeroTo = require( '@stdlib/array/zero-to' ); +var pkg = require( './../package.json' ).name; +var Float64ArrayLE = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var arr = new Float64ArrayLE( zeroTo( len ) ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.toString(); + if ( typeof out !== 'string' ) { + b.fail( 'should return a string' ); + } + } + b.toc(); + if ( typeof out !== 'string' ) { + b.fail( 'should return a string' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':toString:len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/little-endian-float64/examples/index.js b/lib/node_modules/@stdlib/array/little-endian-float64/examples/index.js new file mode 100644 index 00000000000..6bae2ff208e --- /dev/null +++ b/lib/node_modules/@stdlib/array/little-endian-float64/examples/index.js @@ -0,0 +1,42 @@ +/** +* @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 Float64Array = require( '@stdlib/array/float64' ); +var logEach = require( '@stdlib/console/log-each' ); +var Float64ArrayLE = require( './../lib' ); + +// Create a typed array by specifying a length: +var out = new Float64ArrayLE( 3 ); +logEach( '%s', out ); + +// Create a typed array from an array: +var arr = [ 1.0, -1.0, -3.14, 3.14, 0.5, 0.5 ]; +out = new Float64ArrayLE( arr ); +logEach( '%s', out ); + +// Create a typed array from an array buffer: +arr = new Float64Array( [ 1.0, -1.0, -3.14, 3.14, 0.5, 0.5 ] ); // host byte order +out = new Float64ArrayLE( arr.buffer ); +logEach( '%s', out ); + +// Create a typed array from an array buffer view: +arr = new Float64Array( [ 1.0, -1.0, -3.14, 3.14, 0.5, 0.5 ] ); // host byte order +out = new Float64ArrayLE( arr.buffer, 8, 2 ); +logEach( '%s', out ); diff --git a/lib/node_modules/@stdlib/array/little-endian-float64/lib/index.js b/lib/node_modules/@stdlib/array/little-endian-float64/lib/index.js new file mode 100644 index 00000000000..310b93fbea9 --- /dev/null +++ b/lib/node_modules/@stdlib/array/little-endian-float64/lib/index.js @@ -0,0 +1,94 @@ +/** +* @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'; + +/** +* Typed array constructor which returns a typed array representing an array of double-precision floating-point numbers in little-endian byte order. +* +* @module @stdlib/array/little-endian-float64 +* +* @example +* var Float64ArrayLE = require( '@stdlib/array/little-endian-float64' ); +* +* var arr = new Float64ArrayLE(); +* // returns +* +* var len = arr.length; +* // returns 0 +* +* @example +* var Float64ArrayLE = require( '@stdlib/array/little-endian-float64' ); +* +* var arr = new Float64ArrayLE( 2 ); +* // returns +* +* var len = arr.length; +* // returns 2 +* +* @example +* var Float64ArrayLE = require( '@stdlib/array/little-endian-float64' ); +* +* var arr = new Float64ArrayLE( [ 1.0 ] ); +* // returns +* +* var len = arr.length; +* // returns 1 +* +* @example +* var ArrayBuffer = require( '@stdlib/array/buffer' ); +* var Float64ArrayLE = require( '@stdlib/array/little-endian-float64' ); +* +* var buf = new ArrayBuffer( 16 ); +* var arr = new Float64ArrayLE( buf ); +* // returns +* +* var len = arr.length; +* // returns 2 +* +* @example +* var ArrayBuffer = require( '@stdlib/array/buffer' ); +* var Float64ArrayLE = require( '@stdlib/array/little-endian-float64' ); +* +* var buf = new ArrayBuffer( 16 ); +* var arr = new Float64ArrayLE( buf, 8 ); +* // returns +* +* var len = arr.length; +* // returns 1 +* +* @example +* var ArrayBuffer = require( '@stdlib/array/buffer' ); +* var Float64ArrayLE = require( '@stdlib/array/little-endian-float64' ); +* +* var buf = new ArrayBuffer( 32 ); +* var arr = new Float64ArrayLE( buf, 8, 2 ); +* // returns +* +* var len = arr.length; +* // returns 2 +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/array/little-endian-float64/lib/main.js b/lib/node_modules/@stdlib/array/little-endian-float64/lib/main.js new file mode 100644 index 00000000000..29fe4e3cd21 --- /dev/null +++ b/lib/node_modules/@stdlib/array/little-endian-float64/lib/main.js @@ -0,0 +1,98 @@ +/** +* @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 factory = require( '@stdlib/array/little-endian-factory' ); + + +// MAIN // + +/** +* Typed array constructor which returns a typed array representing an array of double-precision floating-point numbers in little-endian byte order. +* +* @name Float64ArrayLE +* @constructor +* @type {Function} +* @param {(NonNegativeInteger|Collection|ArrayBuffer|Iterable)} [arg] - length, typed array, array-like object, buffer, or an iterable +* @param {NonNegativeInteger} [byteOffset=0] - byte offset +* @param {NonNegativeInteger} [length] - view length +* @throws {TypeError} if provided only one argument, the argument must be a valid argument +* @throws {TypeError} byte offset must be a nonnegative integer +* @throws {RangeError} must provide sufficient memory to accommodate byte offset and view length requirements +* @returns {Float64ArrayLE} typed array instance +* +* @example +* var arr = new Float64ArrayLE(); +* // returns +* +* var len = arr.length; +* // returns 0 +* +* @example +* var arr = new Float64ArrayLE( 2 ); +* // returns +* +* var len = arr.length; +* // returns 2 +* +* @example +* var arr = new Float64ArrayLE( [ 1.0, 2.0 ] ); +* // returns +* +* var len = arr.length; +* // returns 2 +* +* @example +* var ArrayBuffer = require( '@stdlib/array/buffer' ); +* +* var buf = new ArrayBuffer( 16 ); +* var arr = new Float64ArrayLE( buf ); +* // returns +* +* var len = arr.length; +* // returns 2 +* +* @example +* var ArrayBuffer = require( '@stdlib/array/buffer' ); +* +* var buf = new ArrayBuffer( 16 ); +* var arr = new Float64ArrayLE( buf, 8 ); +* // returns +* +* var len = arr.length; +* // returns 1 +* +* @example +* var ArrayBuffer = require( '@stdlib/array/buffer' ); +* +* var buf = new ArrayBuffer( 32 ); +* var arr = new Float64ArrayLE( buf, 8, 2 ); +* // returns +* +* var len = arr.length; +* // returns 2 +*/ +var Float64ArrayLE = factory( 'float64' ); + + +// EXPORTS // + +module.exports = Float64ArrayLE; diff --git a/lib/node_modules/@stdlib/array/little-endian-float64/package.json b/lib/node_modules/@stdlib/array/little-endian-float64/package.json new file mode 100644 index 00000000000..05072203918 --- /dev/null +++ b/lib/node_modules/@stdlib/array/little-endian-float64/package.json @@ -0,0 +1,70 @@ +{ + "name": "@stdlib/array/little-endian-float64", + "version": "0.0.0", + "description": "Float64Array in little-endian byte order.", + "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", + "stdtypes", + "types", + "data", + "structure", + "array", + "typed", + "typed array", + "typed-array", + "float64array", + "float64", + "double", + "double-precision", + "ieee754", + "endian", + "little-endian", + "byte-order" + ] +} diff --git a/lib/node_modules/@stdlib/array/little-endian-float64/test/test.js b/lib/node_modules/@stdlib/array/little-endian-float64/test/test.js new file mode 100644 index 00000000000..fc72bbf8822 --- /dev/null +++ b/lib/node_modules/@stdlib/array/little-endian-float64/test/test.js @@ -0,0 +1,35 @@ +/** +* @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 ctor = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof ctor, 'function', 'main export is a function' ); + t.end(); +}); + +// TODO: add tests diff --git a/lib/node_modules/@stdlib/array/nans-like/docs/repl.txt b/lib/node_modules/@stdlib/array/nans-like/docs/repl.txt index b29b19e313d..df99cb07b8c 100644 --- a/lib/node_modules/@stdlib/array/nans-like/docs/repl.txt +++ b/lib/node_modules/@stdlib/array/nans-like/docs/repl.txt @@ -5,11 +5,11 @@ The function supports the following data types: - - float64: double-precision floating-point numbers (IEEE 754) - - float32: single-precision floating-point numbers (IEEE 754) - - complex128: double-precision complex floating-point numbers - - complex64: single-precision complex floating-point numbers - - generic: generic JavaScript values + - float64: double-precision floating-point numbers (IEEE 754). + - float32: single-precision floating-point numbers (IEEE 754). + - complex128: double-precision complex floating-point numbers. + - complex64: single-precision complex floating-point numbers. + - generic: generic JavaScript values. Parameters ---------- diff --git a/lib/node_modules/@stdlib/array/one-to-like/docs/repl.txt b/lib/node_modules/@stdlib/array/one-to-like/docs/repl.txt index a23253f58c0..9db036cae69 100644 --- a/lib/node_modules/@stdlib/array/one-to-like/docs/repl.txt +++ b/lib/node_modules/@stdlib/array/one-to-like/docs/repl.txt @@ -6,18 +6,18 @@ The function supports the following data types: - - float64: double-precision floating-point numbers (IEEE 754) - - float32: single-precision floating-point numbers (IEEE 754) - - complex128: double-precision complex floating-point numbers - - complex64: single-precision complex floating-point numbers - - int32: 32-bit two's complement signed integers - - uint32: 32-bit unsigned integers - - int16: 16-bit two's complement signed integers - - uint16: 16-bit unsigned integers - - int8: 8-bit two's complement signed integers - - uint8: 8-bit unsigned integers - - uint8c: 8-bit unsigned integers clamped to 0-255 - - generic: generic JavaScript values + - float64: double-precision floating-point numbers (IEEE 754). + - float32: single-precision floating-point numbers (IEEE 754). + - complex128: double-precision complex floating-point numbers. + - complex64: single-precision complex floating-point numbers. + - int32: 32-bit two's complement signed integers. + - uint32: 32-bit unsigned integers. + - int16: 16-bit two's complement signed integers. + - uint16: 16-bit unsigned integers. + - int8: 8-bit two's complement signed integers. + - uint8: 8-bit unsigned integers. + - uint8c: 8-bit unsigned integers clamped to 0-255. + - generic: generic JavaScript values. Parameters ---------- diff --git a/lib/node_modules/@stdlib/array/one-to/docs/repl.txt b/lib/node_modules/@stdlib/array/one-to/docs/repl.txt index cde1e731d0c..d80892df622 100644 --- a/lib/node_modules/@stdlib/array/one-to/docs/repl.txt +++ b/lib/node_modules/@stdlib/array/one-to/docs/repl.txt @@ -5,18 +5,18 @@ The function supports the following data types: - - float64: double-precision floating-point numbers (IEEE 754) - - float32: single-precision floating-point numbers (IEEE 754) - - complex128: double-precision complex floating-point numbers - - complex64: single-precision complex floating-point numbers - - int32: 32-bit two's complement signed integers - - uint32: 32-bit unsigned integers - - int16: 16-bit two's complement signed integers - - uint16: 16-bit unsigned integers - - int8: 8-bit two's complement signed integers - - uint8: 8-bit unsigned integers - - uint8c: 8-bit unsigned integers clamped to 0-255 - - generic: generic JavaScript values + - float64: double-precision floating-point numbers (IEEE 754). + - float32: single-precision floating-point numbers (IEEE 754). + - complex128: double-precision complex floating-point numbers. + - complex64: single-precision complex floating-point numbers. + - int32: 32-bit two's complement signed integers. + - uint32: 32-bit unsigned integers. + - int16: 16-bit two's complement signed integers. + - uint16: 16-bit unsigned integers. + - int8: 8-bit two's complement signed integers. + - uint8: 8-bit unsigned integers. + - uint8c: 8-bit unsigned integers clamped to 0-255. + - generic: generic JavaScript values. The default array data type is `float64`. diff --git a/lib/node_modules/@stdlib/array/ones-like/docs/repl.txt b/lib/node_modules/@stdlib/array/ones-like/docs/repl.txt index 6ec8be30a6f..d67ed49037a 100644 --- a/lib/node_modules/@stdlib/array/ones-like/docs/repl.txt +++ b/lib/node_modules/@stdlib/array/ones-like/docs/repl.txt @@ -5,18 +5,18 @@ The function supports the following data types: - - float64: double-precision floating-point numbers (IEEE 754) - - float32: single-precision floating-point numbers (IEEE 754) - - complex128: double-precision complex floating-point numbers - - complex64: single-precision complex floating-point numbers - - int32: 32-bit two's complement signed integers - - uint32: 32-bit unsigned integers - - int16: 16-bit two's complement signed integers - - uint16: 16-bit unsigned integers - - int8: 8-bit two's complement signed integers - - uint8: 8-bit unsigned integers - - uint8c: 8-bit unsigned integers clamped to 0-255 - - generic: generic JavaScript values + - float64: double-precision floating-point numbers (IEEE 754). + - float32: single-precision floating-point numbers (IEEE 754). + - complex128: double-precision complex floating-point numbers. + - complex64: single-precision complex floating-point numbers. + - int32: 32-bit two's complement signed integers. + - uint32: 32-bit unsigned integers. + - int16: 16-bit two's complement signed integers. + - uint16: 16-bit unsigned integers. + - int8: 8-bit two's complement signed integers. + - uint8: 8-bit unsigned integers. + - uint8c: 8-bit unsigned integers clamped to 0-255. + - generic: generic JavaScript values. Parameters ---------- diff --git a/lib/node_modules/@stdlib/array/ones/docs/repl.txt b/lib/node_modules/@stdlib/array/ones/docs/repl.txt index ba7bc66fe28..fea655d7afb 100644 --- a/lib/node_modules/@stdlib/array/ones/docs/repl.txt +++ b/lib/node_modules/@stdlib/array/ones/docs/repl.txt @@ -4,18 +4,18 @@ The function supports the following data types: - - float64: double-precision floating-point numbers (IEEE 754) - - float32: single-precision floating-point numbers (IEEE 754) - - complex128: double-precision complex floating-point numbers - - complex64: single-precision complex floating-point numbers - - int32: 32-bit two's complement signed integers - - uint32: 32-bit unsigned integers - - int16: 16-bit two's complement signed integers - - uint16: 16-bit unsigned integers - - int8: 8-bit two's complement signed integers - - uint8: 8-bit unsigned integers - - uint8c: 8-bit unsigned integers clamped to 0-255 - - generic: generic JavaScript values + - float64: double-precision floating-point numbers (IEEE 754). + - float32: single-precision floating-point numbers (IEEE 754). + - complex128: double-precision complex floating-point numbers. + - complex64: single-precision complex floating-point numbers. + - int32: 32-bit two's complement signed integers. + - uint32: 32-bit unsigned integers. + - int16: 16-bit two's complement signed integers. + - uint16: 16-bit unsigned integers. + - int8: 8-bit two's complement signed integers. + - uint8: 8-bit unsigned integers. + - uint8c: 8-bit unsigned integers clamped to 0-255. + - generic: generic JavaScript values. The default array data type is `float64`. diff --git a/lib/node_modules/@stdlib/array/reviver/docs/repl.txt b/lib/node_modules/@stdlib/array/reviver/docs/repl.txt index 96aaabf76b1..33cc8eac9cc 100644 --- a/lib/node_modules/@stdlib/array/reviver/docs/repl.txt +++ b/lib/node_modules/@stdlib/array/reviver/docs/repl.txt @@ -5,8 +5,8 @@ The serialization format for typed array is an object having the following fields: - - type: typed array type (e.g., "Float64Array", "Int8Array") - - data: typed array data as an array of numbers + - type: typed array type (e.g., "Float64Array", "Int8Array"). + - data: typed array data as an array of numbers. Parameters ---------- diff --git a/lib/node_modules/@stdlib/array/to-circular-iterator/docs/repl.txt b/lib/node_modules/@stdlib/array/to-circular-iterator/docs/repl.txt index 717b8d7b873..3de37f1a7de 100644 --- a/lib/node_modules/@stdlib/array/to-circular-iterator/docs/repl.txt +++ b/lib/node_modules/@stdlib/array/to-circular-iterator/docs/repl.txt @@ -5,10 +5,10 @@ When invoked, an input function is provided four arguments: - - value: iterated value - - index: iterated value index - - n: iteration count - - src: source array-like object + - value: iterated value. + - index: iterated value index. + - n: iteration count. + - src: source array-like object. If an environment supports Symbol.iterator, the returned iterator is iterable. diff --git a/lib/node_modules/@stdlib/array/to-iterator-right/docs/repl.txt b/lib/node_modules/@stdlib/array/to-iterator-right/docs/repl.txt index 203cce371f6..f16c0179100 100644 --- a/lib/node_modules/@stdlib/array/to-iterator-right/docs/repl.txt +++ b/lib/node_modules/@stdlib/array/to-iterator-right/docs/repl.txt @@ -5,9 +5,9 @@ When invoked, an input function is provided three arguments: - - value: iterated value - - index: iterated value index - - src: source array-like object + - value: iterated value. + - index: iterated value index. + - src: source array-like object. If an environment supports Symbol.iterator, the returned iterator is iterable. diff --git a/lib/node_modules/@stdlib/array/to-iterator/docs/repl.txt b/lib/node_modules/@stdlib/array/to-iterator/docs/repl.txt index cead6576ba7..a84a4d0d200 100644 --- a/lib/node_modules/@stdlib/array/to-iterator/docs/repl.txt +++ b/lib/node_modules/@stdlib/array/to-iterator/docs/repl.txt @@ -5,9 +5,9 @@ When invoked, an input function is provided three arguments: - - value: iterated value - - index: iterated value index - - src: source array-like object + - value: iterated value. + - index: iterated value index. + - src: source array-like object. If an environment supports Symbol.iterator, the returned iterator is iterable. diff --git a/lib/node_modules/@stdlib/array/to-json/docs/repl.txt b/lib/node_modules/@stdlib/array/to-json/docs/repl.txt index 704694f1c0a..27b1d6ec70f 100644 --- a/lib/node_modules/@stdlib/array/to-json/docs/repl.txt +++ b/lib/node_modules/@stdlib/array/to-json/docs/repl.txt @@ -19,8 +19,8 @@ The returned JSON object has the following properties: - - type: typed array type - - data: typed array data as a generic array + - type: typed array type. + - data: typed array data as a generic array. The implementation supports custom typed arrays and sets the `type` field to the closest known typed array type. diff --git a/lib/node_modules/@stdlib/array/to-sparse-iterator-right/docs/repl.txt b/lib/node_modules/@stdlib/array/to-sparse-iterator-right/docs/repl.txt index 567177dd40a..3e9002c14ee 100644 --- a/lib/node_modules/@stdlib/array/to-sparse-iterator-right/docs/repl.txt +++ b/lib/node_modules/@stdlib/array/to-sparse-iterator-right/docs/repl.txt @@ -7,9 +7,9 @@ When invoked, an input function is provided three arguments: - - value: iterated value - - index: iterated value index - - src: source array-like object + - value: iterated value. + - index: iterated value index. + - src: source array-like object. If an environment supports Symbol.iterator, the returned iterator is iterable. diff --git a/lib/node_modules/@stdlib/array/to-sparse-iterator/docs/repl.txt b/lib/node_modules/@stdlib/array/to-sparse-iterator/docs/repl.txt index e9febde03c1..0f3e77e3def 100644 --- a/lib/node_modules/@stdlib/array/to-sparse-iterator/docs/repl.txt +++ b/lib/node_modules/@stdlib/array/to-sparse-iterator/docs/repl.txt @@ -7,9 +7,9 @@ When invoked, an input function is provided three arguments: - - value: iterated value - - index: iterated value index - - src: source array-like object + - value: iterated value. + - index: iterated value index. + - src: source array-like object. If an environment supports Symbol.iterator, the returned iterator is iterable. diff --git a/lib/node_modules/@stdlib/array/to-strided-iterator/docs/repl.txt b/lib/node_modules/@stdlib/array/to-strided-iterator/docs/repl.txt index 8d3dc826663..bb9609cafb1 100644 --- a/lib/node_modules/@stdlib/array/to-strided-iterator/docs/repl.txt +++ b/lib/node_modules/@stdlib/array/to-strided-iterator/docs/repl.txt @@ -5,10 +5,10 @@ When invoked, an input function is provided four arguments: - - value: iterated value - - index: iterated value index - - n: iteration count (zero-based) - - src: source array-like object + - value: iterated value. + - index: iterated value index. + - n: iteration count (zero-based). + - src: source array-like object. If an environment supports Symbol.iterator, the returned iterator is iterable. diff --git a/lib/node_modules/@stdlib/array/to-view-iterator-right/docs/repl.txt b/lib/node_modules/@stdlib/array/to-view-iterator-right/docs/repl.txt index 1f909621b27..b6a5e3d43cd 100644 --- a/lib/node_modules/@stdlib/array/to-view-iterator-right/docs/repl.txt +++ b/lib/node_modules/@stdlib/array/to-view-iterator-right/docs/repl.txt @@ -5,10 +5,10 @@ When invoked, an input function is provided four arguments: - - value: iterated value - - index: iterated value index - - n: iteration count (zero-based) - - src: source array-like object + - value: iterated value. + - index: iterated value index. + - n: iteration count (zero-based). + - src: source array-like object. If an environment supports Symbol.iterator, the returned iterator is iterable. diff --git a/lib/node_modules/@stdlib/array/to-view-iterator/docs/repl.txt b/lib/node_modules/@stdlib/array/to-view-iterator/docs/repl.txt index 902971c3d29..8271875e7d2 100644 --- a/lib/node_modules/@stdlib/array/to-view-iterator/docs/repl.txt +++ b/lib/node_modules/@stdlib/array/to-view-iterator/docs/repl.txt @@ -5,10 +5,10 @@ When invoked, an input function is provided four arguments: - - value: iterated value - - index: iterated value index - - n: iteration count (zero-based) - - src: source array-like object + - value: iterated value. + - index: iterated value index. + - n: iteration count (zero-based). + - src: source array-like object. If an environment supports Symbol.iterator, the returned iterator is iterable. diff --git a/lib/node_modules/@stdlib/array/typed-complex/docs/repl.txt b/lib/node_modules/@stdlib/array/typed-complex/docs/repl.txt index 014eab17102..06edbe77847 100644 --- a/lib/node_modules/@stdlib/array/typed-complex/docs/repl.txt +++ b/lib/node_modules/@stdlib/array/typed-complex/docs/repl.txt @@ -4,8 +4,8 @@ The function supports the following data types: - - complex128: double-precision complex floating-point numbers - - complex64: single-precision complex floating-point numbers + - complex128: double-precision complex floating-point numbers. + - complex64: single-precision complex floating-point numbers. The default typed array data type is `complex128`. diff --git a/lib/node_modules/@stdlib/array/typed-real/docs/repl.txt b/lib/node_modules/@stdlib/array/typed-real/docs/repl.txt index 0a9881ffe7b..6c93288b4e3 100644 --- a/lib/node_modules/@stdlib/array/typed-real/docs/repl.txt +++ b/lib/node_modules/@stdlib/array/typed-real/docs/repl.txt @@ -4,15 +4,15 @@ The function supports the following data types: - - float64: double-precision floating-point numbers (IEEE 754) - - float32: single-precision floating-point numbers (IEEE 754) - - int32: 32-bit two's complement signed integers - - uint32: 32-bit unsigned integers - - int16: 16-bit two's complement signed integers - - uint16: 16-bit unsigned integers - - int8: 8-bit two's complement signed integers - - uint8: 8-bit unsigned integers - - uint8c: 8-bit unsigned integers clamped to 0-255 + - float64: double-precision floating-point numbers (IEEE 754). + - float32: single-precision floating-point numbers (IEEE 754). + - int32: 32-bit two's complement signed integers. + - uint32: 32-bit unsigned integers. + - int16: 16-bit two's complement signed integers. + - uint16: 16-bit unsigned integers. + - int8: 8-bit two's complement signed integers. + - uint8: 8-bit unsigned integers. + - uint8c: 8-bit unsigned integers clamped to 0-255. The default typed array data type is `float64`. diff --git a/lib/node_modules/@stdlib/array/zero-to-like/docs/repl.txt b/lib/node_modules/@stdlib/array/zero-to-like/docs/repl.txt index 4445fa7c879..6c86b632d72 100644 --- a/lib/node_modules/@stdlib/array/zero-to-like/docs/repl.txt +++ b/lib/node_modules/@stdlib/array/zero-to-like/docs/repl.txt @@ -6,18 +6,18 @@ The function supports the following data types: - - float64: double-precision floating-point numbers (IEEE 754) - - float32: single-precision floating-point numbers (IEEE 754) - - complex128: double-precision complex floating-point numbers - - complex64: single-precision complex floating-point numbers - - int32: 32-bit two's complement signed integers - - uint32: 32-bit unsigned integers - - int16: 16-bit two's complement signed integers - - uint16: 16-bit unsigned integers - - int8: 8-bit two's complement signed integers - - uint8: 8-bit unsigned integers - - uint8c: 8-bit unsigned integers clamped to 0-255 - - generic: generic JavaScript values + - float64: double-precision floating-point numbers (IEEE 754). + - float32: single-precision floating-point numbers (IEEE 754). + - complex128: double-precision complex floating-point numbers. + - complex64: single-precision complex floating-point numbers. + - int32: 32-bit two's complement signed integers. + - uint32: 32-bit unsigned integers. + - int16: 16-bit two's complement signed integers. + - uint16: 16-bit unsigned integers. + - int8: 8-bit two's complement signed integers. + - uint8: 8-bit unsigned integers. + - uint8c: 8-bit unsigned integers clamped to 0-255. + - generic: generic JavaScript values. Parameters ---------- diff --git a/lib/node_modules/@stdlib/array/zero-to/docs/repl.txt b/lib/node_modules/@stdlib/array/zero-to/docs/repl.txt index fda8e7b8351..fd2cae9db6c 100644 --- a/lib/node_modules/@stdlib/array/zero-to/docs/repl.txt +++ b/lib/node_modules/@stdlib/array/zero-to/docs/repl.txt @@ -5,18 +5,18 @@ The function supports the following data types: - - float64: double-precision floating-point numbers (IEEE 754) - - float32: single-precision floating-point numbers (IEEE 754) - - complex128: double-precision complex floating-point numbers - - complex64: single-precision complex floating-point numbers - - int32: 32-bit two's complement signed integers - - uint32: 32-bit unsigned integers - - int16: 16-bit two's complement signed integers - - uint16: 16-bit unsigned integers - - int8: 8-bit two's complement signed integers - - uint8: 8-bit unsigned integers - - uint8c: 8-bit unsigned integers clamped to 0-255 - - generic: generic JavaScript values + - float64: double-precision floating-point numbers (IEEE 754). + - float32: single-precision floating-point numbers (IEEE 754). + - complex128: double-precision complex floating-point numbers. + - complex64: single-precision complex floating-point numbers. + - int32: 32-bit two's complement signed integers. + - uint32: 32-bit unsigned integers. + - int16: 16-bit two's complement signed integers. + - uint16: 16-bit unsigned integers. + - int8: 8-bit two's complement signed integers. + - uint8: 8-bit unsigned integers. + - uint8c: 8-bit unsigned integers clamped to 0-255. + - generic: generic JavaScript values. The default array data type is `float64`. diff --git a/lib/node_modules/@stdlib/array/zeros-like/docs/repl.txt b/lib/node_modules/@stdlib/array/zeros-like/docs/repl.txt index 1655e1e87bb..4bb0bc0d52b 100644 --- a/lib/node_modules/@stdlib/array/zeros-like/docs/repl.txt +++ b/lib/node_modules/@stdlib/array/zeros-like/docs/repl.txt @@ -5,18 +5,18 @@ The function supports the following data types: - - float64: double-precision floating-point numbers (IEEE 754) - - float32: single-precision floating-point numbers (IEEE 754) - - complex128: double-precision complex floating-point numbers - - complex64: single-precision complex floating-point numbers - - int32: 32-bit two's complement signed integers - - uint32: 32-bit unsigned integers - - int16: 16-bit two's complement signed integers - - uint16: 16-bit unsigned integers - - int8: 8-bit two's complement signed integers - - uint8: 8-bit unsigned integers - - uint8c: 8-bit unsigned integers clamped to 0-255 - - generic: generic JavaScript values + - float64: double-precision floating-point numbers (IEEE 754). + - float32: single-precision floating-point numbers (IEEE 754). + - complex128: double-precision complex floating-point numbers. + - complex64: single-precision complex floating-point numbers. + - int32: 32-bit two's complement signed integers. + - uint32: 32-bit unsigned integers. + - int16: 16-bit two's complement signed integers. + - uint16: 16-bit unsigned integers. + - int8: 8-bit two's complement signed integers. + - uint8: 8-bit unsigned integers. + - uint8c: 8-bit unsigned integers clamped to 0-255. + - generic: generic JavaScript values. Parameters ---------- diff --git a/lib/node_modules/@stdlib/array/zeros/docs/repl.txt b/lib/node_modules/@stdlib/array/zeros/docs/repl.txt index 4e88eb65793..6a593202a43 100644 --- a/lib/node_modules/@stdlib/array/zeros/docs/repl.txt +++ b/lib/node_modules/@stdlib/array/zeros/docs/repl.txt @@ -4,18 +4,18 @@ The function supports the following data types: - - float64: double-precision floating-point numbers (IEEE 754) - - float32: single-precision floating-point numbers (IEEE 754) - - complex128: double-precision complex floating-point numbers - - complex64: single-precision complex floating-point numbers - - int32: 32-bit two's complement signed integers - - uint32: 32-bit unsigned integers - - int16: 16-bit two's complement signed integers - - uint16: 16-bit unsigned integers - - int8: 8-bit two's complement signed integers - - uint8: 8-bit unsigned integers - - uint8c: 8-bit unsigned integers clamped to 0-255 - - generic: generic JavaScript values + - float64: double-precision floating-point numbers (IEEE 754). + - float32: single-precision floating-point numbers (IEEE 754). + - complex128: double-precision complex floating-point numbers. + - complex64: single-precision complex floating-point numbers. + - int32: 32-bit two's complement signed integers. + - uint32: 32-bit unsigned integers. + - int16: 16-bit two's complement signed integers. + - uint16: 16-bit unsigned integers. + - int8: 8-bit two's complement signed integers. + - uint8: 8-bit unsigned integers. + - uint8c: 8-bit unsigned integers clamped to 0-255. + - generic: generic JavaScript values. The default array data type is `float64`. diff --git a/lib/node_modules/@stdlib/assert/has-sharedarraybuffer-support/test/test.js b/lib/node_modules/@stdlib/assert/has-sharedarraybuffer-support/test/test.js index a728145deff..5e06094a135 100644 --- a/lib/node_modules/@stdlib/assert/has-sharedarraybuffer-support/test/test.js +++ b/lib/node_modules/@stdlib/assert/has-sharedarraybuffer-support/test/test.js @@ -30,6 +30,13 @@ var detect = require( './../lib' ); var hasSharedArrayBuffer = ( typeof SharedArrayBuffer === 'function' ); // eslint-disable-line stdlib/require-globals +// FUNCTIONS // + +function isBufferMock() { + return true; +} + + // TESTS // tape( 'main export is a function', function test( t ) { @@ -78,15 +85,11 @@ tape( 'if `SharedArrayBuffer` is supported, detection result is `true`', functio mocked = proxyquire( './../lib/main.js', { './sharedarraybuffer.js': Mock, - '@stdlib/assert/is-sharedarraybuffer': isBuffer + '@stdlib/assert/is-sharedarraybuffer': isBufferMock }); t.strictEqual( mocked(), true, 'detection result is `true` (mocked)' ); t.end(); - - function isBuffer() { - return true; - } }); tape( 'if `SharedArrayBuffer` is not supported, detection result is `false` (no SharedArrayBuffer global function)', function test( t ) { @@ -141,14 +144,10 @@ tape( 'if `SharedArrayBuffer` is not supported, detected result is `false` (no s } mocked = proxyquire( './../lib/main.js', { './sharedarraybuffer.js': Mock, - '@stdlib/assert/is-sharedarraybuffer': isBuffer + '@stdlib/assert/is-sharedarraybuffer': isBufferMock }); t.strictEqual( mocked(), false, 'detection result is `false`' ); t.end(); - - function isBuffer() { - return true; - } }); tape( 'if `SharedArrayBuffer` is not supported, detected result is `false` (no byteLength property)', function test( t ) { @@ -183,12 +182,8 @@ tape( 'if `SharedArrayBuffer` is not supported, detected result is `false` (no b } mocked = proxyquire( './../lib/main.js', { './sharedarraybuffer.js': Mock, - '@stdlib/assert/is-sharedarraybuffer': isBuffer + '@stdlib/assert/is-sharedarraybuffer': isBufferMock }); t.strictEqual( mocked(), false, 'detection result is `false`' ); t.end(); - - function isBuffer() { - return true; - } }); diff --git a/lib/node_modules/@stdlib/assert/is-duration-string/docs/repl.txt b/lib/node_modules/@stdlib/assert/is-duration-string/docs/repl.txt index 14183a9368e..56266b319ca 100644 --- a/lib/node_modules/@stdlib/assert/is-duration-string/docs/repl.txt +++ b/lib/node_modules/@stdlib/assert/is-duration-string/docs/repl.txt @@ -9,11 +9,11 @@ unit is a non-negative integer followed by a unit identifier. The following unit identifiers are supported: - - `d`: days - - `h`: hours - - `m`: minutes - - `s`: seconds - - `ms`: milliseconds + - d: days. + - h: hours. + - m: minutes. + - s: seconds. + - ms: milliseconds. For example, the string `1m3s10ms` is a duration string containing three time units: `1m` (1 minute), `3s` (3 seconds), and `10ms` (10 milliseconds). diff --git a/lib/node_modules/@stdlib/assert/is-ndarray-like-with-data-type/README.md b/lib/node_modules/@stdlib/assert/is-ndarray-like-with-data-type/README.md new file mode 100644 index 00000000000..60e93a6aaa9 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-ndarray-like-with-data-type/README.md @@ -0,0 +1,95 @@ + + +# isndarrayLikeWithDataType + +> Test if a value is an [ndarray-like object][@stdlib/assert/is-ndarray-like] having a specified [data type][@stdlib/ndarray/dtypes]. + +
+ +## Usage + +```javascript +var isndarrayLikeWithDataType = require( '@stdlib/assert/is-ndarray-like-with-data-type' ); +``` + +#### isndarrayLikeWithDataType( value, dtype ) + +Tests if a value is an [ndarray-like object][@stdlib/assert/is-ndarray-like] having a specified [data type][@stdlib/ndarray/dtypes]. + +```javascript +var ndarray = require( '@stdlib/ndarray/ctor' ); + +var arr = ndarray( 'generic', [ 0, 0, 0, 0 ], [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); +var bool = isndarrayLikeWithDataType( arr, 'generic' ); +// returns true +``` + +
+ + + +
+ +## Examples + + + +```javascript +var ndarray = require( '@stdlib/ndarray/ctor' ); +var isndarrayLikeWithDataType = require( '@stdlib/assert/is-ndarray-like-with-data-type' ); + +var arr = ndarray( 'generic', [ 0, 0, 0, 0 ], [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); +var bool = isndarrayLikeWithDataType( arr, 'generic' ); +// returns true + +bool = isndarrayLikeWithDataType( [ 1, 2, 3, 4 ], 'generic' ); +// returns false + +bool = isndarrayLikeWithDataType( {}, 'generic' ); +// returns false + +bool = isndarrayLikeWithDataType( null, 'generic' ); +// returns false +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/assert/is-ndarray-like-with-data-type/benchmark/benchmark.js b/lib/node_modules/@stdlib/assert/is-ndarray-like-with-data-type/benchmark/benchmark.js new file mode 100644 index 00000000000..e3f9fad2b55 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-ndarray-like-with-data-type/benchmark/benchmark.js @@ -0,0 +1,146 @@ +/** +* @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 isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; +var ndarray = require( '@stdlib/ndarray/ctor' ); +var noop = require( '@stdlib/utils/noop' ); +var pkg = require( './../package.json' ).name; +var isndarrayLikeWithDataType = require( './../lib' ); + + +// MAIN // + +bench( pkg+'::true,ndarray', function benchmark( b ) { + var strides; + var offset; + var buffer; + var values; + var shape; + var order; + var bool; + var arr; + var i; + + buffer = [ 0, 0, 0, 0 ]; + shape = [ 2, 2 ]; + strides = [ 2, 1 ]; + offset = 0; + order = 'row-major'; + + arr = ndarray( 'generic', buffer, shape, strides, offset, order ); + + values = [ + arr, + arr, + arr, + arr, + arr + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + bool = isndarrayLikeWithDataType( values[ i%values.length ], 'generic' ); + 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+'::true,ndarray_like', function benchmark( b ) { + var values; + var bool; + var arr; + var i; + + arr = { + 'data': [ 0, 0, 0, 0 ], + 'shape': [ 2, 2 ], + 'strides': [ 2, 1 ], + 'offset': 0, + 'order': 'row-major', + 'ndims': 2, + 'dtype': 'generic', + 'length': 4, + 'flags': {}, + 'get': noop, + 'set': noop + }; + + values = [ + arr, + arr, + arr, + arr, + arr + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + bool = isndarrayLikeWithDataType( values[ i%values.length ], 'generic' ); + 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', function benchmark( b ) { + var values; + var bool; + var i; + + values = [ + 5, + 'beep', + true, + false, + null, + [ 1, 2, 3 ], + {} + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + bool = isndarrayLikeWithDataType( values[ i%values.length ], 'generic' ); + 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(); +}); diff --git a/lib/node_modules/@stdlib/assert/is-ndarray-like-with-data-type/docs/repl.txt b/lib/node_modules/@stdlib/assert/is-ndarray-like-with-data-type/docs/repl.txt new file mode 100644 index 00000000000..ca8eb4f32f2 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-ndarray-like-with-data-type/docs/repl.txt @@ -0,0 +1,44 @@ + +{{alias}}( value, dtype ) + Tests if a value is an ndarray-like object having a specified data type. + + Parameters + ---------- + value: any + Value to test. + + dtype: any + Data type value. + + Returns + ------- + bool: boolean + Boolean indicating whether a value is an ndarray-like object having a + specified data type. + + Examples + -------- + > var M = {}; + > M.data = [ 0, 0, 0, 0 ]; + > M.ndims = 2; + > M.shape = [ 2, 2 ]; + > M.strides = [ 2, 1 ]; + > M.offset = 0; + > M.order = 'row-major'; + > M.dtype = 'generic'; + > M.length = 4; + > M.flags = {}; + > M.get = function get( i, j ) {}; + > M.set = function set( i, j ) {}; + > var bool = {{alias}}( M, 'generic' ) + true + > bool = {{alias}}( [ 1, 2, 3, 4 ], 'generic' ) + false + > bool = {{alias}}( 3.14, 'generic' ) + false + > bool = {{alias}}( {}, 'generic' ) + false + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/assert/is-ndarray-like-with-data-type/docs/types/index.d.ts b/lib/node_modules/@stdlib/assert/is-ndarray-like-with-data-type/docs/types/index.d.ts new file mode 100644 index 00000000000..c0e104a319c --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-ndarray-like-with-data-type/docs/types/index.d.ts @@ -0,0 +1,44 @@ +/* +* @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 + +/** +* Tests if a value is an ndarray-like object having a specified data type. +* +* @param v - value to test +* @param dtype - data type +* @returns boolean indicating if a value is an ndarray-like object having a specified data type +* +* @example +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* +* var arr = ndarray( 'generic', [ 0, 0, 0, 0 ], [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); +* +* var bool = isndarrayLikeWithDataType( arr, 'generic' ); +* // returns true +* +* bool = isndarrayLikeWithDataType( [], 'generic' ); +* // returns false +*/ +declare function isndarrayLikeWithDataType( v: any, dtype: any ): boolean; + + +// EXPORTS // + +export = isndarrayLikeWithDataType; diff --git a/lib/node_modules/@stdlib/assert/is-ndarray-like-with-data-type/docs/types/test.ts b/lib/node_modules/@stdlib/assert/is-ndarray-like-with-data-type/docs/types/test.ts new file mode 100644 index 00000000000..09f997e057f --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-ndarray-like-with-data-type/docs/types/test.ts @@ -0,0 +1,58 @@ +/* +* @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. +*/ + +/* eslint-disable @typescript-eslint/no-invalid-this */ + +import isndarrayLikeWithDataType = require( './index' ); + + +// TESTS // + +// The function returns a boolean... +{ + const ndarray = { + 'data': [ 2, 1, 1, 2 ], + 'ndims': 2, + 'shape': [ 2, 2 ], + 'strides': [ 2, 1 ], + 'offset': 0, + 'order': 'row-major', + 'dtype': 'generic', + 'length': 4, + 'flags': {}, + 'get': function get( i: number, j: number ): number { + const idx = ( this.strides[ 0 ] * i ) + ( this.strides[ 1 ] * j ); + return this.data[ idx ]; + }, + 'set': function set( i: number, j: number, v: number ): number { + const idx = ( this.strides[ 0 ] * i ) + ( this.strides[ 1 ] * j ); + this.data[ idx ] = v; + return v; + } + }; + isndarrayLikeWithDataType( ndarray, 'generic' ); // $ExpectType boolean + isndarrayLikeWithDataType( [], 'generic' ); // $ExpectType boolean + isndarrayLikeWithDataType( false, 'generic' ); // $ExpectType boolean +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + isndarrayLikeWithDataType(); // $ExpectError + isndarrayLikeWithDataType( null ); // $ExpectError + isndarrayLikeWithDataType( null, 'generic', {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/assert/is-ndarray-like-with-data-type/examples/index.js b/lib/node_modules/@stdlib/assert/is-ndarray-like-with-data-type/examples/index.js new file mode 100644 index 00000000000..e64d698ff8f --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-ndarray-like-with-data-type/examples/index.js @@ -0,0 +1,36 @@ +/** +* @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 ndarray = require( '@stdlib/ndarray/ctor' ); +var isndarrayLikeWithDataType = require( './../lib' ); + +var arr = ndarray( 'generic', [ 0, 0, 0, 0 ], [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + +console.log( isndarrayLikeWithDataType( arr, 'generic' ) ); +// => true + +console.log( isndarrayLikeWithDataType( [ 1, 2, 3, 4 ], 'generic' ) ); +// => false + +console.log( isndarrayLikeWithDataType( {}, 'generic' ) ); +// => false + +console.log( isndarrayLikeWithDataType( null, 'generic' ) ); +// => false diff --git a/lib/node_modules/@stdlib/assert/is-ndarray-like-with-data-type/lib/index.js b/lib/node_modules/@stdlib/assert/is-ndarray-like-with-data-type/lib/index.js new file mode 100644 index 00000000000..75c3fd9fe18 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-ndarray-like-with-data-type/lib/index.js @@ -0,0 +1,45 @@ +/** +* @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'; + +/** +* Test if a value is an ndarray-like object having a specified data type. +* +* @module @stdlib/assert/is-ndarray-like-with-data-type +* +* @example +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var isndarrayLikeWithDataType = require( '@stdlib/assert/is-ndarray-like-with-data-type' ); +* +* var arr = ndarray( 'generic', [ 0, 0, 0, 0 ], [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); +* var bool = isndarrayLikeWithDataType( arr, 'generic' ); +* // returns true +* +* bool = isndarrayLikeWithDataType( [], 'generic' ); +* // returns false +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/assert/is-ndarray-like-with-data-type/lib/main.js b/lib/node_modules/@stdlib/assert/is-ndarray-like-with-data-type/lib/main.js new file mode 100644 index 00000000000..2a9d25817ce --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-ndarray-like-with-data-type/lib/main.js @@ -0,0 +1,54 @@ +/** +* @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 isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var getDType = require( '@stdlib/ndarray/base/dtype' ); + + +// MAIN // + +/** +* Tests if a value is an ndarray-like object having a specified data type. +* +* @param {*} v - value to test +* @param {*} dtype - data type +* @returns {boolean} boolean indicating if a value is an ndarray-lik object having a specified data typee +* +* @example +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* +* var arr = ndarray( 'generic', [ 0, 0, 0, 0 ], [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); +* +* var bool = isndarrayLikeWithDataType( arr, 'generic' ); +* // returns true +* +* bool = isndarrayLikeWithDataType( [], 'generic' ); +* // returns false +*/ +function isndarrayLikeWithDataType( v, dtype ) { + return ( isndarrayLike( v ) && getDType( v ) === dtype ); +} + + +// EXPORTS // + +module.exports = isndarrayLikeWithDataType; diff --git a/lib/node_modules/@stdlib/assert/is-ndarray-like-with-data-type/package.json b/lib/node_modules/@stdlib/assert/is-ndarray-like-with-data-type/package.json new file mode 100644 index 00000000000..1de9d85c6db --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-ndarray-like-with-data-type/package.json @@ -0,0 +1,70 @@ +{ + "name": "@stdlib/assert/is-ndarray-like-with-data-type", + "version": "0.0.0", + "description": "Test if a value is an ndarray-like object having a specified data type.", + "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", + "stdassert", + "assertion", + "assert", + "utilities", + "utility", + "utils", + "util", + "is", + "isndarray", + "ndarray", + "ndarray-like", + "validate", + "isvalid", + "test", + "type", + "check" + ] +} diff --git a/lib/node_modules/@stdlib/assert/is-ndarray-like-with-data-type/test/test.js b/lib/node_modules/@stdlib/assert/is-ndarray-like-with-data-type/test/test.js new file mode 100644 index 00000000000..bc151a39cdb --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-ndarray-like-with-data-type/test/test.js @@ -0,0 +1,106 @@ +/** +* @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 ndarray = require( '@stdlib/ndarray/ctor' ); +var noop = require( '@stdlib/utils/noop' ); +var isndarrayLikeWithDataType = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof isndarrayLikeWithDataType, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns `true` if provided an ndarray having a specified data type', function test( t ) { + var arr = ndarray( 'generic', [ 0, 0, 0, 0 ], [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + t.equal( isndarrayLikeWithDataType( arr, 'generic' ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns `true` if provided an ndarray-like object having a specified data type', function test( t ) { + var arr; + + arr = { + 'data': [ 0, 0, 0, 0 ], + 'shape': [ 2, 2 ], + 'strides': [ 2, 1 ], + 'offset': 0, + 'order': 'row-major', + 'ndims': 2, + 'dtype': 'generic', + 'length': 4, + 'flags': {}, + 'get': noop, + 'set': noop + }; + + t.equal( isndarrayLikeWithDataType( arr, 'generic' ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns `false` if provided an ndarray-like object not having a specified data type', function test( t ) { + var arr; + + arr = { + 'data': [ 0, 0, 0, 0 ], + 'shape': [ 2, 2 ], + 'strides': [ 2, 1 ], + 'offset': 0, + 'order': 'row-major', + 'ndims': 2, + 'dtype': 'generic', + 'length': 4, + 'flags': {}, + 'get': noop, + 'set': noop + }; + + t.equal( isndarrayLikeWithDataType( arr, 'foobar' ), false, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns `false` if not provided an ndarray-like object', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + null, + void 0, + true, + false, + [], + {}, + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.equal( isndarrayLikeWithDataType( values[i] ), false, 'returns expected value when provided '+values[i] ); + } + t.end(); +}); diff --git a/lib/node_modules/@stdlib/assert/is-nonnegative-finite/lib/object.js b/lib/node_modules/@stdlib/assert/is-nonnegative-finite/lib/object.js index f2248b62286..5e8cb360168 100644 --- a/lib/node_modules/@stdlib/assert/is-nonnegative-finite/lib/object.js +++ b/lib/node_modules/@stdlib/assert/is-nonnegative-finite/lib/object.js @@ -20,7 +20,7 @@ // MODULES // -var isNonNegativeNumber = require( '@stdlib/assert/is-nonnegative-number').isObject; +var isNonNegativeNumber = require( '@stdlib/assert/is-nonnegative-number' ).isObject; var PINF = require( '@stdlib/constants/float64/pinf' ); diff --git a/lib/node_modules/@stdlib/assert/lib/index.js b/lib/node_modules/@stdlib/assert/lib/index.js index b8841509640..30f116c28f6 100644 --- a/lib/node_modules/@stdlib/assert/lib/index.js +++ b/lib/node_modules/@stdlib/assert/lib/index.js @@ -1584,6 +1584,15 @@ setReadOnly( ns, 'isNativeFunction', require( '@stdlib/assert/is-native-function */ setReadOnly( ns, 'isndarrayLike', require( '@stdlib/assert/is-ndarray-like' ) ); +/** +* @name isndarrayLikeWithDataType +* @memberof ns +* @readonly +* @type {Function} +* @see {@link module:@stdlib/assert/is-ndarray-like-with-data-type} +*/ +setReadOnly( ns, 'isndarrayLikeWithDataType', require( '@stdlib/assert/is-ndarray-like-with-data-type' ) ); + /** * @name isNegativeInteger * @memberof ns diff --git a/lib/node_modules/@stdlib/blas/base/caxpy/lib/caxpy.js b/lib/node_modules/@stdlib/blas/base/caxpy/lib/caxpy.js index 99209915375..6af42c15a13 100644 --- a/lib/node_modules/@stdlib/blas/base/caxpy/lib/caxpy.js +++ b/lib/node_modules/@stdlib/blas/base/caxpy/lib/caxpy.js @@ -20,8 +20,8 @@ // MODULES // -var stride2offset = require('@stdlib/strided/base/stride2offset'); -var ndarray = require('./ndarray.js'); +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require( './ndarray.js' ); // MAIN // diff --git a/lib/node_modules/@stdlib/blas/base/dasum/README.md b/lib/node_modules/@stdlib/blas/base/dasum/README.md index 880c68d12d2..985daee9720 100644 --- a/lib/node_modules/@stdlib/blas/base/dasum/README.md +++ b/lib/node_modules/@stdlib/blas/base/dasum/README.md @@ -97,7 +97,7 @@ var sum = dasum( 3, x1, 2 ); // returns 12.0 ``` -If either `N` or `stride` is less than or equal to `0`, the function returns `0`. +If `N` is less than or equal to `0`, the function returns `0`. #### dasum.ndarray( N, x, stride, offset ) @@ -217,6 +217,28 @@ The function accepts the following arguments: double c_dasum( const CBLAS_INT N, const double *X, const CBLAS_INT stride ); ``` +#### c_dasum_ndarray( N, \*X, stride, offset ) + +Computes the sum of absolute values using alternative indexing semantics. + +```c +const double x[] = { 1.0, 2.0, 3.0, 4.0 }; + +double v = c_dasum_ndarray( 4, x, -1, 3 ); +// returns 10.0 +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **X**: `[in] double*` input array. +- **stride**: `[in] CBLAS_INT` index increment for `X`. +- **offset**: `[in] CBLAS_INT` starting index for `X`. + +```c +double c_dasum_ndarray( const CBLAS_INT N, const double *X, const CBLAS_INT stride, const CBLAS_INT offset ); +``` + @@ -254,6 +276,12 @@ int main( void ) { // Print the result: printf( "sum: %lf\n", sum ); + + // Compute the sum of absolute values: + sum = c_dasum_ndarray( N, x, -strideX, N-1 ); + + // Print the result: + printf( "sum: %lf\n", sum ); } ``` diff --git a/lib/node_modules/@stdlib/blas/base/dasum/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/blas/base/dasum/benchmark/c/benchmark.length.c index 4bf10dbcd96..ec801fd3c08 100644 --- a/lib/node_modules/@stdlib/blas/base/dasum/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/blas/base/dasum/benchmark/c/benchmark.length.c @@ -94,7 +94,7 @@ static double rand_double( void ) { * @param len array length * @return elapsed time in seconds */ -static double benchmark( int iterations, int len ) { +static double benchmark1( int iterations, int len ) { double elapsed; double x[ len ]; double y; @@ -120,6 +120,39 @@ static double benchmark( int iterations, int len ) { return elapsed; } +/** +* Runs a benchmark. +* +* @param iterations number of iterations +* @param len array length +* @return elapsed time in seconds +*/ +static double benchmark2( int iterations, int len ) { + double elapsed; + double x[ len ]; + double y; + double t; + int i; + + for ( i = 0; i < len; i++ ) { + x[ i ] = ( rand_double()*20000.0 ) - 10000.0; + } + y = 0.0; + t = tic(); + for ( i = 0; i < iterations; i++ ) { + y = c_dasum_ndarray( len, x, 1, 0 ); + if ( y != y ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( y != y ) { + printf( "should not return NaN\n" ); + } + return elapsed; +} + /** * Main execution sequence. */ @@ -142,7 +175,14 @@ int main( void ) { for ( j = 0; j < REPEATS; j++ ) { count += 1; printf( "# c::%s:len=%d\n", NAME, len ); - elapsed = benchmark( iter, len ); + elapsed = benchmark1( iter, len ); + print_results( iter, elapsed ); + printf( "ok %d benchmark finished\n", count ); + } + for ( j = 0; j < REPEATS; j++ ) { + count += 1; + printf( "# c::%s:ndarray:len=%d\n", NAME, len ); + elapsed = benchmark2( iter, len ); print_results( iter, elapsed ); printf( "ok %d benchmark finished\n", count ); } diff --git a/lib/node_modules/@stdlib/blas/base/dasum/docs/repl.txt b/lib/node_modules/@stdlib/blas/base/dasum/docs/repl.txt index 7074e9518cb..a1dc7b88932 100644 --- a/lib/node_modules/@stdlib/blas/base/dasum/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/base/dasum/docs/repl.txt @@ -10,7 +10,7 @@ Indexing is relative to the first index. To introduce an offset, use typed array views. - If `N` or `stride` is less than or equal to `0`, the function returns `0`. + If `N` is less than or equal to `0`, the function returns `0`. Parameters ---------- diff --git a/lib/node_modules/@stdlib/blas/base/dasum/examples/c/example.c b/lib/node_modules/@stdlib/blas/base/dasum/examples/c/example.c index 490764e3238..07ea8282b63 100644 --- a/lib/node_modules/@stdlib/blas/base/dasum/examples/c/example.c +++ b/lib/node_modules/@stdlib/blas/base/dasum/examples/c/example.c @@ -34,4 +34,10 @@ int main( void ) { // Print the result: printf( "sum: %lf\n", sum ); + + // Compute the sum of absolute values: + sum = c_dasum_ndarray( N, x, -strideX, N-1 ); + + // Print the result: + printf( "sum: %lf\n", sum ); } diff --git a/lib/node_modules/@stdlib/blas/base/dasum/include/stdlib/blas/base/dasum.h b/lib/node_modules/@stdlib/blas/base/dasum/include/stdlib/blas/base/dasum.h index 861d6009527..edb2a7cd520 100644 --- a/lib/node_modules/@stdlib/blas/base/dasum/include/stdlib/blas/base/dasum.h +++ b/lib/node_modules/@stdlib/blas/base/dasum/include/stdlib/blas/base/dasum.h @@ -36,6 +36,11 @@ extern "C" { */ double API_SUFFIX(c_dasum)( const CBLAS_INT N, const double *X, const CBLAS_INT stride ); +/** +* Computes the sum of absolute values using alternative indexing semantics. +*/ +double API_SUFFIX(c_dasum_ndarray)( const CBLAS_INT N, const double *X, const CBLAS_INT stride, const CBLAS_INT offset ); + #ifdef __cplusplus } #endif diff --git a/lib/node_modules/@stdlib/blas/base/dasum/lib/dasum.js b/lib/node_modules/@stdlib/blas/base/dasum/lib/dasum.js index 3cc1e021e5f..767201cbf6e 100644 --- a/lib/node_modules/@stdlib/blas/base/dasum/lib/dasum.js +++ b/lib/node_modules/@stdlib/blas/base/dasum/lib/dasum.js @@ -20,12 +20,8 @@ // MODULES // -var abs = require( '@stdlib/math/base/special/abs' ); - - -// VARIABLES // - -var M = 6; +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require( './ndarray.js' ); // MAIN // @@ -35,7 +31,7 @@ var M = 6; * * @param {PositiveInteger} N - number of indexed elements * @param {Float64Array} x - input array -* @param {PositiveInteger} stride - `x` stride length +* @param {integer} stride - `x` stride length * @returns {number} sum * * @example @@ -47,37 +43,8 @@ var M = 6; * // returns 15.0 */ function dasum( N, x, stride ) { - var sum; - var m; - var i; - - sum = 0.0; - if ( N <= 0 || stride <= 0 ) { - return sum; - } - // Use unrolled loops if the stride is equal to `1`... - if ( stride === 1 ) { - m = N % M; - - // If we have a remainder, run a clean-up loop... - if ( m > 0 ) { - for ( i = 0; i < m; i++ ) { - sum += abs( x[i] ); - } - } - if ( N < M ) { - return sum; - } - for ( i = m; i < N; i += M ) { - sum += abs(x[i]) + abs(x[i+1]) + abs(x[i+2]) + abs(x[i+3]) + abs(x[i+4]) + abs(x[i+5]); // eslint-disable-line max-len - } - return sum; - } - N *= stride; - for ( i = 0; i < N; i += stride ) { - sum += abs( x[i] ); - } - return sum; + var ox = stride2offset( N, stride ); + return ndarray( N, x, stride, ox ); } diff --git a/lib/node_modules/@stdlib/blas/base/dasum/lib/dasum.native.js b/lib/node_modules/@stdlib/blas/base/dasum/lib/dasum.native.js index 20e82391cfa..5931c4422fb 100644 --- a/lib/node_modules/@stdlib/blas/base/dasum/lib/dasum.native.js +++ b/lib/node_modules/@stdlib/blas/base/dasum/lib/dasum.native.js @@ -30,7 +30,7 @@ var addon = require( './../src/addon.node' ); * * @param {PositiveInteger} N - number of indexed elements * @param {Float64Array} x - input array -* @param {PositiveInteger} stride - `x` stride length +* @param {integer} stride - `x` stride length * @returns {number} sum * * @example diff --git a/lib/node_modules/@stdlib/blas/base/dasum/lib/ndarray.js b/lib/node_modules/@stdlib/blas/base/dasum/lib/ndarray.js index 3f5673049d6..412705ce062 100644 --- a/lib/node_modules/@stdlib/blas/base/dasum/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/dasum/lib/ndarray.js @@ -23,11 +23,6 @@ var abs = require( '@stdlib/math/base/special/abs' ); -// VARIABLES // - -var M = 6; - - // MAIN // /** @@ -36,7 +31,7 @@ var M = 6; * @param {PositiveInteger} N - number of indexed elements * @param {Float64Array} x - input array * @param {integer} stride - `x` stride length -* @param {NonNegativeInteger} offset - starting `x` index +* @param {NonNegativeInteger} offset - starting index for `x` * @returns {number} sum * * @example @@ -50,7 +45,6 @@ var M = 6; function dasum( N, x, stride, offset ) { var sum; var ix; - var m; var i; sum = 0.0; @@ -58,27 +52,6 @@ function dasum( N, x, stride, offset ) { return sum; } ix = offset; - - // Use unrolled loops if the stride is equal to `1`... - if ( stride === 1 ) { - m = N % M; - - // If we have a remainder, run a clean-up loop... - if ( m > 0 ) { - for ( i = 0; i < m; i++ ) { - sum += abs( x[ix] ); - ix += stride; - } - } - if ( N < M ) { - return sum; - } - for ( i = m; i < N; i += M ) { - sum += abs( x[ix] ) + abs( x[ix+1] ) + abs( x[ix+2] ) + abs( x[ix+3] ) + abs( x[ix+4] ) + abs( x[ix+5] ); // eslint-disable-line max-len - ix += M; - } - return sum; - } for ( i = 0; i < N; i++ ) { sum += abs( x[ix] ); ix += stride; diff --git a/lib/node_modules/@stdlib/blas/base/dasum/lib/ndarray.native.js b/lib/node_modules/@stdlib/blas/base/dasum/lib/ndarray.native.js index 316d91ecd2d..5a2fc11742e 100644 --- a/lib/node_modules/@stdlib/blas/base/dasum/lib/ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/base/dasum/lib/ndarray.native.js @@ -20,9 +20,7 @@ // MODULES // -var minViewBufferIndex = require( '@stdlib/strided/base/min-view-buffer-index' ); -var offsetView = require( '@stdlib/strided/base/offset-view' ); -var addon = require( './dasum.native.js' ); +var addon = require( './../src/addon.node' ); // MAIN // @@ -33,7 +31,7 @@ var addon = require( './dasum.native.js' ); * @param {PositiveInteger} N - number of indexed elements * @param {Float64Array} x - input array * @param {integer} stride - `x` stride length -* @param {NonNegativeInteger} offset - starting `x` index +* @param {NonNegativeInteger} offset - starting index for `x` * @returns {number} sum * * @example @@ -45,13 +43,7 @@ var addon = require( './dasum.native.js' ); * // returns 15.0 */ function dasum( N, x, stride, offset ) { - var view; - offset = minViewBufferIndex( N, stride, offset ); - if ( stride < 0 ) { - stride *= -1; - } - view = offsetView( x, offset ); - return addon( N, view, stride ); + return addon.ndarray( N, x, stride, offset ); } diff --git a/lib/node_modules/@stdlib/blas/base/dasum/manifest.json b/lib/node_modules/@stdlib/blas/base/dasum/manifest.json index d3bb868c81e..981fd587d2d 100644 --- a/lib/node_modules/@stdlib/blas/base/dasum/manifest.json +++ b/lib/node_modules/@stdlib/blas/base/dasum/manifest.json @@ -45,6 +45,7 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/napi/export", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", @@ -58,15 +59,19 @@ "blas": "", "wasm": false, "src": [ - "./src/dasum.c" + "./src/dasum.c", + "./src/dasum_ndarray.c" ], "include": [ "./include" ], - "libraries": [], + "libraries": [ + "-lm" + ], "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset", "@stdlib/math/base/special/abs" ] }, @@ -76,15 +81,19 @@ "blas": "", "wasm": false, "src": [ - "./src/dasum.c" + "./src/dasum.c", + "./src/dasum_ndarray.c" ], "include": [ "./include" ], - "libraries": [], + "libraries": [ + "-lm" + ], "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset", "@stdlib/math/base/special/abs" ] }, @@ -107,6 +116,7 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/napi/export", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", @@ -131,7 +141,8 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index" ] }, { @@ -151,7 +162,8 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index" ] }, @@ -172,6 +184,7 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/napi/export", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", @@ -185,15 +198,19 @@ "blas": "", "wasm": false, "src": [ - "./src/dasum.c" + "./src/dasum.c", + "./src/dasum_ndarray.c" ], "include": [ "./include" ], - "libraries": [], + "libraries": [ + "-lm" + ], "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset", "@stdlib/math/base/special/abs" ] }, @@ -203,15 +220,19 @@ "blas": "", "wasm": false, "src": [ - "./src/dasum.c" + "./src/dasum.c", + "./src/dasum_ndarray.c" ], "include": [ "./include" ], - "libraries": [], + "libraries": [ + "-lm" + ], "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset", "@stdlib/math/base/special/abs" ] }, @@ -233,6 +254,7 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/napi/export", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", @@ -256,7 +278,8 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index" ] }, { @@ -275,7 +298,8 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index" ] }, @@ -297,6 +321,7 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/napi/export", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", @@ -321,7 +346,8 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index" ] }, { @@ -342,7 +368,7 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", - "@stdlib/math/base/special/abs" + "@stdlib/strided/base/min-view-buffer-index" ] }, @@ -352,21 +378,25 @@ "blas": "", "wasm": false, "src": [ - "./src/dasum.c" + "./src/dasum.c", + "./src/dasum_ndarray.c" ], "include": [ "./include" ], - "libraries": [], + "libraries": [ + "-lm" + ], "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset", + "@stdlib/math/base/special/abs", "@stdlib/napi/export", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", "@stdlib/napi/argv-strided-float64array", - "@stdlib/napi/create-double", - "@stdlib/math/base/special/abs" + "@stdlib/napi/create-double" ] }, { @@ -375,15 +405,19 @@ "blas": "", "wasm": false, "src": [ - "./src/dasum.c" + "./src/dasum.c", + "./src/dasum_ndarray.c" ], "include": [ "./include" ], - "libraries": [], + "libraries": [ + "-lm" + ], "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset", "@stdlib/math/base/special/abs" ] }, @@ -393,15 +427,19 @@ "blas": "", "wasm": false, "src": [ - "./src/dasum.c" + "./src/dasum.c", + "./src/dasum_ndarray.c" ], "include": [ "./include" ], - "libraries": [], + "libraries": [ + "-lm" + ], "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset", "@stdlib/math/base/special/abs" ] }, @@ -412,15 +450,19 @@ "blas": "", "wasm": true, "src": [ - "./src/dasum.c" + "./src/dasum.c", + "./src/dasum_ndarray.c" ], "include": [ "./include" ], - "libraries": [], + "libraries": [ + "-lm" + ], "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset", "@stdlib/math/base/special/abs" ] } diff --git a/lib/node_modules/@stdlib/blas/base/dasum/src/addon.c b/lib/node_modules/@stdlib/blas/base/dasum/src/addon.c index 6d9debae8ac..0fd3632c7d6 100644 --- a/lib/node_modules/@stdlib/blas/base/dasum/src/addon.c +++ b/lib/node_modules/@stdlib/blas/base/dasum/src/addon.c @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 The Stdlib Authors. +* 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. @@ -35,10 +35,27 @@ 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_FLOAT64ARRAY( env, X, N, strideX, argv, 1 ); - STDLIB_NAPI_CREATE_DOUBLE( env, API_SUFFIX(c_dasum)( N, X, strideX ), v ); + STDLIB_NAPI_ARGV_INT64( env, stride, argv, 2 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, stride, argv, 1 ); + STDLIB_NAPI_CREATE_DOUBLE( env, API_SUFFIX(c_dasum)( N, X, stride ), v ); return v; } -STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) +/** +* Receives JavaScript callback invocation data. +* +* @param env environment under which the function is invoked +* @param info callback data +* @return Node-API value +*/ +static napi_value addon_method( 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_INT64( env, stride, argv, 2 ); + STDLIB_NAPI_ARGV_INT64( env, offset, argv, 3 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, stride, argv, 1 ); + STDLIB_NAPI_CREATE_DOUBLE( env, API_SUFFIX(c_dasum_ndarray)( N, X, stride, offset ), v ); + return v; +} + +STDLIB_NAPI_MODULE_EXPORT_FCN_WITH_METHOD( addon, "ndarray", addon_method ) diff --git a/lib/node_modules/@stdlib/blas/base/dasum/src/dasum.c b/lib/node_modules/@stdlib/blas/base/dasum/src/dasum.c index e1056889d9e..dd938991d26 100644 --- a/lib/node_modules/@stdlib/blas/base/dasum/src/dasum.c +++ b/lib/node_modules/@stdlib/blas/base/dasum/src/dasum.c @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 The Stdlib Authors. +* 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. @@ -18,7 +18,7 @@ #include "stdlib/blas/base/dasum.h" #include "stdlib/blas/base/shared.h" -#include "stdlib/math/base/special/abs.h" +#include "stdlib/strided/base/stride2offset.h" /** * Computes the sum of absolute values. @@ -26,37 +26,9 @@ * @param N number of indexed elements * @param X input array * @param stride stride length -* @return sum of absolute values +* @return sum */ double API_SUFFIX(c_dasum)( const CBLAS_INT N, const double *X, const CBLAS_INT stride ) { - CBLAS_INT m; - CBLAS_INT i; - double sum; - - sum = 0.0; - if ( N <= 0 || stride <= 0 ) { - return sum; - } - // If the stride is equal to `1`, use unrolled loops... - if ( stride == 1 ) { - m = N % 6; - - // If we have a remainder, run a clean-up loop... - if ( m > 0 ) { - for ( i = 0; i < m; i++ ) { - sum += stdlib_base_abs( X[i] ); - } - } - if ( N < 6 ) { - return sum; - } - for ( i = m; i < N; i += 6 ) { - sum += stdlib_base_abs( X[i] ) + stdlib_base_abs( X[i+1] ) + stdlib_base_abs( X[i+2] ) + stdlib_base_abs( X[i+3] ) + stdlib_base_abs( X[i+4] ) + stdlib_base_abs( X[i+5] ); - } - return sum; - } - for ( i = 0; i < N*stride; i += stride ) { - sum += stdlib_base_abs( X[i] ); - } - return sum; + CBLAS_INT ox = stdlib_strided_stride2offset( N, stride ); + return API_SUFFIX(c_dasum_ndarray)( N, X, stride, ox ); } diff --git a/lib/node_modules/@stdlib/blas/base/dasum/src/dasum_cblas.c b/lib/node_modules/@stdlib/blas/base/dasum/src/dasum_cblas.c index 303cad6bd10..52b25cb25a7 100644 --- a/lib/node_modules/@stdlib/blas/base/dasum/src/dasum_cblas.c +++ b/lib/node_modules/@stdlib/blas/base/dasum/src/dasum_cblas.c @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 The Stdlib Authors. +* 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. @@ -19,6 +19,7 @@ #include "stdlib/blas/base/dasum.h" #include "stdlib/blas/base/dasum_cblas.h" #include "stdlib/blas/base/shared.h" +#include "stdlib/strided/base/min_view_buffer_index.h" /** * Computes the sum of absolute values. @@ -26,8 +27,30 @@ * @param N number of indexed elements * @param X input array * @param stride stride length -* @return sum of absolute values +* @return sum */ double API_SUFFIX(c_dasum)( const CBLAS_INT N, const double *X, const CBLAS_INT stride ) { - return API_SUFFIX(cblas_dasum)( N, X, stride ); + CBLAS_INT sx = stride; + if ( sx < 0 ) { + sx = -sx; + } + return API_SUFFIX(cblas_dasum)( N, X, sx ); +} + +/** +* Computes the sum of absolute values using alternative indexing semantics. +* +* @param N number of indexed elements +* @param X input array +* @param stride stride length +* @param offset starting index +* @return sum +*/ +double API_SUFFIX(c_dasum_ndarray)( const CBLAS_INT N, const double *X, const CBLAS_INT stride, const CBLAS_INT offset ) { + CBLAS_INT sx = stride; + if ( sx < 0 ) { + sx = -sx; + } + X += stdlib_strided_min_view_buffer_index( N, stride, offset ); // adjust array pointer + return API_SUFFIX(cblas_dasum)( N, X, sx ); } diff --git a/lib/node_modules/@stdlib/blas/base/dasum/src/dasum_f.c b/lib/node_modules/@stdlib/blas/base/dasum/src/dasum_f.c index a2f8f1c5904..dfd08c0566e 100644 --- a/lib/node_modules/@stdlib/blas/base/dasum/src/dasum_f.c +++ b/lib/node_modules/@stdlib/blas/base/dasum/src/dasum_f.c @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 The Stdlib Authors. +* 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. @@ -19,6 +19,7 @@ #include "stdlib/blas/base/dasum.h" #include "stdlib/blas/base/dasum_fortran.h" #include "stdlib/blas/base/shared.h" +#include "stdlib/strided/base/min_view_buffer_index.h" /** * Computes the sum of absolute values. @@ -26,10 +27,38 @@ * @param N number of indexed elements * @param X input array * @param stride stride length -* @return sum of absolute values +* @return sum */ double API_SUFFIX(c_dasum)( const CBLAS_INT N, const double *X, const CBLAS_INT stride ) { + CBLAS_INT sx; double sum; - dasumsub( &N, X, &stride, &sum ); + + sx = stride; + if ( sx < 0 ) { + sx = -sx; + } + dasumsub( &N, X, &sx, &sum ); + return sum; +} + +/** +* Computes the sum of absolute values using alternative indexing semantics. +* +* @param N number of indexed elements +* @param X input array +* @param stride stride length +* @param offset starting index +* @return sum +*/ +double API_SUFFIX(c_dasum_ndarray)( const CBLAS_INT N, const double *X, const CBLAS_INT stride, const CBLAS_INT offset ) { + CBLAS_INT sx; + double sum; + + sx = stride; + X += stdlib_strided_min_view_buffer_index( N, stride, offset ); // adjust array pointer + if ( sx < 0 ) { + sx = -sx; + } + dasumsub( &N, X, &sx, &sum ); return sum; } diff --git a/lib/node_modules/@stdlib/blas/base/dasum/src/dasum_ndarray.c b/lib/node_modules/@stdlib/blas/base/dasum/src/dasum_ndarray.c new file mode 100644 index 00000000000..4b242766893 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dasum/src/dasum_ndarray.c @@ -0,0 +1,71 @@ +/** +* @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. +*/ + +#include "stdlib/blas/base/dasum.h" +#include "stdlib/blas/base/shared.h" +#include "stdlib/math/base/special/abs.h" + +static const CBLAS_INT M = 6; + +/** +* Computes the sum of absolute values using alternative indexing semantics. +* +* @param N number of indexed elements +* @param X input array +* @param stride stride length +* @param offset starting index +* @return sum +*/ +double API_SUFFIX(c_dasum_ndarray)( const CBLAS_INT N, const double *X, const CBLAS_INT stride, const CBLAS_INT offset ) { + CBLAS_INT ix; + CBLAS_INT i; + CBLAS_INT m; + double sum; + + sum = 0.0; + if ( N <= 0 ) { + return sum; + } + ix = offset; + + // If the stride is equal to `1`, use unrolled loops... + if ( stride == 1 ) { + m = N % M; + + // If we have a remainder, run a clean-up loop... + if ( m > 0 ) { + for ( i = 0; i < m; i++ ) { + sum += stdlib_base_abs( X[ ix ] ); + ix += stride; + } + } + if ( N < M ) { + return sum; + } + for ( i = m; i < N; i += M ) { + sum += stdlib_base_abs( X[ ix ] ) + stdlib_base_abs( X[ ix+1 ] ) + stdlib_base_abs( X[ ix+2 ] ) + stdlib_base_abs( X[ ix+3 ] ) + stdlib_base_abs( X[ ix+4 ] ) + stdlib_base_abs( X[ ix+5 ] ); + ix += M; + } + return sum; + } + for ( i = 0; i < N; i ++ ) { + sum += stdlib_base_abs( X[ ix ] ); + ix += stride; + } + return sum; +} diff --git a/lib/node_modules/@stdlib/blas/base/dasum/test/test.dasum.js b/lib/node_modules/@stdlib/blas/base/dasum/test/test.dasum.js index 6b61954ad07..fafae44e2c5 100644 --- a/lib/node_modules/@stdlib/blas/base/dasum/test/test.dasum.js +++ b/lib/node_modules/@stdlib/blas/base/dasum/test/test.dasum.js @@ -82,15 +82,23 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu t.end(); }); -tape( 'if provided a `stride` parameter less than or equal to `0`, the function returns `0`', function test( t ) { +tape( 'the function supports specifying a negative stride', function test( t ) { var x; var y; + var N; - x = new Float64Array( [ 1.0, -2.0, 3.0, -4.0, 5.0 ] ); + x = new Float64Array([ + 1.0, // 2 + -2.0, + 3.0, // 1 + -4.0, + 5.0 + ]); + N = 2; - y = dasum( x.length, x, -1 ); + y = dasum( N, x, -2 ); - t.strictEqual( y, 0.0, 'returns expected value' ); + t.strictEqual( y, 4.0, 'returns expected value' ); t.end(); }); diff --git a/lib/node_modules/@stdlib/blas/base/dasum/test/test.dasum.native.js b/lib/node_modules/@stdlib/blas/base/dasum/test/test.dasum.native.js index a6650e397ac..796df0bd3d5 100644 --- a/lib/node_modules/@stdlib/blas/base/dasum/test/test.dasum.native.js +++ b/lib/node_modules/@stdlib/blas/base/dasum/test/test.dasum.native.js @@ -86,15 +86,23 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu t.end(); }); -tape( 'if provided a `stride` parameter less than or equal to `0`, the function returns `0`', opts, function test( t ) { +tape( 'the function supports specifying a negative stride', opts, function test( t ) { var x; var y; + var N; - x = new Float64Array( [ 1.0, -2.0, 3.0, -4.0, 5.0 ] ); + x = new Float64Array([ + 1.0, // 2 + -2.0, + 3.0, // 1 + -4.0, + 5.0 + ]); + N = 2; - y = dasum( x.length, x, -1 ); + y = dasum( N, x, -2 ); - t.strictEqual( y, 0.0, 'returns expected value' ); + t.strictEqual( y, 4.0, 'returns expected value' ); t.end(); }); diff --git a/lib/node_modules/@stdlib/blas/base/dasum/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/base/dasum/test/test.ndarray.js index fe7ad352729..b0275b65bf9 100644 --- a/lib/node_modules/@stdlib/blas/base/dasum/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/dasum/test/test.ndarray.js @@ -106,7 +106,7 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu t.end(); }); -tape( 'the function supports negative strides', function test( t ) { +tape( 'the function supports specifying a negative stride', function test( t ) { var x; var y; var N; diff --git a/lib/node_modules/@stdlib/blas/base/dasum/test/test.ndarray.native.js b/lib/node_modules/@stdlib/blas/base/dasum/test/test.ndarray.native.js index 0f8867ae078..36f5cb263a0 100644 --- a/lib/node_modules/@stdlib/blas/base/dasum/test/test.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/base/dasum/test/test.ndarray.native.js @@ -115,7 +115,7 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu t.end(); }); -tape( 'the function supports negative strides', opts, function test( t ) { +tape( 'the function supports specifying a negative stride', opts, function test( t ) { var x; var y; var N; diff --git a/lib/node_modules/@stdlib/blas/base/daxpy-wasm/README.md b/lib/node_modules/@stdlib/blas/base/daxpy-wasm/README.md index 91a3e3f06bc..fae7996ae87 100644 --- a/lib/node_modules/@stdlib/blas/base/daxpy-wasm/README.md +++ b/lib/node_modules/@stdlib/blas/base/daxpy-wasm/README.md @@ -147,7 +147,7 @@ var mod = new daxpy.Module( mem ); mod.initializeSync(); ``` -#### mod.main( N, alpha, xptr, strideX, yptr, strideY ) +#### daxpy.Module.prototype.main( N, α, xp, sx, yp, sy ) Multiplies a vector `x` by a constant and adds the result to `y`. @@ -201,13 +201,13 @@ console.log( view ); The function has the following parameters: - **N**: number of indexed elements. -- **alpha**: scalar constant. -- **xptr**: input [`Float64Array`][@stdlib/array/float64] pointer (i.e., byte offset). -- **strideX**: index increment for `x`. -- **yptr**: input [`Float64Array`][@stdlib/array/float64] pointer (i.e., byte offset). -- **strideY**: index increment for `y`. +- **α**: scalar constant. +- **xp**: input [`Float64Array`][@stdlib/array/float64] pointer (i.e., byte offset). +- **sx**: index increment for `x`. +- **yp**: input [`Float64Array`][@stdlib/array/float64] pointer (i.e., byte offset). +- **sy**: index increment for `y`. -#### mod.ndarray( N, alpha, xptr, strideX, offsetX, yptr, strideY, offsetY ) +#### daxpy.Module.prototype.ndarray( N, α, xp, sx, ox, yp, sy, oy ) Multiplies a vector `x` by a constant and adds the result to `y` using alternative indexing semantics. @@ -260,8 +260,8 @@ console.log( view ); The function has the following additional parameters: -- **offsetX**: starting index for `x`. -- **offsetY**: starting index for `y`. +- **ox**: starting index for `x`. +- **oy**: starting index for `y`. diff --git a/lib/node_modules/@stdlib/blas/base/daxpy-wasm/docs/repl.txt b/lib/node_modules/@stdlib/blas/base/daxpy-wasm/docs/repl.txt new file mode 100644 index 00000000000..d168e0ec500 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/daxpy-wasm/docs/repl.txt @@ -0,0 +1,562 @@ + +{{alias}}.main( N, alpha, x, strideX, y, strideY ) + Multiplies a vector `x` by a constant `alpha` and adds the result to `y`. + + The `N` and stride parameters determine which elements in the strided arrays + are accessed at runtime. + + Indexing is relative to the first index. To introduce an offset, use typed + array views. + + If `N <= 0` or `alpha == 0`, the function returns `y` unchanged. + + Parameters + ---------- + N: integer + Number of indexed elements. + + alpha: number + Constant. + + x: Float64Array + Input array. + + strideX: integer + Index increment for `x`. + + y: Float64Array + Output array. + + strideY: integer + Index increment for `y`. + + Returns + ------- + y: Float64Array + Output array. + + Examples + -------- + // Standard usage: + > var x = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + > var y = new {{alias:@stdlib/array/float64}}( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ); + > var alpha = 5.0; + > {{alias}}.main( x.length, alpha, x, 1, y, 1 ) + [ 6.0, 11.0, 16.0, 21.0, 26.0 ] + + // Using `N` and stride parameters: + > x = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + > y = new {{alias:@stdlib/array/float64}}( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); + > {{alias}}.main( 3, alpha, x, 2, y, -1 ) + [ 26.0, 16.0, 6.0, 1.0, 1.0, 1.0 ] + + // Using view offsets: + > var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + > var y0 = new {{alias:@stdlib/array/float64}}( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); + > var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); + > var y1 = new {{alias:@stdlib/array/float64}}( y0.buffer, y0.BYTES_PER_ELEMENT*3 ); + > {{alias}}.main( 3, 5.0, x1, -2, y1, 1 ) + [ 40.0, 31.0, 22.0 ] + > y0 + [ 7.0, 8.0, 9.0, 40.0, 31.0, 22.0 ] + + +{{alias}}.ndarray( N, alpha, x, strideX, offsetX, y, strideY, offsetY ) + Multiplies a vector `x` by a constant `alpha` and adds the result to `y`, + using alternative indexing semantics. + + While typed array views mandate a view offset based on the underlying + buffer, the offset parameters support indexing semantics based on starting + indices. + + Parameters + ---------- + N: integer + Number of indexed elements. + + alpha: number + Constant. + + x: Float64Array + Input array. + + strideX: integer + Index increment for `x`. + + offsetX: integer + Starting index for `x`. + + y: Float64Array + Output array. + + strideY: integer + Index increment for `y`. + + offsetY: integer + Starting index for `y`. + + Returns + ------- + y: Float64Array + Output array. + + Examples + -------- + // Standard usage: + > var x = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + > var y = new {{alias:@stdlib/array/float64}}( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ); + > var alpha = 5.0; + > {{alias}}.ndarray( x.length, alpha, x, 1, 0, y, 1, 0 ) + [ 6.0, 11.0, 16.0, 21.0, 26.0 ] + + // Advanced indexing: + > x = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + > y = new {{alias:@stdlib/array/float64}}( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); + > {{alias}}.ndarray( 3, alpha, x, 2, 1, y, -1, y.length-1 ) + [ 7.0, 8.0, 9.0, 40.0, 31.0, 22.0 ] + + +{{alias}}.Module( memory ) + Returns a new WebAssembly module wrapper which uses the provided WebAssembly + memory instance as its underlying memory. + + Parameters + ---------- + memory: Memory + WebAssembly memory instance. + + Returns + ------- + mod: Module + WebAssembly module wrapper. + + Examples + -------- + // Create a new memory instance: + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + + // Create a new routine: + > var mod = new {{alias}}.Module( mem ); + + // Initialize the routine: + > mod.initializeSync(); + + +{{alias}}.Module.prototype.binary + Read-only property which returns WebAssembly binary code. + + Returns + ------- + out: Uint8Array + WebAssembly binary code. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + > mod.binary + + + +{{alias}}.Module.prototype.memory + Read-only property which returns WebAssembly memory. + + Returns + ------- + mem: Memory|null + WebAssembly memory. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + > mod.memory + + + +{{alias}}.Module.prototype.buffer + Read-only property which returns a WebAssembly memory buffer as a + Uint8Array. + + Returns + ------- + buf: Uint8Array|null + WebAssembly memory buffer. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + > mod.buffer + + + +{{alias}}.Module.prototype.view + Read-only property which returns a WebAsssembly memory buffer as a DataView. + + Returns + ------- + view: DataView|null + WebAssembly memory view. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + > mod.view + + + +{{alias}}.Module.prototype.exports + Read-only property which returns "raw" WebAssembly module exports. + + Returns + ------- + out: Object|null + WebAssembly module exports. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + > mod.exports + {...} + + +{{alias}}.Module.prototype.initialize() + Asynchronously initializes a WebAssembly module instance. + + Returns + ------- + p: Promise + Promise which resolves upon initializing a WebAssembly module instance. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initialize(); + + +{{alias}}.Module.prototype.initializeAsync( clbk ) + Asynchronously initializes a WebAssembly module instance. + + Parameters + ---------- + clbk: Function + Callback to invoke upon initializing a WebAssembly module instance. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > function clbk() { console.log( 'done' ) }; + > mod.initializeAsync( clbk ); + + +{{alias}}.Module.prototype.initializeSync() + Synchronously initializes a WebAssembly module instance. + + In web browsers, JavaScript engines may raise an exception when attempting + to synchronously compile large WebAssembly binaries due to concerns about + blocking the main thread. Hence, to initialize WebAssembly modules having + large binaries (e.g., >4KiB), consider using asynchronous initialization + methods in browser contexts. + + Returns + ------- + mod: Module + Module wrapper instance. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + + +{{alias}}.Module.prototype.realloc( nbytes ) + Reallocates the underlying WebAssembly memory instance to a specified number + of bytes. + + WebAssembly memory can only **grow**, not shrink. Hence, if provided a + number of bytes which is less than or equal to the size of the current + memory, the function does nothing. + + When non-shared memory is resized, the underlying the `ArrayBuffer` is + detached, consequently invalidating any associated typed array views. Before + resizing non-shared memory, ensure that associated typed array views no + longer need byte access and can be garbage collected. + + Parameters + ---------- + nbytes: integer + Memory size (in bytes). + + Returns + ------- + bool: boolean + Boolean indicating whether the resize operation was successful. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + > mod.realloc( 100 ) + + + +{{alias}}.Module.prototype.hasCapacity( byteOffset, values ) + Returns a boolean indicating whether the underlying WebAssembly memory + instance has the capacity to store a provided list of values starting from a + specified byte offset. + + Parameters + ---------- + byteOffset: integer + Byte offset at which to start writing values. + + values: ArrayLikeObject + Input array containing values to write. + + Returns + ------- + bool: boolean + Boolean indicating whether the underlying WebAssembly memory instance + has enough capacity. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + > mod.realloc( 100 ); + > mod.hasCapacity( 0, [ 1, 2, 3, 4 ] ) + true + + +{{alias}}.Module.prototype.isView( values ) + Returns a boolean indicating whether a provided list of values is a view of + the underlying memory of the WebAssembly module. + + Parameters + ---------- + values: ArrayLikeObject + Input array. + + Returns + ------- + bool: boolean + Boolean indicating whether the list is a memory view. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + > mod.realloc( 100 ); + > mod.isView( [ 1, 2, 3, 4 ] ) + false + + +{{alias}}.Module.prototype.write( byteOffset, values ) + Writes values to the underlying WebAssembly memory instance. + + The function infers element size (i.e., number of bytes per element) from + the data type of the input array. For example, if provided a Float32Array, + the function writes each element as a single-precision floating-point number + to the underlying WebAssembly memory instance. + + In order to write elements as a different data type, you need to perform an + explicit cast *before* calling this method. For example, in order to write + single-precision floating-point numbers contained in a Float32Array as + signed 32-bit integers, you must first convert the Float32Array to an + Int32Array before passing the values to this method. + + If provided an array having an unknown or "generic" data type, elements are + written as double-precision floating-point numbers. + + Parameters + ---------- + byteOffset: integer + Byte offset at which to start writing values. + + values: ArrayLikeObject + Input array containing values to write. + + Returns + ------- + mod: Module + Module wrapper instance. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + > mod.realloc( 100 ); + > mod.write( 0, [ 1, 2, 3, 4 ] ); + + +{{alias}}.Module.prototype.read( byteOffset, out ) + Reads values from the underlying WebAssembly memory instance. + + The function infers element size (i.e., number of bytes per element) from + the data type of the output array. For example, if provided a Float32Array, + the function reads each element as a single-precision floating-point number + from the underlying WebAssembly memory instance. + + In order to read elements as a different data type, you need to perform an + explicit cast *after* calling this method. For example, in order to read + single-precision floating-point numbers contained in a Float32Array as + signed 32-bit integers, you must convert the Float32Array to an Int32Array + after reading memory values using this method. + + If provided an output array having an unknown or "generic" data type, + elements are read as double-precision floating-point numbers. + + Parameters + ---------- + byteOffset: integer + Byte offset at which to start reading values. + + out: ArrayLikeObject + Output array for storing read values. + + Returns + ------- + mod: Module + Module wrapper instance. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + > mod.realloc( 100 ); + > mod.write( 0, [ 1, 2, 3, 4 ] ); + > var out = [ 0, 0, 0, 0 ]; + > mod.read( 0, out ); + > out + [ 1, 2, 3, 4 ] + + +{{alias}}.Module.prototype.main( N, α, xp, sx, yp, sy ) + Multiples a vector `x` by a constant and adds the result to `y`. + + Parameters + ---------- + N: integer + Number of indexed elements. + + α: number + Constant. + + xp: integer + Input array pointer (i.e., byte offset). + + sx: integer + Index increment for `x`. + + yp: integer + Output array pointer (i.e., byte offset). + + sy: integer + Index increment for `y`. + + Returns + ------- + yp: integer + Output array pointer (i.e., byte offset). + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 1 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + + // Define "pointers" (i.e., byte offsets) into module memory: + > var xptr = 0; + > var yptr = 40; + + // Write data to module memory: + > mod.write( xptr, {{alias:@stdlib/array/one-to}}( 5, 'float64' ) ); + > mod.write( yptr, {{alias:@stdlib/array/ones}}( 5, 'float64' ) ); + + // Perform computation: + > mod.main( 5, 5.0, xptr, 1, yptr, 1 ); + + // Extract results from module memory: + > var view = {{alias:@stdlib/array/zeros}}( 5, 'float64' ); + > mod.read( yptr, view ); + > view + [ 6.0, 11.0, 16.0, 21.0, 26.0 ] + + +{{alias}}.Module.prototype.ndarray( N, α, xp, sx, ox, yp, sy, oy ) + Multiples a vector `x` by a constant and adds the result to `y`, using + alternative indexing semantics. + + Parameters + ---------- + N: integer + Number of indexed elements. + + α: number + Constant. + + xp: integer + Input array pointer (i.e., byte offset). + + sx: integer + Index increment for `x`. + + ox: integer + Starting index for `x`. + + yp: integer + Output array pointer (i.e., byte offset). + + sy: integer + Index increment for `y`. + + oy: integer + Starting index for `y`. + + Returns + ------- + oy: integer + Output array pointer (i.e., byte offset). + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 1 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + + // Define "pointers" (i.e., byte offsets) into module memory: + > var xptr = 0; + > var yptr = 40; + + // Write data to module memory: + > mod.write( xptr, {{alias:@stdlib/array/one-to}}( 5, 'float64' ) ); + > mod.write( yptr, {{alias:@stdlib/array/ones}}( 5, 'float64' ) ); + + // Perform computation: + > mod.ndarray( 5, 5.0, xptr, 1, 0, yptr, 1, 0 ); + + // Extract results from module memory: + > var view = {{alias:@stdlib/array/zeros}}( 5, 'float64' ); + > mod.read( yptr, view ); + > view + [ 6.0, 11.0, 16.0, 21.0, 26.0 ] + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/blas/base/daxpy-wasm/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/base/daxpy-wasm/docs/types/index.d.ts new file mode 100644 index 00000000000..72e2688cf9c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/daxpy-wasm/docs/types/index.d.ts @@ -0,0 +1,402 @@ +/* +* @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 { ModuleWrapper, Memory } from '@stdlib/types/wasm'; + +/** +* Interface defining a module constructor which is both "newable" and "callable". +*/ +interface ModuleConstructor { + /** + * Returns a new WebAssembly module wrapper instance which uses the provided WebAssembly memory instance as its underlying memory. + * + * @param mem - WebAssembly memory instance + * @returns module wrapper instance + * + * @example + * var Memory = require( '@stdlib/wasm/memory' ); + * var oneTo = require( '@stdlib/array/one-to' ); + * var ones = require( '@stdlib/array/ones' ); + * var zeros = require( '@stdlib/array/zeros' ); + * var bytesPerElement = require( '@stdlib/ndarray/base/bytes-per-element' ); + * + * // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): + * var mem = new Memory({ + * 'initial': 10, + * 'maximum': 100 + * }); + * + * // Create a BLAS routine: + * var daxpy = new daxpy.Module( mem ); + * // returns + * + * // Initialize the routine: + * daxpy.initializeSync(); + * + * // Define a vector data type: + * var dtype = 'float64'; + * + * // Specify a vector length: + * var N = 5; + * + * // Define pointers (i.e., byte offsets) for storing two vectors: + * var xptr = 0; + * var yptr = N * bytesPerElement( dtype ); + * + * // Write vector values to module memory: + * daxpy.write( xptr, oneTo( N, dtype ) ); + * daxpy.write( yptr, ones( N, dtype ) ); + * + * // Perform computation: + * var ptr = daxpy.main( N, 5.0, xptr, 1, yptr, 1 ); + * // returns + * + * var bool = ( ptr === yptr ); + * // returns true + * + * // Read out the results: + * var view = zeros( N, dtype ); + * daxpy.read( yptr, view ); + * // view => [ 6.0, 11.0, 16.0, 21.0, 26.0 ] + */ + new( mem: Memory ): Module; // newable + + /** + * Returns a new WebAssembly module wrapper instance which uses the provided WebAssembly memory instance as its underlying memory. + * + * @param mem - WebAssembly memory instance + * @returns module wrapper instance + * + * @example + * var Memory = require( '@stdlib/wasm/memory' ); + * var oneTo = require( '@stdlib/array/one-to' ); + * var ones = require( '@stdlib/array/ones' ); + * var zeros = require( '@stdlib/array/zeros' ); + * var bytesPerElement = require( '@stdlib/ndarray/base/bytes-per-element' ); + * + * // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): + * var mem = new Memory({ + * 'initial': 10, + * 'maximum': 100 + * }); + * + * // Create a BLAS routine: + * var daxpy = daxpy.Module( mem ); + * // returns + * + * // Initialize the routine: + * daxpy.initializeSync(); + * + * // Define a vector data type: + * var dtype = 'float64'; + * + * // Specify a vector length: + * var N = 5; + * + * // Define pointers (i.e., byte offsets) for storing two vectors: + * var xptr = 0; + * var yptr = N * bytesPerElement( dtype ); + * + * // Write vector values to module memory: + * daxpy.write( xptr, oneTo( N, dtype ) ); + * daxpy.write( yptr, ones( N, dtype ) ); + * + * // Perform computation: + * var ptr = daxpy.main( N, 5.0, xptr, 1, yptr, 1 ); + * // returns + * + * var bool = ( ptr === yptr ); + * // returns true + * + * // Read out the results: + * var view = zeros( N, dtype ); + * daxpy.read( yptr, view ); + * // view => [ 6.0, 11.0, 16.0, 21.0, 26.0 ] + */ + ( mem: Memory ): Module; // callable +} + +/** +* Interface describing a `daxpy` WebAssembly module. +*/ +interface Module extends ModuleWrapper { + /** + * Multiplies a vector `x` by a constant `alpha` and adds the result to `y`. + * + * @param N - number of indexed elements + * @param alpha - constant + * @param xptr - input array pointer (i.e., byte offset) + * @param strideX - `x` stride length + * @param yptr - output array pointer (i.e., byte offset) + * @param strideY - `y` stride length + * @returns output array pointer (i.e., byte offset) + * + * @example + * var Memory = require( '@stdlib/wasm/memory' ); + * var oneTo = require( '@stdlib/array/one-to' ); + * var ones = require( '@stdlib/array/ones' ); + * var zeros = require( '@stdlib/array/zeros' ); + * var bytesPerElement = require( '@stdlib/ndarray/base/bytes-per-element' ); + * + * // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): + * var mem = new Memory({ + * 'initial': 10, + * 'maximum': 100 + * }); + * + * // Create a BLAS routine: + * var daxpy = new Module( mem ); + * // returns + * + * // Initialize the routine: + * daxpy.initializeSync(); + * + * // Define a vector data type: + * var dtype = 'float64'; + * + * // Specify a vector length: + * var N = 5; + * + * // Define pointers (i.e., byte offsets) for storing two vectors: + * var xptr = 0; + * var yptr = N * bytesPerElement( dtype ); + * + * // Write vector values to module memory: + * daxpy.write( xptr, oneTo( N, dtype ) ); + * daxpy.write( yptr, ones( N, dtype ) ); + * + * // Perform computation: + * var ptr = daxpy.main( N, 5.0, xptr, 1, yptr, 1 ); + * // returns + * + * var bool = ( ptr === yptr ); + * // returns true + * + * // Read out the results: + * var view = zeros( N, dtype ); + * daxpy.read( yptr, view ); + * // view => [ 6.0, 11.0, 16.0, 21.0, 26.0 ] + */ + main( N: number, alpha: number, xptr: number, strideX: number, yptr: number, strideY: number ): number; + + /** + * Multiplies a vector `x` by a constant `alpha` and adds the result to `y` using alternative indexing semantics. + * + * @param N - number of indexed elements + * @param alpha - constant + * @param xptr - input array pointer (i.e., byte offset) + * @param strideX - `x` stride length + * @param offsetX - starting index for `x` + * @param yptr - output array pointer (i.e., byte offset) + * @param strideY - `y` stride length + * @param offsetY - starting index for `y` + * @returns output array pointer (i.e., byte offset) + * + * @example + * var Memory = require( '@stdlib/wasm/memory' ); + * var oneTo = require( '@stdlib/array/one-to' ); + * var ones = require( '@stdlib/array/ones' ); + * var zeros = require( '@stdlib/array/zeros' ); + * var bytesPerElement = require( '@stdlib/ndarray/base/bytes-per-element' ); + * + * // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): + * var mem = new Memory({ + * 'initial': 10, + * 'maximum': 100 + * }); + * + * // Create a BLAS routine: + * var daxpy = new Module( mem ); + * // returns + * + * // Initialize the routine: + * daxpy.initializeSync(); + * + * // Define a vector data type: + * var dtype = 'float64'; + * + * // Specify a vector length: + * var N = 5; + * + * // Define pointers (i.e., byte offsets) for storing two vectors: + * var xptr = 0; + * var yptr = N * bytesPerElement( dtype ); + * + * // Write vector values to module memory: + * daxpy.write( xptr, oneTo( N, dtype ) ); + * daxpy.write( yptr, ones( N, dtype ) ); + * + * // Perform computation: + * var ptr = daxpy.ndarray( N, 5.0, xptr, 1, 0, yptr, 1, 0 ); + * // returns + * + * var bool = ( ptr === yptr ); + * // returns true + * + * // Read out the results: + * var view = zeros( N, dtype ); + * daxpy.read( yptr, view ); + * // view => [ 6.0, 11.0, 16.0, 21.0, 26.0 ] + */ + ndarray( N: number, alpha: number, xptr: number, strideX: number, offsetX: number, yptr: number, strideY: number, offsetY: number ): number; +} + +/** +* Interface describing `daxpy`. +*/ +interface Routine extends ModuleWrapper { + /** + * Multiplies a vector `x` by a constant `alpha` and adds the result to `y`. + * + * @param N - number of indexed elements + * @param alpha - constant + * @param x - input array + * @param strideX - `x` stride length + * @param y - output array + * @param strideY - `y` stride length + * @returns output array + * + * @example + * var Float64Array = require( '@stdlib/array/float64' ); + * + * var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + * var y = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ); + * + * daxpy.main( x.length, 5.0, x, 1, y, 1 ); + * // y => [ 6.0, 11.0, 16.0, 21.0, 26.0 ] + */ + main( N: number, alpha: number, x: Float64Array, strideX: number, y: Float64Array, strideY: number ): Float64Array; + + /** + * Multiplies a vector `x` by a constant `alpha` and adds the result to `y` using alternative indexing semantics. + * + * @param N - number of indexed elements + * @param alpha - constant + * @param x - input array + * @param strideX - `x` stride length + * @param offsetX - starting index for `x` + * @param y - output array + * @param strideY - `y` stride length + * @param offsetY - starting index for `y` + * @returns output array + * + * @example + * var Float64Array = require( '@stdlib/array/float64' ); + * + * var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + * var y = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ); + * + * daxpy.ndarray( x.length, 5.0, x, 1, 0, y, 1, 0 ); + * // y => [ 6.0, 11.0, 16.0, 21.0, 26.0 ] + */ + ndarray( N: number, alpha: number, x: Float64Array, strideX: number, offsetX: number, y: Float64Array, strideY: number, offsetY: number ): Float64Array; + + /** + * Returns a new WebAssembly module wrapper instance which uses the provided WebAssembly memory instance as its underlying memory. + * + * @param mem - WebAssembly memory instance + * @returns module wrapper instance + * + * @example + * var Memory = require( '@stdlib/wasm/memory' ); + * var oneTo = require( '@stdlib/array/one-to' ); + * var ones = require( '@stdlib/array/ones' ); + * var zeros = require( '@stdlib/array/zeros' ); + * var bytesPerElement = require( '@stdlib/ndarray/base/bytes-per-element' ); + * + * // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): + * var mem = new Memory({ + * 'initial': 10, + * 'maximum': 100 + * }); + * + * // Create a BLAS routine: + * var daxpy = new daxpy.Module( mem ); + * // returns + * + * // Initialize the routine: + * daxpy.initializeSync(); + * + * // Define a vector data type: + * var dtype = 'float64'; + * + * // Specify a vector length: + * var N = 5; + * + * // Define pointers (i.e., byte offsets) for storing two vectors: + * var xptr = 0; + * var yptr = N * bytesPerElement( dtype ); + * + * // Write vector values to module memory: + * daxpy.write( xptr, oneTo( N, dtype ) ); + * daxpy.write( yptr, ones( N, dtype ) ); + * + * // Perform computation: + * var ptr = daxpy.main( N, 5.0, xptr, 1, yptr, 1 ); + * // returns + * + * var bool = ( ptr === yptr ); + * // returns true + * + * // Read out the results: + * var view = zeros( N, dtype ); + * daxpy.read( yptr, view ); + * // view => [ 6.0, 11.0, 16.0, 21.0, 26.0 ] + */ + Module: ModuleConstructor; +} + +/** +* Multiplies a vector `x` by a constant `alpha` and adds the result to `y`. +* +* @param N - number of indexed elements +* @param alpha - constant +* @param x - input array +* @param strideX - `x` stride length +* @param y - output array +* @param strideY - `y` stride length +* @returns output array +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +* var y = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +* +* daxpy.main( x.length, 5.0, x, 1, y, 1 ); +* // y => [ 6.0, 11.0, 16.0, 21.0, 26.0 ] +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +* var y = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +* +* daxpy.ndarray( x.length, 5.0, x, 1, 0, y, 1, 0 ); +* // y => [ 6.0, 11.0, 16.0, 21.0, 26.0 ] +*/ +declare var daxpy: Routine; + + +// EXPORTS // + +export = daxpy; diff --git a/lib/node_modules/@stdlib/blas/base/daxpy-wasm/docs/types/test.ts b/lib/node_modules/@stdlib/blas/base/daxpy-wasm/docs/types/test.ts new file mode 100644 index 00000000000..24cdc4f39e3 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/daxpy-wasm/docs/types/test.ts @@ -0,0 +1,596 @@ +/* +* @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. +*/ + +/* eslint-disable space-in-parens */ + +import Memory = require( '@stdlib/wasm/memory' ); +import daxpy = require( './index' ); + + +// TESTS // + +// Attached to the main export is a `main` method which returns a Float64Array... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + daxpy.main( x.length, 5.0, x, 1, y, 1 ); // $ExpectType Float64Array +} + +// The compiler throws an error if the `main` method is provided a first argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + daxpy.main( '10', 5.0, x, 1, y, 1 ); // $ExpectError + daxpy.main( true, 5.0, x, 1, y, 1 ); // $ExpectError + daxpy.main( false, 5.0, x, 1, y, 1 ); // $ExpectError + daxpy.main( null, 5.0, x, 1, y, 1 ); // $ExpectError + daxpy.main( undefined, 5.0, x, 1, y, 1 ); // $ExpectError + daxpy.main( [], 5.0, x, 1, y, 1 ); // $ExpectError + daxpy.main( {}, 5.0, x, 1, y, 1 ); // $ExpectError + daxpy.main( ( x: number ): number => x, 5.0, x, 1, y, 1 ); // $ExpectError +} + +// The compiler throws an error if the `main` method is provided a second argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + daxpy.main( x.length, '10', x, 1, y, 1 ); // $ExpectError + daxpy.main( x.length, true, x, 1, y, 1 ); // $ExpectError + daxpy.main( x.length, false, x, 1, y, 1 ); // $ExpectError + daxpy.main( x.length, null, x, 1, y, 1 ); // $ExpectError + daxpy.main( x.length, undefined, x, 1, y, 1 ); // $ExpectError + daxpy.main( x.length, [], x, 1, y, 1 ); // $ExpectError + daxpy.main( x.length, {}, x, 1, y, 1 ); // $ExpectError + daxpy.main( x.length, ( x: number ): number => x, x, 1, y, 1 ); // $ExpectError +} + +// The compiler throws an error if the `main` method is provided a third argument which is not a Float64Array... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + daxpy.main( x.length, 5.0, 10, 1, y, 1 ); // $ExpectError + daxpy.main( x.length, 5.0, '10', 1, y, 1 ); // $ExpectError + daxpy.main( x.length, 5.0, true, 1, y, 1 ); // $ExpectError + daxpy.main( x.length, 5.0, false, 1, y, 1 ); // $ExpectError + daxpy.main( x.length, 5.0, null, 1, y, 1 ); // $ExpectError + daxpy.main( x.length, 5.0, undefined, 1, y, 1 ); // $ExpectError + daxpy.main( x.length, 5.0, [], 1, y, 1 ); // $ExpectError + daxpy.main( x.length, 5.0, {}, 1, y, 1 ); // $ExpectError + daxpy.main( x.length, 5.0, ( x: number ): number => x, 1, y, 1 ); // $ExpectError +} + +// The compiler throws an error if the `main` method is provided a fourth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + daxpy.main( x.length, 5.0, x, '10', y, 1 ); // $ExpectError + daxpy.main( x.length, 5.0, x, true, y, 1 ); // $ExpectError + daxpy.main( x.length, 5.0, x, false, y, 1 ); // $ExpectError + daxpy.main( x.length, 5.0, x, null, y, 1 ); // $ExpectError + daxpy.main( x.length, 5.0, x, undefined, y, 1 ); // $ExpectError + daxpy.main( x.length, 5.0, x, [], y, 1 ); // $ExpectError + daxpy.main( x.length, 5.0, x, {}, y, 1 ); // $ExpectError + daxpy.main( x.length, 5.0, x, ( x: number ): number => x, y, 1 ); // $ExpectError +} + +// The compiler throws an error if the `main` method is provided a fifth argument which is not a Float64Array... +{ + const x = new Float64Array( 10 ); + + daxpy.main( x.length, 5.0, x, 1, 10, 1 ); // $ExpectError + daxpy.main( x.length, 5.0, x, 1, '10', 1 ); // $ExpectError + daxpy.main( x.length, 5.0, x, 1, true, 1 ); // $ExpectError + daxpy.main( x.length, 5.0, x, 1, false, 1 ); // $ExpectError + daxpy.main( x.length, 5.0, x, 1, null, 1 ); // $ExpectError + daxpy.main( x.length, 5.0, x, 1, undefined, 1 ); // $ExpectError + daxpy.main( x.length, 5.0, x, 1, [], 1 ); // $ExpectError + daxpy.main( x.length, 5.0, x, 1, {}, 1 ); // $ExpectError + daxpy.main( x.length, 5.0, x, 1, ( x: number ): number => x, 1 ); // $ExpectError +} + +// The compiler throws an error if the `main` method is provided a sixth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + daxpy.main( x.length, 5.0, x, 1, y, '10' ); // $ExpectError + daxpy.main( x.length, 5.0, x, 1, y, true ); // $ExpectError + daxpy.main( x.length, 5.0, x, 1, y, false ); // $ExpectError + daxpy.main( x.length, 5.0, x, 1, y, null ); // $ExpectError + daxpy.main( x.length, 5.0, x, 1, y, undefined ); // $ExpectError + daxpy.main( x.length, 5.0, x, 1, y, [] ); // $ExpectError + daxpy.main( x.length, 5.0, x, 1, y, {} ); // $ExpectError + daxpy.main( x.length, 5.0, x, 1, y, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `main` method is provided an unsupported number of arguments... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + daxpy.main(); // $ExpectError + daxpy.main( x.length ); // $ExpectError + daxpy.main( x.length, 5.0 ); // $ExpectError + daxpy.main( x.length, 5.0, x ); // $ExpectError + daxpy.main( x.length, 5.0, x, 1 ); // $ExpectError + daxpy.main( x.length, 5.0, x, 1, y ); // $ExpectError + daxpy.main( x.length, 5.0, x, 1, y, 1, 10 ); // $ExpectError +} + +// Attached to main export is an `ndarray` method which returns a Float64Array... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + daxpy.ndarray( x.length, 5.0, x, 1, 0, y, 1, 0 ); // $ExpectType Float64Array +} + +// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + daxpy.ndarray( '10', 5.0, x, 1, 0, y, 1, 0 ); // $ExpectError + daxpy.ndarray( true, 5.0, x, 1, 0, y, 1, 0 ); // $ExpectError + daxpy.ndarray( false, 5.0, x, 1, 0, y, 1, 0 ); // $ExpectError + daxpy.ndarray( null, 5.0, x, 1, 0, y, 1, 0 ); // $ExpectError + daxpy.ndarray( undefined, 5.0, x, 1, 0, y, 1, 0 ); // $ExpectError + daxpy.ndarray( [], 5.0, x, 1, 0, y, 1, 0 ); // $ExpectError + daxpy.ndarray( {}, 5.0, x, 1, 0, y, 1, 0 ); // $ExpectError + daxpy.ndarray( ( x: number ): number => x, 5.0, x, 1, 0, y, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a second argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + daxpy.ndarray( x.length, '10', x, 1, 0, y, 1, 0 ); // $ExpectError + daxpy.ndarray( x.length, true, x, 1, 0, y, 1, 0 ); // $ExpectError + daxpy.ndarray( x.length, false, x, 1, 0, y, 1, 0 ); // $ExpectError + daxpy.ndarray( x.length, null, x, 1, 0, y, 1, 0 ); // $ExpectError + daxpy.ndarray( x.length, undefined, x, 1, 0, y, 1, 0 ); // $ExpectError + daxpy.ndarray( x.length, [], x, 1, 0, y, 1, 0 ); // $ExpectError + daxpy.ndarray( x.length, {}, x, 1, 0, y, 1, 0 ); // $ExpectError + daxpy.ndarray( x.length, ( x: number ): number => x, x, 1, 0, y, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a third argument which is not a Float64Array... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + daxpy.ndarray( x.length, 5.0, 10, 1, 0, y, 1, 0 ); // $ExpectError + daxpy.ndarray( x.length, 5.0, '10', 1, 0, y, 1, 0 ); // $ExpectError + daxpy.ndarray( x.length, 5.0, true, 1, 0, y, 1, 0 ); // $ExpectError + daxpy.ndarray( x.length, 5.0, false, 1, 0, y, 1, 0 ); // $ExpectError + daxpy.ndarray( x.length, 5.0, null, 1, 0, y, 1, 0 ); // $ExpectError + daxpy.ndarray( x.length, 5.0, undefined, 1, 0, y, 1, 0 ); // $ExpectError + daxpy.ndarray( x.length, 5.0, [], 1, 0, y, 1, 0 ); // $ExpectError + daxpy.ndarray( x.length, 5.0, {}, 1, 0, y, 1, 0 ); // $ExpectError + daxpy.ndarray( x.length, 5.0, ( x: number ): number => x, 1, 0, y, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fourth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + daxpy.ndarray( x.length, 5.0, x, '10', 0, y, 1, 0 ); // $ExpectError + daxpy.ndarray( x.length, 5.0, x, true, 0, y, 1, 0 ); // $ExpectError + daxpy.ndarray( x.length, 5.0, x, false, 0, y, 1, 0 ); // $ExpectError + daxpy.ndarray( x.length, 5.0, x, null, 0, y, 1, 0 ); // $ExpectError + daxpy.ndarray( x.length, 5.0, x, undefined, 0, y, 1, 0 ); // $ExpectError + daxpy.ndarray( x.length, 5.0, x, [], 0, y, 1, 0 ); // $ExpectError + daxpy.ndarray( x.length, 5.0, x, {}, 0, y, 1, 0 ); // $ExpectError + daxpy.ndarray( x.length, 5.0, x, ( x: number ): number => x, 0, y, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fifth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + daxpy.ndarray( x.length, 5.0, x, 1, '10', y, 1, 0 ); // $ExpectError + daxpy.ndarray( x.length, 5.0, x, 1, true, y, 1, 0 ); // $ExpectError + daxpy.ndarray( x.length, 5.0, x, 1, false, y, 1, 0 ); // $ExpectError + daxpy.ndarray( x.length, 5.0, x, 1, null, y, 1, 0 ); // $ExpectError + daxpy.ndarray( x.length, 5.0, x, 1, undefined, y, 1, 0 ); // $ExpectError + daxpy.ndarray( x.length, 5.0, x, 1, [], y, 1, 0 ); // $ExpectError + daxpy.ndarray( x.length, 5.0, x, 1, {}, y, 1, 0 ); // $ExpectError + daxpy.ndarray( x.length, 5.0, x, 1, ( x: number ): number => x, y, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a sixth argument which is not a Float64Array... +{ + const x = new Float64Array( 10 ); + + daxpy.ndarray( x.length, 5.0, x, 1, 0, 10, 1, 0 ); // $ExpectError + daxpy.ndarray( x.length, 5.0, x, 1, 0, '10', 1, 0 ); // $ExpectError + daxpy.ndarray( x.length, 5.0, x, 1, 0, true, 1, 0 ); // $ExpectError + daxpy.ndarray( x.length, 5.0, x, 1, 0, false, 1, 0 ); // $ExpectError + daxpy.ndarray( x.length, 5.0, x, 1, 0, null, 1, 0 ); // $ExpectError + daxpy.ndarray( x.length, 5.0, x, 1, 0, undefined, 1, 0 ); // $ExpectError + daxpy.ndarray( x.length, 5.0, x, 1, 0, [], 1, 0 ); // $ExpectError + daxpy.ndarray( x.length, 5.0, x, 1, 0, {}, 1, 0 ); // $ExpectError + daxpy.ndarray( x.length, 5.0, x, 1, 0, ( x: number ): number => x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a seventh argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + daxpy.ndarray( x.length, 5.0, x, 1, 0, y, '10', 0 ); // $ExpectError + daxpy.ndarray( x.length, 5.0, x, 1, 0, y, true, 0 ); // $ExpectError + daxpy.ndarray( x.length, 5.0, x, 1, 0, y, false, 0 ); // $ExpectError + daxpy.ndarray( x.length, 5.0, x, 1, 0, y, null, 0 ); // $ExpectError + daxpy.ndarray( x.length, 5.0, x, 1, 0, y, undefined, 0 ); // $ExpectError + daxpy.ndarray( x.length, 5.0, x, 1, 0, y, [], 0 ); // $ExpectError + daxpy.ndarray( x.length, 5.0, x, 1, 0, y, {}, 0 ); // $ExpectError + daxpy.ndarray( x.length, 5.0, x, 1, 0, y, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an eighth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + daxpy.ndarray( x.length, 5.0, x, 1, 0, y, 1, '10' ); // $ExpectError + daxpy.ndarray( x.length, 5.0, x, 1, 0, y, 1, true ); // $ExpectError + daxpy.ndarray( x.length, 5.0, x, 1, 0, y, 1, false ); // $ExpectError + daxpy.ndarray( x.length, 5.0, x, 1, 0, y, 1, null ); // $ExpectError + daxpy.ndarray( x.length, 5.0, x, 1, 0, y, 1, undefined ); // $ExpectError + daxpy.ndarray( x.length, 5.0, x, 1, 0, y, 1, [] ); // $ExpectError + daxpy.ndarray( x.length, 5.0, x, 1, 0, y, 1, {} ); // $ExpectError + daxpy.ndarray( x.length, 5.0, x, 1, 0, y, 1, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + daxpy.ndarray(); // $ExpectError + daxpy.ndarray( x.length ); // $ExpectError + daxpy.ndarray( x.length, 5.0 ); // $ExpectError + daxpy.ndarray( x.length, 5.0, x ); // $ExpectError + daxpy.ndarray( x.length, 5.0, x, 1 ); // $ExpectError + daxpy.ndarray( x.length, 5.0, x, 1, 0 ); // $ExpectError + daxpy.ndarray( x.length, 5.0, x, 1, 0, y ); // $ExpectError + daxpy.ndarray( x.length, 5.0, x, 1, 0, y, 1 ); // $ExpectError + daxpy.ndarray( x.length, 5.0, x, 1, 0, y, 1, 0, 10 ); // $ExpectError +} + +// Attached to the main export is a `Module` constructor which returns a module... +{ + const mem = new Memory({ + 'initial': 0 + }); + + daxpy.Module( mem ); // $ExpectType Module +} + +// The compiler throws an error if the `Module` constructor is not provided a WebAssembly memory instance... +{ + daxpy.Module( '10' ); // $ExpectError + daxpy.Module( true ); // $ExpectError + daxpy.Module( false ); // $ExpectError + daxpy.Module( null ); // $ExpectError + daxpy.Module( undefined ); // $ExpectError + daxpy.Module( [] ); // $ExpectError + daxpy.Module( {} ); // $ExpectError + daxpy.Module( ( x: number ): number => x ); // $ExpectError +} + +// The `Module` constructor returns a module instance having a `main` method which returns a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = daxpy.Module( mem ); + + mod.main( 10, 5.0, 0, 1, 80, 1 ); // $ExpectType number +} + +// The compiler throws an error if the `main` method of a module instance is provided a first argument which is not a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = daxpy.Module( mem ); + + mod.main( '10', 5.0, 10, 1, 80, 1 ); // $ExpectError + mod.main( true, 5.0, 10, 1, 80, 1 ); // $ExpectError + mod.main( false, 5.0, 10, 1, 80, 1 ); // $ExpectError + mod.main( null, 5.0, 10, 1, 80, 1 ); // $ExpectError + mod.main( undefined, 5.0, 10, 1, 80, 1 ); // $ExpectError + mod.main( [], 5.0, 10, 1, 80, 1 ); // $ExpectError + mod.main( {}, 5.0, 10, 1, 80, 1 ); // $ExpectError + mod.main( ( x: number ): number => x, 5.0, 10, 1, 80, 1 ); // $ExpectError +} + +// The compiler throws an error if the `main` method of a module instance is provided a second argument which is not a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = daxpy.Module( mem ); + + mod.main( 10, '10', 0, 1, 80, 1 ); // $ExpectError + mod.main( 10, true, 0, 1, 80, 1 ); // $ExpectError + mod.main( 10, false, 0, 1, 80, 1 ); // $ExpectError + mod.main( 10, null, 0, 1, 80, 1 ); // $ExpectError + mod.main( 10, undefined, 0, 1, 80, 1 ); // $ExpectError + mod.main( 10, [], 0, 1, 80, 1 ); // $ExpectError + mod.main( 10, {}, 0, 1, 80, 1 ); // $ExpectError + mod.main( 10, ( x: number ): number => x, 0, 1, 80, 1 ); // $ExpectError +} + +// The compiler throws an error if the `main` method of a module instance is provided a third argument which is not a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = daxpy.Module( mem ); + + mod.main( 10, 5.0, '10', 1, 80, 1 ); // $ExpectError + mod.main( 10, 5.0, true, 1, 80, 1 ); // $ExpectError + mod.main( 10, 5.0, false, 1, 80, 1 ); // $ExpectError + mod.main( 10, 5.0, null, 1, 80, 1 ); // $ExpectError + mod.main( 10, 5.0, undefined, 1, 80, 1 ); // $ExpectError + mod.main( 10, 5.0, [], 1, 80, 1 ); // $ExpectError + mod.main( 10, 5.0, {}, 1, 80, 1 ); // $ExpectError + mod.main( 10, 5.0, ( x: number ): number => x, 1, 80, 1 ); // $ExpectError +} + +// The compiler throws an error if the `main` method of a module instance is provided a fourth argument which is not a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = daxpy.Module( mem ); + + mod.main( 10, 5.0, 0, '10', 80, 1 ); // $ExpectError + mod.main( 10, 5.0, 0, true, 80, 1 ); // $ExpectError + mod.main( 10, 5.0, 0, false, 80, 1 ); // $ExpectError + mod.main( 10, 5.0, 0, null, 80, 1 ); // $ExpectError + mod.main( 10, 5.0, 0, undefined, 80, 1 ); // $ExpectError + mod.main( 10, 5.0, 0, [], 80, 1 ); // $ExpectError + mod.main( 10, 5.0, 0, {}, 80, 1 ); // $ExpectError + mod.main( 10, 5.0, 0, ( x: number ): number => x, 80, 1 ); // $ExpectError +} + +// The compiler throws an error if the `main` method of a module instance is provided a fifth argument which is not a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = daxpy.Module( mem ); + + mod.main( 10, 5.0, 0, 1, '10', 1 ); // $ExpectError + mod.main( 10, 5.0, 0, 1, true, 1 ); // $ExpectError + mod.main( 10, 5.0, 0, 1, false, 1 ); // $ExpectError + mod.main( 10, 5.0, 0, 1, null, 1 ); // $ExpectError + mod.main( 10, 5.0, 0, 1, undefined, 1 ); // $ExpectError + mod.main( 10, 5.0, 0, 1, [], 1 ); // $ExpectError + mod.main( 10, 5.0, 0, 1, {}, 1 ); // $ExpectError + mod.main( 10, 5.0, 0, 1, ( x: number ): number => x, 1 ); // $ExpectError +} + +// The compiler throws an error if the `main` method of a module instance is provided a sixth argument which is not a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = daxpy.Module( mem ); + + mod.main( 10, 5.0, 0, 1, 80, '10' ); // $ExpectError + mod.main( 10, 5.0, 0, 1, 80, true ); // $ExpectError + mod.main( 10, 5.0, 0, 1, 80, false ); // $ExpectError + mod.main( 10, 5.0, 0, 1, 80, null ); // $ExpectError + mod.main( 10, 5.0, 0, 1, 80, undefined ); // $ExpectError + mod.main( 10, 5.0, 0, 1, 80, [] ); // $ExpectError + mod.main( 10, 5.0, 0, 1, 80, {} ); // $ExpectError + mod.main( 10, 5.0, 0, 1, 80, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `main` method of a module instance is provided an unsupported number of arguments... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = daxpy.Module( mem ); + + mod.main(); // $ExpectError + mod.main( 10 ); // $ExpectError + mod.main( 10, 5.0 ); // $ExpectError + mod.main( 10, 5.0, 0 ); // $ExpectError + mod.main( 10, 5.0, 0, 1 ); // $ExpectError + mod.main( 10, 5.0, 0, 1, 80 ); // $ExpectError + mod.main( 10, 5.0, 0, 1, 80, 1, 10 ); // $ExpectError +} + +// The `Module` constructor returns a module instance having an `ndarray` method which returns a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = daxpy.Module( mem ); + + mod.ndarray( 10, 5.0, 0, 1, 0, 80, 1, 0 ); // $ExpectType number +} + +// The compiler throws an error if the `ndarray` method of a module instance is provided a first argument which is not a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = daxpy.Module( mem ); + + mod.ndarray( '10', 5.0, 0, 1, 0, 80, 1, 0 ); // $ExpectError + mod.ndarray( true, 5.0, 0, 1, 0, 80, 1, 0 ); // $ExpectError + mod.ndarray( false, 5.0, 0, 1, 0, 80, 1, 0 ); // $ExpectError + mod.ndarray( null, 5.0, 0, 1, 0, 80, 1, 0 ); // $ExpectError + mod.ndarray( undefined, 5.0, 0, 1, 0, 80, 1, 0 ); // $ExpectError + mod.ndarray( [], 5.0, 0, 1, 0, 80, 1, 0 ); // $ExpectError + mod.ndarray( {}, 5.0, 0, 1, 0, 80, 1, 0 ); // $ExpectError + mod.ndarray( ( x: number ): number => x, 5.0, 0, 1, 0, 80, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method of a module instance is provided a second argument which is not a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = daxpy.Module( mem ); + + mod.ndarray( 10, '10', 0, 1, 0, 80, 1, 0 ); // $ExpectError + mod.ndarray( 10, true, 0, 1, 0, 80, 1, 0 ); // $ExpectError + mod.ndarray( 10, false, 0, 1, 0, 80, 1, 0 ); // $ExpectError + mod.ndarray( 10, null, 0, 1, 0, 80, 1, 0 ); // $ExpectError + mod.ndarray( 10, undefined, 0, 1, 0, 80, 1, 0 ); // $ExpectError + mod.ndarray( 10, [], 0, 1, 0, 80, 1, 0 ); // $ExpectError + mod.ndarray( 10, {}, 0, 1, 0, 80, 1, 0 ); // $ExpectError + mod.ndarray( 10, ( x: number ): number => x, 0, 1, 0, 80, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method of a module instance is provided a third argument which is not a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = daxpy.Module( mem ); + + mod.ndarray( 10, 5.0, '10', 1, 0, 80, 1, 0 ); // $ExpectError + mod.ndarray( 10, 5.0, true, 1, 0, 80, 1, 0 ); // $ExpectError + mod.ndarray( 10, 5.0, false, 1, 0, 80, 1, 0 ); // $ExpectError + mod.ndarray( 10, 5.0, null, 1, 0, 80, 1, 0 ); // $ExpectError + mod.ndarray( 10, 5.0, undefined, 1, 0, 80, 1, 0 ); // $ExpectError + mod.ndarray( 10, 5.0, [], 1, 0, 80, 1, 0 ); // $ExpectError + mod.ndarray( 10, 5.0, {}, 1, 0, 80, 1, 0 ); // $ExpectError + mod.ndarray( 10, 5.0, ( x: number ): number => x, 1, 0, 80, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method of a module instance is provided a fourth argument which is not a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = daxpy.Module( mem ); + + mod.ndarray( 10, 5.0, 0, '10', 0, 80, 1, 0 ); // $ExpectError + mod.ndarray( 10, 5.0, 0, true, 0, 80, 1, 0 ); // $ExpectError + mod.ndarray( 10, 5.0, 0, false, 0, 80, 1, 0 ); // $ExpectError + mod.ndarray( 10, 5.0, 0, null, 0, 80, 1, 0 ); // $ExpectError + mod.ndarray( 10, 5.0, 0, undefined, 0, 80, 1, 0 ); // $ExpectError + mod.ndarray( 10, 5.0, 0, [], 0, 80, 1, 0 ); // $ExpectError + mod.ndarray( 10, 5.0, 0, {}, 0, 80, 1, 0 ); // $ExpectError + mod.ndarray( 10, 5.0, 0, ( x: number ): number => x, 0, 80, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method of a module instance is provided a fifth argument which is not a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = daxpy.Module( mem ); + + mod.ndarray( 10, 5.0, 0, 1, '10', 80, 1, 0 ); // $ExpectError + mod.ndarray( 10, 5.0, 0, 1, true, 80, 1, 0 ); // $ExpectError + mod.ndarray( 10, 5.0, 0, 1, false, 80, 1, 0 ); // $ExpectError + mod.ndarray( 10, 5.0, 0, 1, null, 80, 1, 0 ); // $ExpectError + mod.ndarray( 10, 5.0, 0, 1, undefined, 80, 1, 0 ); // $ExpectError + mod.ndarray( 10, 5.0, 0, 1, [], 80, 1, 0 ); // $ExpectError + mod.ndarray( 10, 5.0, 0, 1, {}, 80, 1, 0 ); // $ExpectError + mod.ndarray( 10, 5.0, 0, 1, ( x: number ): number => x, 80, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method of a module instance is provided a sixth argument which is not a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = daxpy.Module( mem ); + + mod.ndarray( 10, 5.0, 0, 1, 0, '10', 1, 0 ); // $ExpectError + mod.ndarray( 10, 5.0, 0, 1, 0, true, 1, 0 ); // $ExpectError + mod.ndarray( 10, 5.0, 0, 1, 0, false, 1, 0 ); // $ExpectError + mod.ndarray( 10, 5.0, 0, 1, 0, null, 1, 0 ); // $ExpectError + mod.ndarray( 10, 5.0, 0, 1, 0, undefined, 1, 0 ); // $ExpectError + mod.ndarray( 10, 5.0, 0, 1, 0, [], 1, 0 ); // $ExpectError + mod.ndarray( 10, 5.0, 0, 1, 0, {}, 1, 0 ); // $ExpectError + mod.ndarray( 10, 5.0, 0, 1, 0, ( x: number ): number => x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method of a module instance is provided a seventh argument which is not a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = daxpy.Module( mem ); + + mod.ndarray( 10, 5.0, 0, 1, 0, 80, '10', 0 ); // $ExpectError + mod.ndarray( 10, 5.0, 0, 1, 0, 80, true, 0 ); // $ExpectError + mod.ndarray( 10, 5.0, 0, 1, 0, 80, false, 0 ); // $ExpectError + mod.ndarray( 10, 5.0, 0, 1, 0, 80, null, 0 ); // $ExpectError + mod.ndarray( 10, 5.0, 0, 1, 0, 80, undefined, 0 ); // $ExpectError + mod.ndarray( 10, 5.0, 0, 1, 0, 80, [], 0 ); // $ExpectError + mod.ndarray( 10, 5.0, 0, 1, 0, 80, {}, 0 ); // $ExpectError + mod.ndarray( 10, 5.0, 0, 1, 0, 80, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method of a module instance is provided an eighth argument which is not a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = daxpy.Module( mem ); + + mod.ndarray( 10, 5.0, 0, 1, 0, 80, 1, '10' ); // $ExpectError + mod.ndarray( 10, 5.0, 0, 1, 0, 80, 1, true ); // $ExpectError + mod.ndarray( 10, 5.0, 0, 1, 0, 80, 1, false ); // $ExpectError + mod.ndarray( 10, 5.0, 0, 1, 0, 80, 1, null ); // $ExpectError + mod.ndarray( 10, 5.0, 0, 1, 0, 80, 1, undefined ); // $ExpectError + mod.ndarray( 10, 5.0, 0, 1, 0, 80, 1, [] ); // $ExpectError + mod.ndarray( 10, 5.0, 0, 1, 0, 80, 1, {} ); // $ExpectError + mod.ndarray( 10, 5.0, 0, 1, 0, 80, 1, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method of a module instance is provided an unsupported number of arguments... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = daxpy.Module( mem ); + + mod.ndarray(); // $ExpectError + mod.ndarray( 10 ); // $ExpectError + mod.ndarray( 10, 5.0 ); // $ExpectError + mod.ndarray( 10, 5.0, 0 ); // $ExpectError + mod.ndarray( 10, 5.0, 0, 1 ); // $ExpectError + mod.ndarray( 10, 5.0, 0, 1, 0 ); // $ExpectError + mod.ndarray( 10, 5.0, 0, 1, 0, 80 ); // $ExpectError + mod.ndarray( 10, 5.0, 0, 1, 0, 80, 1 ); // $ExpectError + mod.ndarray( 10, 5.0, 0, 1, 0, 80, 1, 0, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/base/daxpy-wasm/examples/little_endian_arrays.js b/lib/node_modules/@stdlib/blas/base/daxpy-wasm/examples/little_endian_arrays.js new file mode 100644 index 00000000000..0075f1a58ef --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/daxpy-wasm/examples/little_endian_arrays.js @@ -0,0 +1,74 @@ +/** +* @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 hasWebAssemblySupport = require( '@stdlib/assert/has-wasm-support' ); +var Memory = require( '@stdlib/wasm/memory' ); +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory; +var gfill = require( '@stdlib/blas/ext/base/gfill' ); +var gfillBy = require( '@stdlib/blas/ext/base/gfill-by' ); +var bytesPerElement = require( '@stdlib/ndarray/base/bytes-per-element' ); +var Float64ArrayLE = require( '@stdlib/array/little-endian-float64' ); +var daxpy = require( './../lib' ); + +function main() { + if ( !hasWebAssemblySupport() ) { + console.error( 'Environment does not support WebAssembly.' ); + return; + } + // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): + var mem = new Memory({ + 'initial': 10, + 'maximum': 100 + }); + + // Create a BLAS routine: + var mod = new daxpy.Module( mem ); + // returns + + // Initialize the routine: + mod.initializeSync(); // eslint-disable-line node/no-sync + + // Define a vector data type: + var dtype = 'float64'; + + // Specify a vector length: + var N = 5; + + // Define pointers (i.e., byte offsets) for storing two vectors: + var xptr = 0; + var yptr = N * bytesPerElement( dtype ); + + // Create typed array views over module memory: + var x = new Float64ArrayLE( mod.memory.buffer, xptr, N ); + var y = new Float64ArrayLE( mod.memory.buffer, yptr, N ); + + // Write values to module memory: + gfillBy( N, x, 1, discreteUniform( -10.0, 10.0 ) ); + gfill( N, 1.0, y, 1 ); + + // Perform computation: + mod.ndarray( N, 5.0, xptr, 1, 0, yptr, 1, 0 ); + + // Print the results: + console.log( 'x[:] = [%s]', x.toString() ); + console.log( 'y[:] = [%s]', y.toString() ); +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/daxpy-wasm/lib/binary.browser.js b/lib/node_modules/@stdlib/blas/base/daxpy-wasm/lib/binary.browser.js new file mode 100644 index 00000000000..4b15b608184 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/daxpy-wasm/lib/binary.browser.js @@ -0,0 +1,33 @@ +/** +* @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 base64ToUint8Array = require( '@stdlib/string/base/base64-to-uint8array' ); + + +// MAIN // + +var wasm = base64ToUint8Array( 'AGFzbQEAAAAADwhkeWxpbmsuMAEEAAAAAAEYA2AAAGAGf3x/f39/AGAIf3x/f39/f38AAg8BA2VudgZtZW1vcnkCAAADBAMAAQIHTAQRX193YXNtX2NhbGxfY3RvcnMAABhfX3dhc21fYXBwbHlfZGF0YV9yZWxvY3MAAAdjX2RheHB5AAEPY19kYXhweV9uZGFycmF5AAIKmAIDAwABCz0BAn4gACABIAIgAyADrCIGQgEgAKwiB31+QgAgBkIAVxunIAQgBSAFrCIGQgEgB31+QgAgBkIAVxunEAIL0wEBBX8CQCAAQQBMDQAgAUQAAAAAAAAAAGENACAAQQFxIQkgAEEBRwRAIABB/v///wdxIQogBiAGaiELIAMgA2ohDEEAIQADQCAFIAdBA3RqIgggASACIARBA3RqKwMAoiAIKwMAoDkDACAFIAYgB2pBA3RqIgggASACIAMgBGpBA3RqKwMAoiAIKwMAoDkDACAHIAtqIQcgBCAMaiEEIABBAmoiACAKRw0ACwsgCUUNACAFIAdBA3RqIgAgASACIARBA3RqKwMAoiAAKwMAoDkDAAsL' ); + + +// EXPORTS // + +module.exports = wasm; diff --git a/lib/node_modules/@stdlib/blas/base/daxpy-wasm/package.json b/lib/node_modules/@stdlib/blas/base/daxpy-wasm/package.json index 791b3e4cc35..a0807ea6d7a 100644 --- a/lib/node_modules/@stdlib/blas/base/daxpy-wasm/package.json +++ b/lib/node_modules/@stdlib/blas/base/daxpy-wasm/package.json @@ -14,11 +14,15 @@ } ], "main": "./lib", + "browser": { + "./lib/binary.js": "./lib/binary.browser.js" + }, "directories": { "benchmark": "./benchmark", "doc": "./docs", "example": "./examples", "lib": "./lib", + "scripts": "./scripts", "src": "./src", "test": "./test" }, diff --git a/lib/node_modules/@stdlib/blas/base/daxpy-wasm/scripts/build.js b/lib/node_modules/@stdlib/blas/base/daxpy-wasm/scripts/build.js new file mode 100644 index 00000000000..348354d7029 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/daxpy-wasm/scripts/build.js @@ -0,0 +1,63 @@ +#!/usr/bin/env node + +/** +* @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 resolve = require( 'path' ).resolve; +var readFile = require( '@stdlib/fs/read-file' ).sync; +var writeFile = require( '@stdlib/fs/write-file' ).sync; +var replace = require( '@stdlib/string/replace' ); + + +// VARIABLES // + +var wpath = resolve( __dirname, '..', 'src', 'main.wasm' ); +var tpath = resolve( __dirname, 'template.txt' ); +var opath = resolve( __dirname, '..', 'lib', 'binary.browser.js' ); + +var opts = { + 'encoding': 'utf8' +}; + +var PLACEHOLDER = '{{WASM_BASE64}}'; + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var wasm; + var tmpl; + + wasm = readFile( wpath ); + tmpl = readFile( tpath, opts ); + + tmpl = replace( tmpl, PLACEHOLDER, wasm.toString( 'base64' ) ); + + writeFile( opath, tmpl, opts ); +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/daxpy-wasm/scripts/template.txt b/lib/node_modules/@stdlib/blas/base/daxpy-wasm/scripts/template.txt new file mode 100644 index 00000000000..12996dd89e3 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/daxpy-wasm/scripts/template.txt @@ -0,0 +1,33 @@ +/** +* @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 base64ToUint8Array = require( '@stdlib/string/base/base64-to-uint8array' ); + + +// MAIN // + +var wasm = base64ToUint8Array( '{{WASM_BASE64}}' ); + + +// EXPORTS // + +module.exports = wasm; diff --git a/lib/node_modules/@stdlib/blas/base/daxpy-wasm/src/Makefile b/lib/node_modules/@stdlib/blas/base/daxpy-wasm/src/Makefile index da6368a1087..1dd61310a79 100644 --- a/lib/node_modules/@stdlib/blas/base/daxpy-wasm/src/Makefile +++ b/lib/node_modules/@stdlib/blas/base/daxpy-wasm/src/Makefile @@ -73,6 +73,13 @@ else WASM_TO_JS := wasm2js endif +# Define the path to the Node.js executable: +ifdef NODE + NODEJS := $(NODE) +else + NODEJS := node +endif + # Define the command-line options when compiling C files: CFLAGS ?= \ -std=c99 \ @@ -115,6 +122,9 @@ wat_targets := main.wat # List of WebAssembly JavaScript targets: wasm_js_targets := main.wasm.js +# List of other JavaScript targets: +browser_js_targets := ./../lib/binary.browser.js + # RULES # @@ -155,7 +165,7 @@ all: wasm # @example # make wasm #/ -wasm: $(wasm_targets) $(wat_targets) +wasm: $(wasm_targets) $(wat_targets) $(browser_js_targets) .PHONY: wasm @@ -191,6 +201,15 @@ $(wat_targets): %.wat: %.wasm $(wasm_js_targets): %.wasm.js: %.wasm $(QUIET) $(WASM_TO_JS) -o $@ $(wasm_targets) +#/ +# Generates an inline WebAssembly build for use in bundlers. +# +# @private +# @param {string} NODE - Node.js executable +#/ +$(browser_js_targets): $(wasm_targets) + $(QUIET) $(NODEJS) ./../scripts/build.js + #/ # Removes generated WebAssembly files. # diff --git a/lib/node_modules/@stdlib/blas/base/daxpy-wasm/test/test.js b/lib/node_modules/@stdlib/blas/base/daxpy-wasm/test/test.js index ad0aa030d80..f9b282a9270 100644 --- a/lib/node_modules/@stdlib/blas/base/daxpy-wasm/test/test.js +++ b/lib/node_modules/@stdlib/blas/base/daxpy-wasm/test/test.js @@ -42,4 +42,12 @@ tape( 'attached to the main export is an `ndarray` method', function test( t ) { t.end(); }); -// TODO: add tests +tape( 'attached to the main export is a `Module` constructor', function test( t ) { + t.strictEqual( typeof daxpy.Module, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'the main export is a `Module` instance', function test( t ) { + t.strictEqual( daxpy instanceof daxpy.Module, true, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/daxpy-wasm/test/test.main.js b/lib/node_modules/@stdlib/blas/base/daxpy-wasm/test/test.main.js new file mode 100644 index 00000000000..6297d026b8f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/daxpy-wasm/test/test.main.js @@ -0,0 +1,284 @@ +/** +* @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 Float64Array = require( '@stdlib/array/float64' ); +var daxpy = require( './../lib' ); + + +// TESTS // + +tape( 'main export is an object', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof daxpy, 'object', 'main export is an object' ); + t.end(); +}); + +tape( 'the `main` method has an arity of 6', function test( t ) { + t.strictEqual( daxpy.main.length, 6, 'returns expected value' ); + t.end(); +}); + +tape( 'the `main` method multiplies `x` by a constant and adds the result to `y`', function test( t ) { + var expected; + var alpha; + var x; + var y; + + alpha = 2.0; + x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + y = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ); + + expected = new Float64Array( [ 3.0, 5.0, 7.0, 9.0, 11.0 ] ); + + daxpy.main( x.length, alpha, x, 1, y, 1 ); + + t.deepEqual( y, expected, 'returns expected value' ); + + // Short datasets: + x = new Float64Array( [ 1.0, 2.0 ] ); + y = new Float64Array( [ 1.0, 1.0 ] ); + + expected = new Float64Array( [ 3.0, 5.0 ] ); + + daxpy.main( x.length, alpha, x, 1, y, 1 ); + + t.deepEqual( y, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the `main` method efficiently handles the case where `alpha` is `0`', function test( t ) { + var expected; + var alpha; + var x; + var y; + + x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + y = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ); + alpha = 0.0; + + expected = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ); + + daxpy.main( x.length, alpha, x, 1, y, 1 ); + + t.deepEqual( y, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the `main` method supports an `x` stride', function test( t ) { + var expected; + var x; + var y; + var N; + + x = new Float64Array([ + 1.0, // 0 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 2 + ]); + y = new Float64Array([ + 1.0, // 0 + 1.0, // 1 + 1.0, // 2 + 1.0, + 1.0 + ]); + N = 3; + + daxpy.main( N, 2.0, x, 2, y, 1 ); + + expected = new Float64Array( [ 3.0, 7.0, 11.0, 1.0, 1.0 ] ); + + t.deepEqual( y, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the `main` method supports a `y` stride', function test( t ) { + var expected; + var x; + var y; + var N; + + x = new Float64Array([ + 1.0, // 0 + 2.0, // 1 + 3.0, // 2 + 4.0, + 5.0 + ]); + y = new Float64Array([ + 1.0, // 0 + 1.0, + 1.0, // 1 + 1.0, + 1.0 // 2 + ]); + N = 3; + + daxpy.main( N, 2.0, x, 1, y, 2 ); + + expected = new Float64Array( [ 3.0, 1.0, 5.0, 1.0, 7.0 ] ); + + t.deepEqual( y, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the `main` method returns a reference to the output array', function test( t ) { + var out; + var x; + var y; + + x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + y = new Float64Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); + + out = daxpy.main( x.length, 3.0, x, 1, y, 1 ); + + t.strictEqual( out, y, 'same reference' ); + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the `main` method returns the output array unchanged', function test( t ) { + var expected; + var x; + var y; + + x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + y = new Float64Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); + + expected = new Float64Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); + + daxpy.main( -1, 3.0, x, 1, y, 1 ); + t.deepEqual( y, expected, 'returns expected value' ); + + daxpy.main( 0, 3.0, x, 1, y, 1 ); + t.deepEqual( y, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the `main` method supports negative strides', function test( t ) { + var expected; + var x; + var y; + var N; + + x = new Float64Array([ + 1.0, // 2 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 0 + ]); + y = new Float64Array([ + 6.0, // 2 + 7.0, // 1 + 8.0, // 0 + 9.0, + 10.0 + ]); + N = 3; + + daxpy.main( N, 3.0, x, -2, y, -1 ); + + expected = new Float64Array( [ 9.0, 16.0, 23.0, 9.0, 10.0 ] ); + + t.deepEqual( y, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the `main` method supports complex access patterns', function test( t ) { + var expected; + var x; + var y; + var N; + + x = new Float64Array([ + 1.0, // 0 + 2.0, + 3.0, // 1 + 4.0, + 5.0, // 2 + 6.0 + ]); + y = new Float64Array([ + 7.0, // 2 + 8.0, // 1 + 9.0, // 0 + 10.0, + 11.0, + 12.0 + ]); + N = 3; + + daxpy.main( N, 3.0, x, 2, y, -1 ); + + expected = new Float64Array( [ 22.0, 17.0, 12.0, 10.0, 11.0, 12.0 ] ); + + t.deepEqual( y, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the `main` method supports view offsets', function test( t ) { + var expected; + var x0; + var y0; + var x1; + var y1; + + // Initial arrays... + x0 = new Float64Array([ + 1.0, + 2.0, // 2 + 3.0, + 4.0, // 1 + 5.0, + 6.0 // 0 + ]); + y0 = new Float64Array([ + 7.0, + 8.0, + 9.0, + 10.0, // 0 + 11.0, // 1 + 12.0 // 2 + ]); + + // Create offset views... + x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // begin at 2nd element + y1 = new Float64Array( y0.buffer, y0.BYTES_PER_ELEMENT*3 ); // begin at the 4th element + + daxpy.main( 3, 3.0, x1, -2, y1, 1 ); + expected = new Float64Array([ + 7.0, + 8.0, + 9.0, + 28.0, + 23.0, + 18.0 + ]); + + t.deepEqual( y0, expected, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/daxpy-wasm/test/test.module.js b/lib/node_modules/@stdlib/blas/base/daxpy-wasm/test/test.module.js new file mode 100644 index 00000000000..9adcb07e22f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/daxpy-wasm/test/test.module.js @@ -0,0 +1,154 @@ +/** +* @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 Memory = require( '@stdlib/wasm/memory' ); +var ModuleWrapper = require( '@stdlib/wasm/module-wrapper' ); +var Module = require( './../lib' ).Module; + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Module, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'the function is a constructor', function test( t ) { + var mem; + var mod; + + mem = new Memory({ + 'initial': 0 + }); + mod = new Module( mem ); + t.strictEqual( mod instanceof Module, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function is a constructor which does not require `new`', function test( t ) { + var mem; + var mod; + + mem = new Memory({ + 'initial': 0 + }); + mod = Module( mem ); // eslint-disable-line new-cap + t.strictEqual( mod instanceof Module, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the module constructor throws an error if provided a first argument which is not a WebAssembly memory instance (new)', 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() { + return new Module( value ); + }; + } +}); + +tape( 'the module constructor throws an error if provided a first argument which is not a WebAssembly memory instance (no new)', 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() { + return Module( value ); // eslint-disable-line new-cap + }; + } +}); + +tape( 'the module instance returned by the module constructor inherits from a module wrapper', function test( t ) { + var mem; + var mod; + + mem = new Memory({ + 'initial': 0 + }); + mod = new Module( mem ); + + t.strictEqual( mod instanceof ModuleWrapper, true, 'returns expected value' ); + t.end(); +}); + +tape( 'attached to a module instance is a `main` method', function test( t ) { + var mem; + var mod; + + mem = new Memory({ + 'initial': 0 + }); + mod = new Module( mem ); + + t.strictEqual( typeof mod.main, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'attached to a module instance is an `ndarray` method', function test( t ) { + var mem; + var mod; + + mem = new Memory({ + 'initial': 0 + }); + mod = new Module( mem ); + + t.strictEqual( typeof mod.ndarray, 'function', 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/daxpy-wasm/test/test.module.main.js b/lib/node_modules/@stdlib/blas/base/daxpy-wasm/test/test.module.main.js new file mode 100644 index 00000000000..37a0073f558 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/daxpy-wasm/test/test.module.main.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. +*/ + +/* eslint-disable node/no-sync */ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var Memory = require( '@stdlib/wasm/memory' ); +var Float64Array = require( '@stdlib/array/float64' ); +var Module = require( './../lib' ).Module; + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Module, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'a module instance has a `main` method which has an arity of 6', function test( t ) { + var mem; + var mod; + + mem = new Memory({ + 'initial': 0 + }); + mod = new Module( mem ); + t.strictEqual( mod.main.length, 6, 'returns expected value' ); + t.end(); +}); + +tape( 'a module instance has a `main` method which multiplies `x` by a constant and adds the result to `y`', function test( t ) { + var expected; + var actual; + var mem; + var mod; + var xp; + var yp; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + yp = 40; + + mod.write( xp, new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ) ); + mod.write( yp, new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ) ); + + expected = new Float64Array( [ 3.0, 5.0, 7.0, 9.0, 11.0 ] ); + + mod.main( 5, 2.0, xp, 1, yp, 1 ); + + actual = new Float64Array( 5 ); + mod.read( yp, actual ); + t.deepEqual( actual, expected, 'returns expected value' ); + + // Short datasets: + xp = 0; + yp = 16; + + mod.write( xp, new Float64Array( [ 1.0, 2.0 ] ) ); + mod.write( yp, new Float64Array( [ 1.0, 1.0 ] ) ); + + expected = new Float64Array( [ 3.0, 5.0 ] ); + + mod.main( 2, 2.0, xp, 1, yp, 1 ); + + actual = new Float64Array( 2 ); + mod.read( yp, actual ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'a module instance has a `main` method which efficiently handles the case where `alpha` is `0`', function test( t ) { + var expected; + var actual; + var mem; + var mod; + var xp; + var yp; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + yp = 40; + + mod.write( xp, new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ) ); + mod.write( yp, new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ) ); + + expected = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ); + + mod.main( 5, 0.0, xp, 1, yp, 1 ); + + actual = new Float64Array( 5 ); + mod.read( yp, actual ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'a module instance has a `main` method which supports an `x` stride', function test( t ) { + var expected; + var actual; + var mem; + var mod; + var xp; + var yp; + var N; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + yp = 40; + + mod.write( xp, new Float64Array([ + 1.0, // 0 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 2 + ])); + mod.write( yp, new Float64Array([ + 1.0, // 0 + 1.0, // 1 + 1.0, // 2 + 1.0, + 1.0 + ])); + N = 3; + + mod.main( N, 2.0, xp, 2, yp, 1 ); + + expected = new Float64Array( [ 3.0, 7.0, 11.0, 1.0, 1.0 ] ); + + actual = new Float64Array( 5 ); + mod.read( yp, actual ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'a module instance has a `main` method which supports a `y` stride', function test( t ) { + var expected; + var actual; + var mem; + var mod; + var xp; + var yp; + var N; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + yp = 40; + + mod.write( xp, new Float64Array([ + 1.0, // 0 + 2.0, // 1 + 3.0, // 2 + 4.0, + 5.0 + ])); + mod.write( yp, new Float64Array([ + 1.0, // 0 + 1.0, + 1.0, // 1 + 1.0, + 1.0 // 2 + ])); + N = 3; + + mod.main( N, 2.0, xp, 1, yp, 2 ); + + expected = new Float64Array( [ 3.0, 1.0, 5.0, 1.0, 7.0 ] ); + + actual = new Float64Array( 5 ); + mod.read( yp, actual ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'a module instance has a `main` method which returns a pointer to the output array', function test( t ) { + var out; + var mem; + var mod; + var xp; + var yp; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + yp = 40; + + mod.write( xp, new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ) ); + mod.write( yp, new Float64Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ) ); + + out = mod.main( 5, 3.0, xp, 1, yp, 1 ); + + t.strictEqual( out, yp, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, a module instance has a `main` method which leaves the output array unchanged', function test( t ) { + var expected; + var actual; + var mem; + var mod; + var xp; + var yp; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + yp = 40; + + mod.write( xp, new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ) ); + mod.write( yp, new Float64Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ) ); + + expected = new Float64Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); + + mod.main( -1, 3.0, xp, 1, yp, 1 ); + actual = new Float64Array( 5 ); + mod.read( yp, actual ); + t.deepEqual( actual, expected, 'returns expected value' ); + + mod.main( 0, 3.0, xp, 1, yp, 1 ); + actual = new Float64Array( 5 ); + mod.read( yp, actual ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'a module instance has a `main` method which supports negative strides', function test( t ) { + var expected; + var actual; + var mem; + var mod; + var xp; + var yp; + var N; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + yp = 40; + + mod.write( xp, new Float64Array([ + 1.0, // 2 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 0 + ])); + mod.write( yp, new Float64Array([ + 6.0, // 2 + 7.0, // 1 + 8.0, // 0 + 9.0, + 10.0 + ])); + N = 3; + + mod.main( N, 3.0, xp, -2, yp, -1 ); + + expected = new Float64Array( [ 9.0, 16.0, 23.0, 9.0, 10.0 ] ); + + actual = new Float64Array( 5 ); + mod.read( yp, actual ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'a module instance has a `main` method which supports complex access patterns', function test( t ) { + var expected; + var actual; + var mem; + var mod; + var xp; + var yp; + var N; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + yp = 48; + + mod.write( xp, new Float64Array([ + 1.0, // 0 + 2.0, + 3.0, // 1 + 4.0, + 5.0, // 2 + 6.0 + ])); + mod.write( 48, new Float64Array([ + 7.0, // 2 + 8.0, // 1 + 9.0, // 0 + 10.0, + 11.0, + 12.0 + ])); + N = 3; + + mod.main( N, 3.0, xp, 2, yp, -1 ); + + expected = new Float64Array( [ 22.0, 17.0, 12.0, 10.0, 11.0, 12.0 ] ); + + actual = new Float64Array( 6 ); + mod.read( yp, actual ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/daxpy-wasm/test/test.module.ndarray.js b/lib/node_modules/@stdlib/blas/base/daxpy-wasm/test/test.module.ndarray.js new file mode 100644 index 00000000000..c2db815a3e3 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/daxpy-wasm/test/test.module.ndarray.js @@ -0,0 +1,458 @@ +/** +* @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. +*/ + +/* eslint-disable node/no-sync */ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var Memory = require( '@stdlib/wasm/memory' ); +var Float64Array = require( '@stdlib/array/float64' ); +var Module = require( './../lib' ).Module; + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Module, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'a module instance has an `ndarray` method which has an arity of 8', function test( t ) { + var mem; + var mod; + + mem = new Memory({ + 'initial': 0 + }); + mod = new Module( mem ); + t.strictEqual( mod.ndarray.length, 8, 'returns expected value' ); + t.end(); +}); + +tape( 'a module instance has an `ndarray` method which multiplies `x` by a constant and adds the result to `y`', function test( t ) { + var expected; + var actual; + var mem; + var mod; + var xp; + var yp; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + yp = 40; + + mod.write( xp, new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ) ); + mod.write( yp, new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ) ); + + expected = new Float64Array( [ 3.0, 5.0, 7.0, 9.0, 11.0 ] ); + + mod.ndarray( 5, 2.0, xp, 1, 0, yp, 1, 0 ); + + actual = new Float64Array( 5 ); + mod.read( yp, actual ); + t.deepEqual( actual, expected, 'returns expected value' ); + + // Short datasets: + xp = 0; + yp = 16; + + mod.write( xp, new Float64Array( [ 1.0, 2.0 ] ) ); + mod.write( yp, new Float64Array( [ 1.0, 1.0 ] ) ); + + expected = new Float64Array( [ 3.0, 5.0 ] ); + + mod.ndarray( 2, 2.0, xp, 1, 0, yp, 1, 0 ); + + actual = new Float64Array( 2 ); + mod.read( yp, actual ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'a module instance has an `ndarray` method which efficiently handles the case where `alpha` is `0`', function test( t ) { + var expected; + var actual; + var mem; + var mod; + var xp; + var yp; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + yp = 40; + + mod.write( xp, new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ) ); + mod.write( yp, new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ) ); + + expected = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ); + + mod.ndarray( 5, 0.0, xp, 1, 0, yp, 1, 0 ); + + actual = new Float64Array( 5 ); + mod.read( yp, actual ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'a module instance has an `ndarray` method which supports an `x` stride', function test( t ) { + var expected; + var actual; + var mem; + var mod; + var xp; + var yp; + var N; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + yp = 40; + + mod.write( xp, new Float64Array([ + 1.0, // 0 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 2 + ])); + mod.write( yp, new Float64Array([ + 1.0, // 0 + 1.0, // 1 + 1.0, // 2 + 1.0, + 1.0 + ])); + N = 3; + + mod.ndarray( N, 2.0, xp, 2, 0, yp, 1, 0 ); + + expected = new Float64Array( [ 3.0, 7.0, 11.0, 1.0, 1.0 ] ); + + actual = new Float64Array( 5 ); + mod.read( yp, actual ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'a module instance has an `ndarray` method which supports an `x` offset', function test( t ) { + var expected; + var actual; + var mem; + var mod; + var xp; + var yp; + var N; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + yp = 40; + + mod.write( xp, new Float64Array([ + 1.0, + 2.0, + 3.0, // 0 + 4.0, // 1 + 5.0 // 2 + ])); + mod.write( yp, new Float64Array([ + 6.0, // 0 + 7.0, // 1 + 8.0, // 2 + 9.0, + 10.0 + ])); + N = 3; + + mod.ndarray( N, 3.0, xp, 1, 2, yp, 1, 0 ); + + expected = new Float64Array( [ 15.0, 19.0, 23.0, 9.0, 10.0 ] ); + + actual = new Float64Array( 5 ); + mod.read( yp, actual ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'a module instance has an `ndarray` method which supports a `y` stride', function test( t ) { + var expected; + var actual; + var mem; + var mod; + var xp; + var yp; + var N; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + yp = 40; + + mod.write( xp, new Float64Array([ + 1.0, // 0 + 2.0, // 1 + 3.0, // 2 + 4.0, + 5.0 + ])); + mod.write( yp, new Float64Array([ + 1.0, // 0 + 1.0, + 1.0, // 1 + 1.0, + 1.0 // 2 + ])); + N = 3; + + mod.ndarray( N, 2.0, xp, 1, 0, yp, 2, 0 ); + + expected = new Float64Array( [ 3.0, 1.0, 5.0, 1.0, 7.0 ] ); + + actual = new Float64Array( 5 ); + mod.read( yp, actual ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'a module instance has an `ndarray` method which supports a `y` offset', function test( t ) { + var expected; + var actual; + var mem; + var mod; + var xp; + var yp; + var N; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + yp = 40; + + mod.write( xp, new Float64Array([ + 1.0, // 0 + 2.0, // 1 + 3.0, // 2 + 4.0, + 5.0 + ])); + mod.write( yp, new Float64Array([ + 6.0, + 7.0, + 8.0, // 0 + 9.0, // 1 + 10.0 // 2 + ])); + N = 3; + + mod.ndarray( N, 3.0, xp, 1, 0, yp, 1, 2 ); + + expected = new Float64Array( [ 6.0, 7.0, 11.0, 15.0, 19.0 ] ); + + actual = new Float64Array( 5 ); + mod.read( yp, actual ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'a module instance has an `ndarray` method which returns a pointer to the output array', function test( t ) { + var out; + var mem; + var mod; + var xp; + var yp; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + yp = 40; + + mod.write( xp, new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ) ); + mod.write( yp, new Float64Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ) ); + + out = mod.ndarray( 5, 3.0, xp, 1, 0, yp, 1, 0 ); + + t.strictEqual( out, yp, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, a module instance has an `ndarray` method which leaves the output array unchanged', function test( t ) { + var expected; + var actual; + var mem; + var mod; + var xp; + var yp; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + yp = 40; + + mod.write( xp, new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ) ); + mod.write( yp, new Float64Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ) ); + + expected = new Float64Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); + + mod.ndarray( -1, 3.0, xp, 1, 0, yp, 1, 0 ); + actual = new Float64Array( 5 ); + mod.read( yp, actual ); + t.deepEqual( actual, expected, 'returns expected value' ); + + mod.ndarray( 0, 3.0, xp, 1, 0, yp, 1, 0 ); + actual = new Float64Array( 5 ); + mod.read( yp, actual ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'a module instance has an `ndarray` method which supports negative strides', function test( t ) { + var expected; + var actual; + var mem; + var mod; + var xp; + var yp; + var N; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + yp = 40; + + mod.write( xp, new Float64Array([ + 1.0, // 2 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 0 + ])); + mod.write( yp, new Float64Array([ + 6.0, // 2 + 7.0, // 1 + 8.0, // 0 + 9.0, + 10.0 + ])); + N = 3; + + mod.ndarray( N, 3.0, xp, -2, 4, yp, -1, 2 ); + + expected = new Float64Array( [ 9.0, 16.0, 23.0, 9.0, 10.0 ] ); + + actual = new Float64Array( 5 ); + mod.read( yp, actual ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'a module instance has an `ndarray` method which supports complex access patterns', function test( t ) { + var expected; + var actual; + var mem; + var mod; + var xp; + var yp; + var N; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + yp = 48; + + mod.write( xp, new Float64Array([ + 1.0, // 0 + 2.0, + 3.0, // 1 + 4.0, + 5.0, // 2 + 6.0 + ])); + mod.write( yp, new Float64Array([ + 7.0, // 2 + 8.0, // 1 + 9.0, // 0 + 10.0, + 11.0, + 12.0 + ])); + N = 3; + + mod.ndarray( N, 3.0, xp, 2, 0, yp, -1, 2 ); + + expected = new Float64Array( [ 22.0, 17.0, 12.0, 10.0, 11.0, 12.0 ] ); + + actual = new Float64Array( 6 ); + mod.read( yp, actual ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/daxpy-wasm/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/base/daxpy-wasm/test/test.ndarray.js new file mode 100644 index 00000000000..a3ab8d98624 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/daxpy-wasm/test/test.ndarray.js @@ -0,0 +1,301 @@ +/** +* @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 Float64Array = require( '@stdlib/array/float64' ); +var daxpy = require( './../lib' ); + + +// TESTS // + +tape( 'main export is an object', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof daxpy, 'object', 'main export is an object' ); + t.end(); +}); + +tape( 'the `ndarray` method has an arity of 8', function test( t ) { + t.strictEqual( daxpy.ndarray.length, 8, 'returns expected value' ); + t.end(); +}); + +tape( 'the `ndarray` method multiplies `x` by a constant and adds the result to `y`', function test( t ) { + var expected; + var alpha; + var x; + var y; + + alpha = 2.0; + x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + y = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ); + + expected = new Float64Array( [ 3.0, 5.0, 7.0, 9.0, 11.0 ] ); + + daxpy.ndarray( x.length, alpha, x, 1, 0, y, 1, 0 ); + + t.deepEqual( y, expected, 'returns expected value' ); + + // Short datasets: + x = new Float64Array( [ 1.0, 2.0 ] ); + y = new Float64Array( [ 1.0, 1.0 ] ); + + expected = new Float64Array( [ 3.0, 5.0 ] ); + + daxpy.ndarray( x.length, alpha, x, 1, 0, y, 1, 0 ); + + t.deepEqual( y, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the `ndarray` method efficiently handles the case where `alpha` is `0`', function test( t ) { + var expected; + var alpha; + var x; + var y; + + x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + y = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ); + alpha = 0.0; + + expected = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ); + + daxpy.ndarray( x.length, alpha, x, 1, 0, y, 1, 0 ); + + t.deepEqual( y, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the `ndarray` method supports an `x` stride', function test( t ) { + var expected; + var x; + var y; + var N; + + x = new Float64Array([ + 1.0, // 0 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 2 + ]); + y = new Float64Array([ + 1.0, // 0 + 1.0, // 1 + 1.0, // 2 + 1.0, + 1.0 + ]); + N = 3; + + daxpy.ndarray( N, 2.0, x, 2, 0, y, 1, 0 ); + + expected = new Float64Array( [ 3.0, 7.0, 11.0, 1.0, 1.0 ] ); + + t.deepEqual( y, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the `ndarray` method supports an `x` offset', function test( t ) { + var expected; + var x; + var y; + var N; + + x = new Float64Array([ + 1.0, + 2.0, + 3.0, // 0 + 4.0, // 1 + 5.0 // 2 + ]); + y = new Float64Array([ + 6.0, // 0 + 7.0, // 1 + 8.0, // 2 + 9.0, + 10.0 + ]); + N = 3; + + daxpy.ndarray( N, 3.0, x, 1, 2, y, 1, 0 ); + + expected = new Float64Array( [ 15.0, 19.0, 23.0, 9.0, 10.0 ] ); + + t.deepEqual( y, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the `ndarray` method supports a `y` stride', function test( t ) { + var expected; + var x; + var y; + var N; + + x = new Float64Array([ + 1.0, // 0 + 2.0, // 1 + 3.0, // 2 + 4.0, + 5.0 + ]); + y = new Float64Array([ + 1.0, // 0 + 1.0, + 1.0, // 1 + 1.0, + 1.0 // 2 + ]); + N = 3; + + daxpy.ndarray( N, 2.0, x, 1, 0, y, 2, 0 ); + + expected = new Float64Array( [ 3.0, 1.0, 5.0, 1.0, 7.0 ] ); + + t.deepEqual( y, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the `ndarray` method supports a `y` offset', function test( t ) { + var expected; + var x; + var y; + var N; + + x = new Float64Array([ + 1.0, // 0 + 2.0, // 1 + 3.0, // 2 + 4.0, + 5.0 + ]); + y = new Float64Array([ + 6.0, + 7.0, + 8.0, // 0 + 9.0, // 1 + 10.0 // 2 + ]); + N = 3; + + daxpy.ndarray( N, 3.0, x, 1, 0, y, 1, 2 ); + + expected = new Float64Array( [ 6.0, 7.0, 11.0, 15.0, 19.0 ] ); + + t.deepEqual( y, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the `ndarray` method returns a reference to the output array', function test( t ) { + var out; + var x; + var y; + + x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + y = new Float64Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); + + out = daxpy.ndarray( x.length, 3.0, x, 1, 0, y, 1, 0 ); + + t.strictEqual( out, y, 'same reference' ); + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the `ndarray` method returns the output array unchanged', function test( t ) { + var expected; + var x; + var y; + + x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + y = new Float64Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); + + expected = new Float64Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); + + daxpy.ndarray( -1, 3.0, x, 1, 0, y, 1, 0 ); + t.deepEqual( y, expected, 'returns expected value' ); + + daxpy.ndarray( 0, 3.0, x, 1, 0, y, 1, 0 ); + t.deepEqual( y, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the `ndarray` method supports negative strides', function test( t ) { + var expected; + var x; + var y; + var N; + + x = new Float64Array([ + 1.0, // 2 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 0 + ]); + y = new Float64Array([ + 6.0, + 7.0, // 2 + 8.0, // 1 + 9.0, // 0 + 10.0 + ]); + N = 3; + + daxpy.ndarray( N, 3.0, x, -2, x.length-1, y, -1, y.length-2 ); + + expected = new Float64Array( [ 6.0, 10.0, 17.0, 24.0, 10.0 ] ); + + t.deepEqual( y, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the `ndarray` method supports complex access patterns', function test( t ) { + var expected; + var x; + var y; + var N; + + x = new Float64Array([ + 1.0, + 2.0, // 0 + 3.0, + 4.0, // 1 + 5.0, + 6.0 // 2 + ]); + y = new Float64Array([ + 7.0, + 8.0, + 9.0, + 10.0, // 2 + 11.0, // 1 + 12.0 // 0 + ]); + N = 3; + + daxpy.ndarray( N, 3.0, x, 2, 1, y, -1, y.length-1 ); + + expected = new Float64Array( [ 7.0, 8.0, 9.0, 28.0, 23.0, 18.0 ] ); + + t.deepEqual( y, expected, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/daxpy-wasm/test/test.routine.js b/lib/node_modules/@stdlib/blas/base/daxpy-wasm/test/test.routine.js new file mode 100644 index 00000000000..56a4b67daaf --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/daxpy-wasm/test/test.routine.js @@ -0,0 +1,71 @@ +/** +* @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 ModuleWrapper = require( '@stdlib/wasm/module-wrapper' ); +var Module = require( './../lib/module.js' ); +var Routine = require( './../lib/routine.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Routine, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'the function is a constructor', function test( t ) { + var mod = new Routine(); + t.strictEqual( mod instanceof Routine, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function is a constructor which does not require `new`', function test( t ) { + var mod = Routine(); // eslint-disable-line new-cap + t.strictEqual( mod instanceof Routine, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the module instance returned by the constructor inherits from a module wrapper', function test( t ) { + var mod = new Routine(); + t.strictEqual( mod instanceof ModuleWrapper, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the module instance returned by the constructor inherits from a BLAS routine module', function test( t ) { + var mod = new Routine(); + t.strictEqual( mod instanceof Module, true, 'returns expected value' ); + t.end(); +}); + +tape( 'attached to a module instance is a `main` method', function test( t ) { + var mod = new Routine(); + t.strictEqual( typeof mod.main, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'attached to a module instance is an `ndarray` method', function test( t ) { + var mod = new Routine(); + t.strictEqual( typeof mod.ndarray, 'function', 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/daxpy/lib/daxpy.js b/lib/node_modules/@stdlib/blas/base/daxpy/lib/daxpy.js index ec77f854553..482ff61542f 100644 --- a/lib/node_modules/@stdlib/blas/base/daxpy/lib/daxpy.js +++ b/lib/node_modules/@stdlib/blas/base/daxpy/lib/daxpy.js @@ -21,7 +21,7 @@ // MODULES // var stride2offset = require( '@stdlib/strided/base/stride2offset' ); -var ndarray = require('./ndarray.js'); +var ndarray = require( './ndarray.js' ); // MAIN // diff --git a/lib/node_modules/@stdlib/blas/base/ddot/README.md b/lib/node_modules/@stdlib/blas/base/ddot/README.md index badb6a89ca6..90b7023547a 100644 --- a/lib/node_modules/@stdlib/blas/base/ddot/README.md +++ b/lib/node_modules/@stdlib/blas/base/ddot/README.md @@ -227,6 +227,32 @@ The function accepts the following arguments: double c_ddot( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, const double *Y, const CBLAS_INT strideY ); ``` +#### c_ddot_ndarray( N, \*X, strideX, offsetX, \*Y, strideY, offsetY ) + +Computes the dot product of two double-precision floating-point vectors using alternative indexing semantics. + +```c +const double x[] = { 4.0, 2.0, -3.0, 5.0, -1.0 }; +const double y[] = { 2.0, 6.0, -1.0, -4.0, 8.0 }; + +double v = c_ddot_ndarray( 5, x, -1, 4, y, -1, 4 ); +// returns -5.0 +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **X**: `[in] double*` first input array. +- **strideX**: `[in] CBLAS_INT` index increment for `X`. +- **offsetX**: `[in] CBLAS_INT` starting index for `X`. +- **Y**: `[in] double*` second input array. +- **strideY**: `[in] CBLAS_INT` index increment for `Y`. +- **offsetY**: `[in] CBLAS_INT` starting index for `Y`. + +```c +double c_ddot_ndarray( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, const double *Y, const CBLAS_INT strideY. const CBLAS_INT offsetY ); +``` + @@ -266,6 +292,12 @@ int main( void ) { // Print the result: printf( "dot product: %lf\n", d ); + + // Compute the dot product: + d = c_ddot_ndarray( N, x, strideX, 0, y, strideY, N-1 ); + + // Print the result: + printf( "dot product: %lf\n", d ); } ``` diff --git a/lib/node_modules/@stdlib/blas/base/ddot/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/blas/base/ddot/benchmark/c/benchmark.length.c index 91cbd2012cc..362d7489ecc 100644 --- a/lib/node_modules/@stdlib/blas/base/ddot/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/blas/base/ddot/benchmark/c/benchmark.length.c @@ -94,7 +94,7 @@ static double rand_double( void ) { * @param len array length * @return elapsed time in seconds */ -static double benchmark( int iterations, int len ) { +static double benchmark1( int iterations, int len ) { double elapsed; double x[ len ]; double y[ len ]; @@ -122,6 +122,41 @@ static double benchmark( int iterations, int len ) { return elapsed; } +/** +* Runs a benchmark. +* +* @param iterations number of iterations +* @param len array length +* @return elapsed time in seconds +*/ +static double benchmark2( int iterations, int len ) { + double elapsed; + double x[ len ]; + double y[ len ]; + double z; + double t; + int i; + + for ( i = 0; i < len; i++ ) { + x[ i ] = ( rand_double()*20000.0 ) - 10000.0; + y[ i ] = ( rand_double()*20000.0 ) - 10000.0; + } + z = 0.0; + t = tic(); + for ( i = 0; i < iterations; i++ ) { + z = c_ddot_ndarray( len, x, 1, 0, y, 1, 0 ); + if ( z != z ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( z != z ) { + printf( "should not return NaN\n" ); + } + return elapsed; +} + /** * Main execution sequence. */ @@ -144,7 +179,14 @@ int main( void ) { for ( j = 0; j < REPEATS; j++ ) { count += 1; printf( "# c::%s:len=%d\n", NAME, len ); - elapsed = benchmark( iter, len ); + elapsed = benchmark1( iter, len ); + print_results( iter, elapsed ); + printf( "ok %d benchmark finished\n", count ); + } + for ( j = 0; j < REPEATS; j++ ) { + count += 1; + printf( "# c::%s:ndarray:len=%d\n", NAME, len ); + elapsed = benchmark2( iter, len ); print_results( iter, elapsed ); printf( "ok %d benchmark finished\n", count ); } diff --git a/lib/node_modules/@stdlib/blas/base/ddot/examples/c/example.c b/lib/node_modules/@stdlib/blas/base/ddot/examples/c/example.c index c205020189c..99cc7e8154a 100644 --- a/lib/node_modules/@stdlib/blas/base/ddot/examples/c/example.c +++ b/lib/node_modules/@stdlib/blas/base/ddot/examples/c/example.c @@ -36,4 +36,10 @@ int main( void ) { // Print the result: printf( "dot product: %lf\n", d ); + + // Compute the dot product: + d = c_ddot_ndarray( N, x, strideX, 0, y, strideY, N-1 ); + + // Print the result: + printf( "dot product: %lf\n", d ); } diff --git a/lib/node_modules/@stdlib/blas/base/ddot/include/stdlib/blas/base/ddot.h b/lib/node_modules/@stdlib/blas/base/ddot/include/stdlib/blas/base/ddot.h index 2368577ec4b..beb870a066d 100644 --- a/lib/node_modules/@stdlib/blas/base/ddot/include/stdlib/blas/base/ddot.h +++ b/lib/node_modules/@stdlib/blas/base/ddot/include/stdlib/blas/base/ddot.h @@ -36,6 +36,11 @@ extern "C" { */ double API_SUFFIX(c_ddot)( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, const double *Y, const CBLAS_INT strideY ); +/** +* Computes the dot product of two double-precision floating-point vectors using alternative indexing semantics. +*/ +double API_SUFFIX(c_ddot_ndarray)( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, const double *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY ); + #ifdef __cplusplus } #endif diff --git a/lib/node_modules/@stdlib/blas/base/ddot/lib/ndarray.native.js b/lib/node_modules/@stdlib/blas/base/ddot/lib/ndarray.native.js index e22d18098d9..1bdf27f0ed1 100644 --- a/lib/node_modules/@stdlib/blas/base/ddot/lib/ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/base/ddot/lib/ndarray.native.js @@ -20,9 +20,7 @@ // MODULES // -var minViewBufferIndex = require( '@stdlib/strided/base/min-view-buffer-index' ); -var offsetView = require( '@stdlib/strided/base/offset-view' ); -var addon = require( './ddot.native.js' ); +var addon = require( './../src/addon.node' ); // MAIN // @@ -49,16 +47,7 @@ var addon = require( './ddot.native.js' ); * // returns -5.0 */ function ddot( N, x, strideX, offsetX, y, strideY, offsetY ) { - var viewX; - var viewY; - - offsetX = minViewBufferIndex( N, strideX, offsetX ); - offsetY = minViewBufferIndex( N, strideY, offsetY ); - - viewX = offsetView( x, offsetX ); - viewY = offsetView( y, offsetY ); - - return addon( N, viewX, strideX, viewY, strideY ); + return addon.ndarray( N, x, strideX, offsetX, y, strideY, offsetY ); } diff --git a/lib/node_modules/@stdlib/blas/base/ddot/manifest.json b/lib/node_modules/@stdlib/blas/base/ddot/manifest.json index f82dd214b89..62aa55f4bdc 100644 --- a/lib/node_modules/@stdlib/blas/base/ddot/manifest.json +++ b/lib/node_modules/@stdlib/blas/base/ddot/manifest.json @@ -45,6 +45,7 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/napi/export", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", @@ -58,7 +59,8 @@ "blas": "", "wasm": false, "src": [ - "./src/ddot.c" + "./src/ddot.c", + "./src/ddot_ndarray.c" ], "include": [ "./include" @@ -66,7 +68,8 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] }, { @@ -75,7 +78,8 @@ "blas": "", "wasm": false, "src": [ - "./src/ddot.c" + "./src/ddot.c", + "./src/ddot_ndarray.c" ], "include": [ "./include" @@ -83,7 +87,8 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] }, @@ -105,6 +110,7 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/napi/export", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", @@ -129,7 +135,8 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index" ] }, { @@ -149,7 +156,8 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index" ] }, @@ -170,6 +178,7 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/napi/export", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", @@ -183,7 +192,8 @@ "blas": "", "wasm": false, "src": [ - "./src/ddot.c" + "./src/ddot.c", + "./src/ddot_ndarray.c" ], "include": [ "./include" @@ -191,7 +201,8 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] }, { @@ -200,7 +211,8 @@ "blas": "", "wasm": false, "src": [ - "./src/ddot.c" + "./src/ddot.c", + "./src/ddot_ndarray.c" ], "include": [ "./include" @@ -208,7 +220,8 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] }, @@ -229,6 +242,7 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/napi/export", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", @@ -252,7 +266,8 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index" ] }, { @@ -271,7 +286,8 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index" ] }, @@ -293,6 +309,7 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/napi/export", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", @@ -317,7 +334,8 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index" ] }, { @@ -337,7 +355,8 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index" ] }, @@ -347,7 +366,8 @@ "blas": "", "wasm": false, "src": [ - "./src/ddot.c" + "./src/ddot.c", + "./src/ddot_ndarray.c" ], "include": [ "./include" @@ -356,6 +376,7 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset", "@stdlib/napi/export", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", @@ -369,7 +390,8 @@ "blas": "", "wasm": false, "src": [ - "./src/ddot.c" + "./src/ddot.c", + "./src/ddot_ndarray.c" ], "include": [ "./include" @@ -377,7 +399,8 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] }, { @@ -386,7 +409,8 @@ "blas": "", "wasm": false, "src": [ - "./src/ddot.c" + "./src/ddot.c", + "./src/ddot_ndarray.c" ], "include": [ "./include" @@ -394,7 +418,8 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] }, @@ -404,7 +429,8 @@ "blas": "", "wasm": true, "src": [ - "./src/ddot.c" + "./src/ddot.c", + "./src/ddot_ndarray.c" ], "include": [ "./include" @@ -412,7 +438,8 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] } ] diff --git a/lib/node_modules/@stdlib/blas/base/ddot/src/addon.c b/lib/node_modules/@stdlib/blas/base/ddot/src/addon.c index ea5ab4bb590..500f6b5b26b 100644 --- a/lib/node_modules/@stdlib/blas/base/ddot/src/addon.c +++ b/lib/node_modules/@stdlib/blas/base/ddot/src/addon.c @@ -43,4 +43,24 @@ static napi_value addon( napi_env env, napi_callback_info info ) { return v; } -STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) +/** +* Receives JavaScript callback invocation data. +* +* @param env environment under which the function is invoked +* @param info callback data +* @return Node-API value +*/ +static napi_value addon_method( napi_env env, napi_callback_info info ) { + STDLIB_NAPI_ARGV( env, info, argv, argc, 7 ); + STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 2 ); + STDLIB_NAPI_ARGV_INT64( env, offsetX, argv, 3 ); + STDLIB_NAPI_ARGV_INT64( env, strideY, argv, 5 ); + STDLIB_NAPI_ARGV_INT64( env, offsetY, argv, 6 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, strideX, argv, 1 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, Y, N, strideY, argv, 4 ); + STDLIB_NAPI_CREATE_DOUBLE( env, API_SUFFIX(c_ddot_ndarray)( N, X, strideX, offsetX, Y, strideY, offsetY ), v ); + return v; +} + +STDLIB_NAPI_MODULE_EXPORT_FCN_WITH_METHOD( addon, "ndarray", addon_method ) 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 d139591c6ef..272fa259e3c 100644 --- a/lib/node_modules/@stdlib/blas/base/ddot/src/ddot.c +++ b/lib/node_modules/@stdlib/blas/base/ddot/src/ddot.c @@ -18,6 +18,7 @@ #include "stdlib/blas/base/ddot.h" #include "stdlib/blas/base/shared.h" +#include "stdlib/strided/base/stride2offset.h" /** * Computes the dot product of two double-precision floating-point vectors. @@ -30,49 +31,8 @@ * @return the dot product */ double API_SUFFIX(c_ddot)( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, const double *Y, const CBLAS_INT strideY ) { - double dot; - CBLAS_INT ix; - CBLAS_INT iy; - CBLAS_INT m; - CBLAS_INT i; - - dot = 0.0; - if ( N <= 0 ) { - return dot; - } - // If both strides are equal to `1`, use unrolled loops... - if ( strideX == 1 && strideY == 1 ) { - m = N % 5; - - // If we have a remainder, do a clean-up loop... - if ( m > 0 ) { - for ( i = 0; i < m; i++ ) { - dot += X[ i ] * Y[ i ]; - } - } - if ( N < 5 ) { - return dot; - } - for ( i = m; i < N; i += 5 ) { - dot += ( X[i]*Y[i] ) + ( X[i+1]*Y[i+1] ) + ( X[i+2]*Y[i+2] ) + ( X[i+3]*Y[i+3] ) + ( X[i+4]*Y[i+4] ); - } - return dot; - } - if ( strideX < 0 ) { - ix = (1-N) * strideX; - } else { - ix = 0; - } - if ( strideY < 0 ) { - iy = (1-N) * strideY; - } else { - iy = 0; - } - for ( i = 0; i < N; i++ ) { - dot += X[ ix ] * Y[ iy ]; - ix += strideX; - iy += strideY; - } - return dot; + CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX ); + CBLAS_INT oy = stdlib_strided_stride2offset( N, strideY ); + return API_SUFFIX(c_ddot_ndarray)( N, X, strideX, ox, Y, strideY, oy ); } 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 53b5dcee26a..c7763569551 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 @@ -19,17 +19,36 @@ #include "stdlib/blas/base/ddot.h" #include "stdlib/blas/base/ddot_cblas.h" #include "stdlib/blas/base/shared.h" +#include "stdlib/strided/base/min_view_buffer_index.h" /** * Computes the dot product of two double-precision floating-point vectors. * * @param N number of indexed elements -* @param X first array +* @param X first input array * @param strideX X stride length -* @param Y second array +* @param Y second input array * @param strideY Y stride length -* @return the dot product +* @return dot product */ double API_SUFFIX(c_ddot)( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, const double *Y, const CBLAS_INT strideY ) { return API_SUFFIX(cblas_ddot)( N, X, strideX, Y, strideY ); } + +/** +* Computes the dot product of two double-precision floating-point vectors using alternative indexing semantics. +* +* @param N number of indexed elements +* @param X first input array +* @param strideX X stride length +* @param offsetX starting index for X +* @param Y second input array +* @param strideY Y stride length +* @param offsetY starting index for Y +* @return dot product +*/ +double API_SUFFIX(c_ddot_ndarray)( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, const double *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY ) { + X += stdlib_strided_min_view_buffer_index( N, strideX, offsetX ); // adjust array pointer + Y += stdlib_strided_min_view_buffer_index( N, strideY, offsetY ); // adjust array pointer + return API_SUFFIX(cblas_ddot_ndarray)( 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 9184cc3daf5..dd916e1286e 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 @@ -19,19 +19,41 @@ #include "stdlib/blas/base/ddot.h" #include "stdlib/blas/base/ddot_fortran.h" #include "stdlib/blas/base/shared.h" +#include "stdlib/strided/base/min_view_buffer_index.h" /** * Computes the dot product of two double-precision floating-point vectors. * * @param N number of indexed elements +* @param X first input array +* @param strideX X stride length +* @param Y second input array +* @param strideY Y stride length +* @return dot product +*/ +double API_SUFFIX(c_ddot)( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, const double *Y, const CBLAS_INT strideY ) { + double dot; + ddotsub( &N, X, &strideX, Y, &strideY, &dot ); + return dot; +} + +/** +* Computes the dot product of two double-precision floating-point vectors using alternative indexing semantics. +* +* @param N number of indexed elements * @param X first array * @param strideX X stride length +* @param offsetX starting index for X * @param Y second array * @param strideY Y stride length +* @param offsetY starting index for Y * @return the dot product */ -double API_SUFFIX(c_ddot)( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, const double *Y, const CBLAS_INT strideY ) { +double API_SUFFIX(c_ddot_ndarray)( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, const double *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY ) { double dot; + + X += stdlib_strided_min_view_buffer_index( N, strideX, offsetX ); // adjust array pointer + Y += stdlib_strided_min_view_buffer_index( N, strideY, offsetY ); // adjust array pointer ddotsub( &N, X, &strideX, Y, &strideY, &dot ); return dot; } diff --git a/lib/node_modules/@stdlib/blas/base/ddot/src/ddot_ndarray.c b/lib/node_modules/@stdlib/blas/base/ddot/src/ddot_ndarray.c new file mode 100644 index 00000000000..aecf91d6a4d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ddot/src/ddot_ndarray.c @@ -0,0 +1,78 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2019 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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/base/ddot.h" +#include "stdlib/blas/base/shared.h" + +static const CBLAS_INT M = 5; + +/** +* Computes the dot product of two double-precision floating-point vectors using alternative indexing semantics. +* +* @param N number of indexed elements +* @param X first array +* @param strideX X stride length +* @param offsetX starting index for X +* @param Y second array +* @param strideY Y stride length +* @param offsetY starting index for Y +* @return the dot product +*/ +double API_SUFFIX(c_ddot_ndarray)( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, const double *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY ) { + double dot; + CBLAS_INT ix; + CBLAS_INT iy; + CBLAS_INT m; + CBLAS_INT i; + + dot = 0.0; + if ( N <= 0 ) { + return dot; + } + ix = offsetX; + iy = offsetY; + + // If both strides are equal to `1`, use unrolled loops... + if ( strideX == 1 && strideY == 1 ) { + m = N % M; + + // If we have a remainder, do a clean-up loop... + if ( m > 0 ) { + for ( i = 0; i < m; i++ ) { + dot += X[ ix ] * Y[ iy ]; + ix += strideX; + iy += strideY; + } + } + if ( N < M ) { + return dot; + } + for ( i = m; i < N; i += M ) { + dot += ( X[ ix ]*Y[ iy ] ) + ( X[ ix+1 ]*Y[ iy+1 ] ) + ( X[ ix+2 ]*Y[ iy+2 ] ) + ( X[ ix+3 ]*Y[ iy+3 ] ) + ( X[ ix+4 ]*Y[ iy+4 ] ); + ix += M; + iy += M; + } + return dot; + } + for ( i = 0; i < N; i++ ) { + dot += X[ ix ] * Y[ iy ]; + ix += strideX; + iy += strideY; + } + return dot; +} diff --git a/lib/node_modules/@stdlib/blas/base/dnrm2/README.md b/lib/node_modules/@stdlib/blas/base/dnrm2/README.md index d286446a1fe..c4a6f6e7293 100644 --- a/lib/node_modules/@stdlib/blas/base/dnrm2/README.md +++ b/lib/node_modules/@stdlib/blas/base/dnrm2/README.md @@ -91,7 +91,7 @@ var z = dnrm2( 4, x1, 2 ); // returns 5.0 ``` -If either `N` or `stride` is less than or equal to `0`, the function returns `0`. +If `N` is less than or equal to `0`, the function returns `0`. #### dnrm2.ndarray( N, x, stride, offset ) @@ -207,6 +207,28 @@ The function accepts the following arguments: double c_dnrm2( const CBLAS_INT N, const double *X, const CBLAS_INT stride ); ``` +#### c_dnrm2_ndarray( N, \*X, stride, offset ) + +Computes the L2-norm of a double-precision floating-point vector using alternative indexing semantics. + +```c +const double x[] = { 1.0, -2.0, 2.0 }; + +double v = c_dnrm2( 3, x, -1, 2 ); +// returns 3.0 +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **X**: `[in] double*` input array. +- **stride**: `[in] CBLAS_INT` index increment for `X`. +- **offset**: `[in] CBLAS_INT` starting index for `X`. + +```c +double c_dnrm2_ndarray( const CBLAS_INT N, const double *X, const CBLAS_INT stride, const CBLAS_INT offset ); +``` + @@ -244,6 +266,12 @@ int main( void ) { // Print the result: printf( "L2-norm: %lf\n", l2 ); + + // Compute the L2-norm: + l2 = c_dnrm2_ndarray( N, x, -strideX, N-1 ); + + // Print the result: + printf( "L2-norm: %lf\n", l2 ); } ``` diff --git a/lib/node_modules/@stdlib/blas/base/dnrm2/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/blas/base/dnrm2/benchmark/c/benchmark.length.c index 5d648dd8856..d6d4413fee1 100644 --- a/lib/node_modules/@stdlib/blas/base/dnrm2/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/blas/base/dnrm2/benchmark/c/benchmark.length.c @@ -94,7 +94,7 @@ static double rand_double( void ) { * @param len array length * @return elapsed time in seconds */ -static double benchmark( int iterations, int len ) { +static double benchmark1( int iterations, int len ) { double elapsed; double x[ len ]; double z; @@ -120,6 +120,39 @@ static double benchmark( int iterations, int len ) { return elapsed; } +/** +* Runs a benchmark. +* +* @param iterations number of iterations +* @param len array length +* @return elapsed time in seconds +*/ +static double benchmark2( int iterations, int len ) { + double elapsed; + double x[ len ]; + double z; + double t; + int i; + + for ( i = 0; i < len; i++ ) { + x[ i ] = ( rand_double() * 20000.0 ) - 10000.0; + } + z = 0.0; + t = tic(); + for ( i = 0; i < iterations; i++ ) { + z = c_dnrm2_ndarray( len, x, 1, 0 ); + if ( z != z ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( z != z ) { + printf( "should not return NaN\n" ); + } + return elapsed; +} + /** * Main execution sequence. */ @@ -142,7 +175,14 @@ int main( void ) { for ( j = 0; j < REPEATS; j++ ) { count += 1; printf( "# c::%s:len=%d\n", NAME, len ); - elapsed = benchmark( iter, len ); + elapsed = benchmark1( iter, len ); + print_results( iter, elapsed ); + printf( "ok %d benchmark finished\n", count ); + } + for ( j = 0; j < REPEATS; j++ ) { + count += 1; + printf( "# c::%s:ndarray:len=%d\n", NAME, len ); + elapsed = benchmark2( iter, len ); print_results( iter, elapsed ); printf( "ok %d benchmark finished\n", count ); } diff --git a/lib/node_modules/@stdlib/blas/base/dnrm2/docs/repl.txt b/lib/node_modules/@stdlib/blas/base/dnrm2/docs/repl.txt index 2bec3739d6b..3e12a5e30fd 100644 --- a/lib/node_modules/@stdlib/blas/base/dnrm2/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/base/dnrm2/docs/repl.txt @@ -8,7 +8,7 @@ Indexing is relative to the first index. To introduce an offset, use a typed array view. - If `N <= 0` or `stride <= 0`, the function returns `0`. + If `N <= 0`, the function returns `0`. Parameters ---------- diff --git a/lib/node_modules/@stdlib/blas/base/dnrm2/examples/c/example.c b/lib/node_modules/@stdlib/blas/base/dnrm2/examples/c/example.c index 6df2de1d7d2..9b577f98c41 100644 --- a/lib/node_modules/@stdlib/blas/base/dnrm2/examples/c/example.c +++ b/lib/node_modules/@stdlib/blas/base/dnrm2/examples/c/example.c @@ -34,4 +34,10 @@ int main( void ) { // Print the result: printf( "L2-norm: %lf\n", l2 ); + + // Compute the L2-norm: + l2 = c_dnrm2_ndarray( N, x, -strideX, N-1 ); + + // Print the result: + printf( "L2-norm: %lf\n", l2 ); } diff --git a/lib/node_modules/@stdlib/blas/base/dnrm2/include/stdlib/blas/base/dnrm2.h b/lib/node_modules/@stdlib/blas/base/dnrm2/include/stdlib/blas/base/dnrm2.h index 88eae88f0ae..1cf316fe2d8 100644 --- a/lib/node_modules/@stdlib/blas/base/dnrm2/include/stdlib/blas/base/dnrm2.h +++ b/lib/node_modules/@stdlib/blas/base/dnrm2/include/stdlib/blas/base/dnrm2.h @@ -36,6 +36,11 @@ extern "C" { */ double API_SUFFIX(c_dnrm2)( const CBLAS_INT N, const double *X, const CBLAS_INT stride ); +/** +* Computes the L2-norm of a double-precision floating-point vector using alternative indexing semantics. +*/ +double API_SUFFIX(c_dnrm2_ndarray)( const CBLAS_INT N, const double *X, const CBLAS_INT stride, const CBLAS_INT offset ); + #ifdef __cplusplus } #endif diff --git a/lib/node_modules/@stdlib/blas/base/dnrm2/lib/dnrm2.js b/lib/node_modules/@stdlib/blas/base/dnrm2/lib/dnrm2.js index e215ed0e6c0..b602fe09f7d 100644 --- a/lib/node_modules/@stdlib/blas/base/dnrm2/lib/dnrm2.js +++ b/lib/node_modules/@stdlib/blas/base/dnrm2/lib/dnrm2.js @@ -20,9 +20,8 @@ // MODULES // -var sqrt = require( '@stdlib/math/base/special/sqrt' ); -var abs = require( '@stdlib/math/base/special/abs' ); -var pow = require( '@stdlib/math/base/special/pow' ); +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require( './ndarray.js' ); // MAIN // @@ -32,7 +31,7 @@ var pow = require( '@stdlib/math/base/special/pow' ); * * @param {PositiveInteger} N - number of indexed elements * @param {Float64Array} x - input array -* @param {PositiveInteger} stride - stride length +* @param {integer} stride - stride length * @returns {number} L2-norm * * @example @@ -44,32 +43,8 @@ var pow = require( '@stdlib/math/base/special/pow' ); * // returns 3.0 */ function dnrm2( N, x, stride ) { - var scale; - var ssq; - var ax; - var i; - - if ( N <= 0 || stride <= 0 ) { - return 0.0; - } - if ( N === 1 ) { - return abs( x[ 0 ] ); - } - scale = 0.0; - ssq = 1.0; - N *= stride; - for ( i = 0; i < N; i += stride ) { - if ( x[ i ] !== 0.0 ) { - ax = abs( x[ i ] ); - if ( scale < ax ) { - ssq = 1.0 + ( ssq * pow( scale/ax, 2 ) ); - scale = ax; - } else { - ssq += pow( ax/scale, 2 ); - } - } - } - return scale * sqrt( ssq ); + var ox = stride2offset( N, stride ); + return ndarray( N, x, stride, ox ); } diff --git a/lib/node_modules/@stdlib/blas/base/dnrm2/lib/dnrm2.native.js b/lib/node_modules/@stdlib/blas/base/dnrm2/lib/dnrm2.native.js index 373d55e877b..faf62bd4eab 100644 --- a/lib/node_modules/@stdlib/blas/base/dnrm2/lib/dnrm2.native.js +++ b/lib/node_modules/@stdlib/blas/base/dnrm2/lib/dnrm2.native.js @@ -30,7 +30,7 @@ var addon = require( './../src/addon.node' ); * * @param {PositiveInteger} N - number of indexed elements * @param {Float64Array} x - input array -* @param {PositiveInteger} stride - stride length +* @param {integer} stride - stride length * @returns {number} L2-norm * * @example diff --git a/lib/node_modules/@stdlib/blas/base/dnrm2/lib/ndarray.js b/lib/node_modules/@stdlib/blas/base/dnrm2/lib/ndarray.js index 4061194670c..bbc2db376bf 100644 --- a/lib/node_modules/@stdlib/blas/base/dnrm2/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/dnrm2/lib/ndarray.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2020 The Stdlib Authors. +* Copyright (c) 2023 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,9 +20,19 @@ // MODULES // -var sqrt = require( '@stdlib/math/base/special/sqrt' ); +var FLOAT64_MAX = require( '@stdlib/constants/float64/max' ); var abs = require( '@stdlib/math/base/special/abs' ); -var pow = require( '@stdlib/math/base/special/pow' ); +var abs2 = require( '@stdlib/math/base/special/abs2' ); +var sqrt = require( '@stdlib/math/base/special/sqrt' ); + + +// VARIABLES // + +// Blue's scaling constants: +var tsml = 1.4916681462400413E-154; +var tbig = 1.9979190722022350E+146; +var ssml = 4.4989137945431964E+161; +var sbig = 1.1113793747425387E-162; // MAIN // @@ -41,12 +51,18 @@ var pow = require( '@stdlib/math/base/special/pow' ); * * var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); * -* var out = dnrm2( 4, x, 2, 1 ); +* var z = dnrm2( 4, x, 2, 1 ); * // returns 5.0 */ function dnrm2( N, x, stride, offset ) { - var scale; - var ssq; + var notbig; + var sumsq; + var abig; + var amed; + var asml; + var ymax; + var ymin; + var scl; var ax; var ix; var i; @@ -54,25 +70,64 @@ function dnrm2( N, x, stride, offset ) { if ( N <= 0 ) { return 0.0; } - if ( N === 1 ) { - return abs( x[ offset ] ); - } ix = offset; - scale = 0.0; - ssq = 1.0; + + // Initialize loop values for accumulation: + notbig = true; + + sumsq = 0.0; + abig = 0.0; + amed = 0.0; + asml = 0.0; + scl = 1.0; + + // Compute the sum of squares using 3 accumulators--`abig` (sum of squares scaled down to avoid overflow), `asml` (sum of squares scaled up to avoid underflow), `amed` (sum of squares that do not require scaling)--and thresholds and multipliers--`tbig` (values bigger than this are scaled down by `sbig`) and `tsml` (values smaller than this are scaled up by `ssml`)... for ( i = 0; i < N; i++ ) { - if ( x[ ix ] !== 0.0 ) { - ax = abs( x[ ix ] ); - if ( scale < ax ) { - ssq = 1.0 + ( ssq * pow( scale/ax, 2 ) ); - scale = ax; - } else { - ssq += pow( ax/scale, 2 ); + ax = abs( x[ ix ] ); + if ( ax > tbig ) { + abig += abs2( ax * sbig ); + notbig = false; + } else if ( ax < tsml ) { + if ( notbig ) { + asml += abs2( ax * ssml ); } + } else { + amed += ( ax * ax ); } ix += stride; } - return scale * sqrt( ssq ); + // Combine `abig` and `amed` or `amed` and `asml` if more than one accumulator was used... + if ( abig > 0.0 ) { + // Combine `abig` and `amed` if `abig` > 0... + if ( amed > 0.0 || ( amed > FLOAT64_MAX ) || ( amed !== amed ) ) { + abig += ( ( amed * sbig ) * sbig ); + } + scl = 1.0 / sbig; + sumsq = abig; + } else if ( asml > 0.0 ) { + // Combine `amed` and `asml` if `asml` > 0... + if ( amed > 0.0 || amed > FLOAT64_MAX || ( amed !== amed ) ) { + amed = sqrt( amed ); + asml = sqrt( asml ) / ssml; + if ( asml > amed ) { + ymin = amed; + ymax = asml; + } else { + ymin = asml; + ymax = amed; + } + scl = 1.0; + sumsq = ( ymax * ymax ) * ( 1.0 + abs2( ymin / ymax ) ); + } else { + scl = 1.0 / ssml; + sumsq = asml; + } + } else { + // All values are mid-range... + scl = 1.0; + sumsq = amed; + } + return sqrt( sumsq ) * scl; } diff --git a/lib/node_modules/@stdlib/blas/base/dnrm2/lib/ndarray.native.js b/lib/node_modules/@stdlib/blas/base/dnrm2/lib/ndarray.native.js index 12b25953b39..d8a3ee8d89a 100644 --- a/lib/node_modules/@stdlib/blas/base/dnrm2/lib/ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/base/dnrm2/lib/ndarray.native.js @@ -20,9 +20,7 @@ // MODULES // -var minViewBufferIndex = require( '@stdlib/strided/base/min-view-buffer-index' ); -var offsetView = require( '@stdlib/strided/base/offset-view' ); -var addon = require( './dnrm2.native.js' ); +var addon = require( './../src/addon.node' ); // MAIN // @@ -45,13 +43,7 @@ var addon = require( './dnrm2.native.js' ); * // returns 5.0 */ function dnrm2( N, x, stride, offset ) { - var view; - offset = minViewBufferIndex( N, stride, offset ); - if ( stride < 0 ) { - stride *= -1; - } - view = offsetView( x, offset ); - return addon( N, view, stride ); + return addon.ndarray( N, x, stride, offset ); } diff --git a/lib/node_modules/@stdlib/blas/base/dnrm2/manifest.json b/lib/node_modules/@stdlib/blas/base/dnrm2/manifest.json index 33d4c1d48f4..cd98f1b2867 100644 --- a/lib/node_modules/@stdlib/blas/base/dnrm2/manifest.json +++ b/lib/node_modules/@stdlib/blas/base/dnrm2/manifest.json @@ -44,8 +44,9 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared", "@stdlib/napi/export", + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", "@stdlib/napi/argv-strided-float64array", @@ -58,7 +59,8 @@ "blas": "", "wasm": false, "src": [ - "./src/dnrm2.c" + "./src/dnrm2.c", + "./src/dnrm2_ndarray.c" ], "include": [ "./include" @@ -70,8 +72,10 @@ "dependencies": [ "@stdlib/blas/base/shared", "@stdlib/math/base/special/abs", + "@stdlib/math/base/special/abs2", "@stdlib/math/base/special/sqrt", - "@stdlib/math/base/special/pow" + "@stdlib/constants/float64/max", + "@stdlib/strided/base/stride2offset" ] }, { @@ -80,7 +84,8 @@ "blas": "", "wasm": false, "src": [ - "./src/dnrm2.c" + "./src/dnrm2.c", + "./src/dnrm2_ndarray.c" ], "include": [ "./include" @@ -92,8 +97,10 @@ "dependencies": [ "@stdlib/blas/base/shared", "@stdlib/math/base/special/abs", + "@stdlib/math/base/special/abs2", "@stdlib/math/base/special/sqrt", - "@stdlib/math/base/special/pow" + "@stdlib/constants/float64/max", + "@stdlib/strided/base/stride2offset" ] }, @@ -114,8 +121,9 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared", "@stdlib/napi/export", + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", "@stdlib/napi/argv-strided-float64array", @@ -139,7 +147,8 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index" ] }, { @@ -159,7 +168,8 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index" ] }, @@ -179,8 +189,9 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared", "@stdlib/napi/export", + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", "@stdlib/napi/argv-strided-float64array", @@ -193,7 +204,8 @@ "blas": "", "wasm": false, "src": [ - "./src/dnrm2.c" + "./src/dnrm2.c", + "./src/dnrm2_ndarray.c" ], "include": [ "./include" @@ -205,8 +217,10 @@ "dependencies": [ "@stdlib/blas/base/shared", "@stdlib/math/base/special/abs", + "@stdlib/math/base/special/abs2", "@stdlib/math/base/special/sqrt", - "@stdlib/math/base/special/pow" + "@stdlib/constants/float64/max", + "@stdlib/strided/base/stride2offset" ] }, { @@ -215,7 +229,8 @@ "blas": "", "wasm": false, "src": [ - "./src/dnrm2.c" + "./src/dnrm2.c", + "./src/dnrm2_ndarray.c" ], "include": [ "./include" @@ -227,8 +242,10 @@ "dependencies": [ "@stdlib/blas/base/shared", "@stdlib/math/base/special/abs", + "@stdlib/math/base/special/abs2", "@stdlib/math/base/special/sqrt", - "@stdlib/math/base/special/pow" + "@stdlib/constants/float64/max", + "@stdlib/strided/base/stride2offset" ] }, @@ -248,8 +265,9 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared", "@stdlib/napi/export", + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", "@stdlib/napi/argv-strided-float64array", @@ -272,7 +290,8 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index" ] }, { @@ -291,7 +310,8 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index" ] }, @@ -312,8 +332,9 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared", "@stdlib/napi/export", + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", "@stdlib/napi/argv-strided-float64array", @@ -337,7 +358,8 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index" ] }, { @@ -357,7 +379,8 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index" ] }, @@ -367,7 +390,8 @@ "blas": "", "wasm": false, "src": [ - "./src/dnrm2.c" + "./src/dnrm2.c", + "./src/dnrm2_ndarray.c" ], "include": [ "./include" @@ -377,15 +401,17 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared", "@stdlib/napi/export", + "@stdlib/blas/base/shared", + "@stdlib/math/base/special/abs", + "@stdlib/math/base/special/abs2", + "@stdlib/math/base/special/sqrt", + "@stdlib/constants/float64/max", + "@stdlib/strided/base/stride2offset", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", "@stdlib/napi/argv-strided-float64array", - "@stdlib/napi/create-double", - "@stdlib/math/base/special/abs", - "@stdlib/math/base/special/sqrt", - "@stdlib/math/base/special/pow" + "@stdlib/napi/create-double" ] }, { @@ -394,7 +420,8 @@ "blas": "", "wasm": false, "src": [ - "./src/dnrm2.c" + "./src/dnrm2.c", + "./src/dnrm2_ndarray.c" ], "include": [ "./include" @@ -406,8 +433,10 @@ "dependencies": [ "@stdlib/blas/base/shared", "@stdlib/math/base/special/abs", + "@stdlib/math/base/special/abs2", "@stdlib/math/base/special/sqrt", - "@stdlib/math/base/special/pow" + "@stdlib/constants/float64/max", + "@stdlib/strided/base/stride2offset" ] }, { @@ -416,7 +445,8 @@ "blas": "", "wasm": false, "src": [ - "./src/dnrm2.c" + "./src/dnrm2.c", + "./src/dnrm2_ndarray.c" ], "include": [ "./include" @@ -428,8 +458,10 @@ "dependencies": [ "@stdlib/blas/base/shared", "@stdlib/math/base/special/abs", + "@stdlib/math/base/special/abs2", "@stdlib/math/base/special/sqrt", - "@stdlib/math/base/special/pow" + "@stdlib/constants/float64/max", + "@stdlib/strided/base/stride2offset" ] }, @@ -439,7 +471,8 @@ "blas": "", "wasm": true, "src": [ - "./src/dnrm2.c" + "./src/dnrm2.c", + "./src/dnrm2_ndarray.c" ], "include": [ "./include" @@ -451,8 +484,10 @@ "dependencies": [ "@stdlib/blas/base/shared", "@stdlib/math/base/special/abs", + "@stdlib/math/base/special/abs2", "@stdlib/math/base/special/sqrt", - "@stdlib/math/base/special/pow" + "@stdlib/constants/float64/max", + "@stdlib/strided/base/stride2offset" ] } ] diff --git a/lib/node_modules/@stdlib/blas/base/dnrm2/src/addon.c b/lib/node_modules/@stdlib/blas/base/dnrm2/src/addon.c index 5559035460e..b09d97ab1c6 100644 --- a/lib/node_modules/@stdlib/blas/base/dnrm2/src/addon.c +++ b/lib/node_modules/@stdlib/blas/base/dnrm2/src/addon.c @@ -35,10 +35,27 @@ 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_FLOAT64ARRAY( env, X, N, strideX, argv, 1 ); - STDLIB_NAPI_CREATE_DOUBLE( env, API_SUFFIX(c_dnrm2)( N, X, strideX ), v ); + STDLIB_NAPI_ARGV_INT64( env, stride, argv, 2 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, stride, argv, 1 ); + STDLIB_NAPI_CREATE_DOUBLE( env, API_SUFFIX(c_dnrm2)( N, X, stride ), v ); return v; } -STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) +/** +* Receives JavaScript callback invocation data. +* +* @param env environment under which the function is invoked +* @param info callback data +* @return Node-API value +*/ +static napi_value addon_method( 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_INT64( env, stride, argv, 2 ); + STDLIB_NAPI_ARGV_INT64( env, offset, argv, 3 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, stride, argv, 1 ); + STDLIB_NAPI_CREATE_DOUBLE( env, API_SUFFIX(c_dnrm2_ndarray)( N, X, stride, offset ), v ); + return v; +} + +STDLIB_NAPI_MODULE_EXPORT_FCN_WITH_METHOD( addon, "ndarray", addon_method ) diff --git a/lib/node_modules/@stdlib/blas/base/dnrm2/src/dnrm2.c b/lib/node_modules/@stdlib/blas/base/dnrm2/src/dnrm2.c index a15dddf7bac..74569f41533 100644 --- a/lib/node_modules/@stdlib/blas/base/dnrm2/src/dnrm2.c +++ b/lib/node_modules/@stdlib/blas/base/dnrm2/src/dnrm2.c @@ -18,9 +18,7 @@ #include "stdlib/blas/base/dnrm2.h" #include "stdlib/blas/base/shared.h" -#include "stdlib/math/base/special/abs.h" -#include "stdlib/math/base/special/sqrt.h" -#include "stdlib/math/base/special/pow.h" +#include "stdlib/strided/base/stride2offset.h" /** * Computes the L2-norm of a double-precision floating-point vector. @@ -31,29 +29,6 @@ * @return L2-norm */ double API_SUFFIX(c_dnrm2)( const CBLAS_INT N, const double *X, const CBLAS_INT stride ) { - double scale; - double ssq; - double ax; - CBLAS_INT i; - - if ( N <= 0 || stride <= 0 ) { - return 0.0; - } - if ( N == 1 ) { - return stdlib_base_abs( X[ 0 ] ); - } - scale = 0.0; - ssq = 1.0; - for ( i = 0; i < N*stride; i += stride ) { - if ( X[ i ] != 0.0 ) { - ax = stdlib_base_abs( X[ i ] ); - if ( scale < ax ) { - ssq = 1.0 + ( ssq * stdlib_base_pow( scale/ax, 2 ) ); - scale = ax; - } else { - ssq += stdlib_base_pow( ax/scale, 2 ); - } - } - } - return scale * stdlib_base_sqrt( ssq ); + CBLAS_INT ox = stdlib_strided_stride2offset( N, stride ); + return API_SUFFIX(c_dnrm2_ndarray)( N, X, stride, ox ); } diff --git a/lib/node_modules/@stdlib/blas/base/dnrm2/src/dnrm2.f b/lib/node_modules/@stdlib/blas/base/dnrm2/src/dnrm2.f index d3b24c19fd1..19f115a19b1 100644 --- a/lib/node_modules/@stdlib/blas/base/dnrm2/src/dnrm2.f +++ b/lib/node_modules/@stdlib/blas/base/dnrm2/src/dnrm2.f @@ -52,6 +52,20 @@ !< double precision function dnrm2( N, dx, stride ) implicit none + ! .. + ! Define a kind parameter for double-precision: + integer, parameter :: wp = kind( 1.0d0 ) + ! .. + ! Define constants: + real( wp ), parameter :: zero = 0.0_wp + real( wp ), parameter :: one = 1.0_wp + real( wp ), parameter :: maxN = huge( 0.0_wp ) + ! .. + ! Blue's scaling constants: + real( wp ), parameter :: tsml = 1.4916681462400413e-154_wp + real( wp ), parameter :: tbig = 1.9979190722022350e146_wp + real( wp ), parameter :: ssml = 4.4989137945431964e161_wp + real( wp ), parameter :: sbig = 1.1113793747425387e-162_wp !.. ! Scalar arguments: integer :: N, stride @@ -60,35 +74,85 @@ double precision function dnrm2( N, dx, stride ) double precision, intent(in) :: dx(*) ! .. ! Local scalars: - double precision :: ax, scale, ssq - integer :: i + integer :: i, ix + logical :: notbig + real( wp ) :: abig, amed, asml, ax, scl, sumsq, ymax, ymin ! .. ! Intrinsic functions: intrinsic dabs, dsqrt ! .. dnrm2 = 0.0d0 ! .. - if ( N <= 0 .OR. stride <= 0 ) then + if ( N <= 0 ) then return end if - !.. - if ( N == 1 ) then - dnrm2 = dabs( dx( 1 ) ) - return + ! .. + scl = one + sumsq = zero + ! .. + ! Compute the sum of squares in 3 accumulators: + ! abig -- sums of squares scaled down to avoid overflow + ! asml -- sums of squares scaled up to avoid underflow + ! amed -- sums of squares that do not require scaling + ! Thresholds and multipliers: + ! tbig -- values bigger than this are scaled down by sbig + ! tsml -- values smaller than this are scaled up by ssml + ! .. + notbig = .true. + asml = zero + amed = zero + abig = zero + ix = 1 + if ( stride < 0 ) then + ix = 1 - ( N - 1 ) * stride end if ! .. - scale = 0.0d0 - ssq = 1.0d0 - do i = 1, 1+((N-1)*stride), stride - if ( dx( i ) /= 0.0d0 ) then - ax = dabs( dx( i ) ) - if ( scale < ax ) then - ssq = 1.0d0 + ( ssq * (scale/ax)**2 ) - scale = ax - else - ssq = ssq + (ax/scale)**2 + do i = 1, N + ax = abs( dx( ix ) ) + if ( ax > tbig ) then + abig = abig + ( ax * sbig )**2 + notbig = .false. + else if ( ax < tsml ) then + if ( notbig ) then + asml = asml + ( ax * ssml )**2 end if + else + amed = amed + ax**2 end if + ix = ix + stride end do - dnrm2 = scale * dsqrt( ssq ) + ! .. + ! Combine abig and amed or amed and asml if more than one accumulator was used: + if ( abig > zero ) then + ! Combine abig and amed if abig > 0... + if ( ( amed > zero ) .or. ( amed > maxN ) .or. ( amed /= amed ) ) then + abig = abig + ( amed * sbig ) * sbig + end if + scl = one / sbig + sumsq = abig + else if ( asml > zero ) then + ! Combine amed and asml if asml > 0... + if ( ( amed > zero ) .or. ( amed > maxN ) .or. ( amed /= amed ) ) then + amed = sqrt( amed ) + asml = sqrt( asml ) / ssml + if ( asml > amed ) then + ymin = amed + ymax = asml + else + ymin = asml + ymax = amed + end if + scl = one + sumsq = ymax**2 * ( one + ( ymin / ymax )**2 ) + else + scl = one / ssml + sumsq = asml + end if + else + ! All values are mid-range... + scl = one + sumsq = amed + end if + dnrm2 = scl * sqrt( sumsq ) + return end function dnrm2 diff --git a/lib/node_modules/@stdlib/blas/base/dnrm2/src/dnrm2_cblas.c b/lib/node_modules/@stdlib/blas/base/dnrm2/src/dnrm2_cblas.c index 9c4cbc66e0a..65d94b77a2c 100644 --- a/lib/node_modules/@stdlib/blas/base/dnrm2/src/dnrm2_cblas.c +++ b/lib/node_modules/@stdlib/blas/base/dnrm2/src/dnrm2_cblas.c @@ -19,6 +19,7 @@ #include "stdlib/blas/base/dnrm2.h" #include "stdlib/blas/base/dnrm2_cblas.h" #include "stdlib/blas/base/shared.h" +#include "stdlib/strided/base/min_view_buffer_index.h" /** * Computes the L2-norm of a double-precision floating-point vector. @@ -29,5 +30,27 @@ * @return L2-norm */ double API_SUFFIX(c_dnrm2)( const CBLAS_INT N, const double *X, const CBLAS_INT stride ) { - return API_SUFFIX(cblas_dnrm2)( N, X, stride ); + CBLAS_INT sx = stride; + if ( sx < 0 ) { + sx = -sx; + } + return API_SUFFIX(cblas_dnrm2)( N, X, sx ); +} + +/** +* Computes the L2-norm of a double-precision floating-point vector using alternative indexing semantics. +* +* @param N number of indexed elements +* @param X input array +* @param stride stride length +* @param offset starting index +* @return L2-norm +*/ +double API_SUFFIX(c_dnrm2_ndarray)( const CBLAS_INT N, const double *X, const CBLAS_INT stride, const CBLAS_INT offset ) { + CBLAS_INT sx = stride; + if ( sx < 0 ) { + sx = -sx; + } + X += stdlib_strided_min_view_buffer_index( N, stride, offset ); // adjust array pointer + return API_SUFFIX(cblas_dnrm2)( N, X, sx ); } diff --git a/lib/node_modules/@stdlib/blas/base/dnrm2/src/dnrm2_f.c b/lib/node_modules/@stdlib/blas/base/dnrm2/src/dnrm2_f.c index 87c289eca6b..41d93d21a98 100644 --- a/lib/node_modules/@stdlib/blas/base/dnrm2/src/dnrm2_f.c +++ b/lib/node_modules/@stdlib/blas/base/dnrm2/src/dnrm2_f.c @@ -19,6 +19,7 @@ #include "stdlib/blas/base/dnrm2.h" #include "stdlib/blas/base/dnrm2_fortran.h" #include "stdlib/blas/base/shared.h" +#include "stdlib/strided/base/min_view_buffer_index.h" /** * Computes the L2-norm of a double-precision floating-point vector. @@ -33,3 +34,19 @@ double API_SUFFIX(c_dnrm2)( const CBLAS_INT N, const double *X, const CBLAS_INT dnrm2sub( &N, X, &stride, &nrm2 ); return nrm2; } + +/** +* Computes the L2-norm of a double-precision floating-point vector using alternative indexing semantics. +* +* @param N number of indexed elements +* @param X input array +* @param stride stride length +* @param offset starting index +* @return L2-norm +*/ +double API_SUFFIX(c_dnrm2_ndarray)( const CBLAS_INT N, const double *X, const CBLAS_INT stride, const CBLAS_INT offset ) { + double nrm2; + X += stdlib_strided_min_view_buffer_index( N, stride, offset ); // adjust array pointer + dnrm2sub( &N, X, &stride, &nrm2 ); + return nrm2; +} diff --git a/lib/node_modules/@stdlib/blas/base/dnrm2/src/dnrm2_ndarray.c b/lib/node_modules/@stdlib/blas/base/dnrm2/src/dnrm2_ndarray.c new file mode 100644 index 00000000000..1063f8bd768 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dnrm2/src/dnrm2_ndarray.c @@ -0,0 +1,112 @@ +/** +* @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. +*/ + +#include "stdlib/blas/base/dnrm2.h" +#include "stdlib/blas/base/shared.h" +#include "stdlib/math/base/special/abs.h" +#include "stdlib/math/base/special/abs2.h" +#include "stdlib/math/base/special/sqrt.h" +#include "stdlib/constants/float64/max.h" +#include + +// Blue's scaling constants... +static const double tsml = 1.4916681462400413E-154; +static const double tbig = 1.9979190722022350E+146; +static const double ssml = 4.4989137945431964E+161; +static const double sbig = 1.1113793747425387E-162; + +/** +* Computes the L2-norm of a double-precision floating-point vector using alternative indexing semantics. +* +* @param N number of indexed elements +* @param X input array +* @param stride stride length +* @param offset starting index +* @return output value +*/ +double API_SUFFIX(c_dnrm2_ndarray)( const CBLAS_INT N, const double *X, const CBLAS_INT stride, const CBLAS_INT offset ) { + CBLAS_INT ix; + double sumsq; + bool notbig; + CBLAS_INT i; + double abig; + double amed; + double asml; + double ymax; + double ymin; + double scl; + double ax; + + if ( N <= 0 ) { + return 0.0; + } + ix = offset; + + // Compute the sum of squares using 3 accumulators--`abig` (sum of squares scaled down to avoid overflow), `asml` (sum of squares scaled up to avoid underflow), `amed` (sum of squares that do not require scaling)--and thresholds and multipliers--`tbig` (values bigger than this are scaled down by `sbig`) and `tsml` (values smaller than this are scaled up by `ssml`)... + notbig = true; + sumsq = 0.0; + abig = 0.0; + amed = 0.0; + asml = 0.0; + for ( i = 0; i < N; i++ ) { + ax = stdlib_base_abs( X[ ix ] ); + if ( ax > tbig ) { + abig += stdlib_base_abs2( ax * sbig ); + notbig = false; + } else if ( ax < tsml ) { + if ( notbig ) { + asml += stdlib_base_abs2( ax * ssml ); + } + } else { + amed += stdlib_base_abs2( ax ); + } + ix += stride; + } + // Combine `abig` and `amed` or `amed` and `asml` if more than one accumulator was used... + if ( abig > 0.0 ) { + // Combine `abig` and `amed` if `abig` > 0... + if ( amed > 0.0 || ( amed > STDLIB_CONSTANT_FLOAT64_MAX ) || ( amed != amed ) ) { + abig += ( amed * sbig ) * sbig; + } + scl = 1.0 / sbig; + sumsq = abig; + } else if ( asml > 0.0 ) { + // Combine `amed` and `asml` if `asml` > 0... + if ( amed > 0.0 || amed > STDLIB_CONSTANT_FLOAT64_MAX || ( amed != amed ) ) { + amed = stdlib_base_sqrt( amed ); + asml = stdlib_base_sqrt( asml ) / ssml; + if ( asml > amed ) { + ymin = amed; + ymax = asml; + } else { + ymin = asml; + ymax = amed; + } + scl = 1.0; + sumsq = stdlib_base_abs2( ymax ) * ( 1.0 + stdlib_base_abs2( ymin / ymax ) ); + } else { + scl = 1.0 / ssml; + sumsq = asml; + } + } else { + // All values are mid-range... + scl = 1.0; + sumsq = amed; + } + return stdlib_base_sqrt( sumsq ) * scl; +} diff --git a/lib/node_modules/@stdlib/blas/base/dnrm2/test/test.dnrm2.js b/lib/node_modules/@stdlib/blas/base/dnrm2/test/test.dnrm2.js index aa303af61d1..22a6a4b1316 100644 --- a/lib/node_modules/@stdlib/blas/base/dnrm2/test/test.dnrm2.js +++ b/lib/node_modules/@stdlib/blas/base/dnrm2/test/test.dnrm2.js @@ -92,18 +92,24 @@ tape( 'the function supports a `stride` parameter', function test( t ) { t.end(); }); -tape( 'if provided a `stride` parameter less than or equal to `0`, the function returns `0`', function test( t ) { +tape( 'the function supports a negative `stride` parameter', function test( t ) { var x; var z; - x = new Float64Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); - - z = dnrm2( x.length, x, 0 ); - t.strictEqual( z, 0.0, 'returns expected value' ); + x = new Float64Array([ + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ]); - z = dnrm2( x.length, x, -1 ); - t.strictEqual( z, 0.0, 'returns expected value' ); + z = dnrm2( 4, x, -2 ); + t.strictEqual( z, 5.0, 'returns expected value' ); t.end(); }); diff --git a/lib/node_modules/@stdlib/blas/base/dnrm2/test/test.dnrm2.native.js b/lib/node_modules/@stdlib/blas/base/dnrm2/test/test.dnrm2.native.js index 822c56743fb..9441031a1b2 100644 --- a/lib/node_modules/@stdlib/blas/base/dnrm2/test/test.dnrm2.native.js +++ b/lib/node_modules/@stdlib/blas/base/dnrm2/test/test.dnrm2.native.js @@ -101,18 +101,24 @@ tape( 'the function supports a `stride` parameter', opts, function test( t ) { t.end(); }); -tape( 'if provided a `stride` parameter less than or equal to `0`, the function returns `0`', opts, function test( t ) { +tape( 'the function supports a negative `stride` parameter', opts, function test( t ) { var x; var z; - x = new Float64Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); - - z = dnrm2( x.length, x, 0 ); - t.strictEqual( z, 0.0, 'returns expected value' ); + x = new Float64Array([ + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ]); - z = dnrm2( x.length, x, -1 ); - t.strictEqual( z, 0.0, 'returns expected value' ); + z = dnrm2( 4, x, -2 ); + t.strictEqual( z, 5.0, 'returns expected value' ); t.end(); }); diff --git a/lib/node_modules/@stdlib/blas/base/dnrm2/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/base/dnrm2/test/test.ndarray.js index 5f2bc2d2251..1962dcf9419 100644 --- a/lib/node_modules/@stdlib/blas/base/dnrm2/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/dnrm2/test/test.ndarray.js @@ -97,13 +97,13 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) var z; x = new Float64Array([ - 1.0, // 0 + 1.0, // 3 2.0, - 2.0, // 1 + 2.0, // 2 -7.0, - -2.0, // 2 + -2.0, // 1 3.0, - 4.0, // 3 + 4.0, // 0 2.0 ]); diff --git a/lib/node_modules/@stdlib/blas/base/dnrm2/test/test.ndarray.native.js b/lib/node_modules/@stdlib/blas/base/dnrm2/test/test.ndarray.native.js index 9932d8c2e83..541af646c82 100644 --- a/lib/node_modules/@stdlib/blas/base/dnrm2/test/test.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/base/dnrm2/test/test.ndarray.native.js @@ -106,13 +106,13 @@ tape( 'the function supports a negative `stride` parameter', opts, function test var z; x = new Float64Array([ - 1.0, // 0 + 1.0, // 3 2.0, - 2.0, // 1 + 2.0, // 2 -7.0, - -2.0, // 2 + -2.0, // 1 3.0, - 4.0, // 3 + 4.0, // 0 2.0 ]); diff --git a/lib/node_modules/@stdlib/blas/base/drot/README.md b/lib/node_modules/@stdlib/blas/base/drot/README.md index e06b96eee24..f12f5efce11 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/README.md +++ b/lib/node_modules/@stdlib/blas/base/drot/README.md @@ -230,6 +230,33 @@ The function accepts the following arguments: void c_drot( const CBLAS_INT N, double *X, const CBLAS_INT strideX, double *Y, const CBLAS_INT strideY, const double c, const double s ); ``` +#### c_drot_ndarray( N, \*X, strideX, offsetX, \*Y, strideY, offsetY, c, s ) + +Applies a plane rotation using alternative indexing semantics. + +```c +double x[] = { 1.0, 2.0, 3.0, 4.0, 5.0 }; +double y[] = { 6.0, 7.0, 8.0, 9.0, 10.0 }; + +c_drot_ndarray( 5, x, 1, 0, y, 1, 0, 0.8, 0.6 ); +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **X**: `[inout] double*` first input array. +- **strideX**: `[in] CBLAS_INT` index increment for `X`. +- **offsetX**: `[in] CBLAS_INT` starting index for `X`. +- **Y**: `[inout] double*` second input array. +- **strideY**: `[in] CBLAS_INT` index increment for `Y`. +- **offsetY**: `[in] CBLAS_INT` starting index for `Y`. +- **c**: `[in] double` cosine of the angle of rotation. +- **s**: `[in] double` sine of the angle of rotation. + +```c +void c_drot_ndarray( const CBLAS_INT N, double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, double *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY, const double c, const double s ); +``` + @@ -258,11 +285,11 @@ int main( void ) { double y[] = { 6.0, 7.0, 8.0, 9.0, 10.0 }; // Specify the number of elements: - const int N = 5; + const int N = 3; // Specify stride lengths: - const int strideX = 1; - const int strideY = 1; + const int strideX = 2; + const int strideY = -2; // Specify angle of rotation: const double c = 0.8; @@ -275,6 +302,14 @@ int main( void ) { for ( int i = 0; i < 5; i++ ) { printf( "x[ %i ] = %lf, y[ %i ] = %lf\n", i, x[ i ], i, y[ i ] ); } + + // Apply plane rotation: + c_drot_ndarray( N, x, strideX, 0, y, strideY, 4, c, s ); + + // Print the result: + for ( int i = 0; i < 5; i++ ) { + printf( "x[ %i ] = %lf, y[ %i ] = %lf\n", i, x[ i ], i, y[ i ] ); + } } ``` diff --git a/lib/node_modules/@stdlib/blas/base/drot/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/blas/base/drot/benchmark/c/benchmark.length.c index b522fce1d70..8bb1d80688f 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/blas/base/drot/benchmark/c/benchmark.length.c @@ -94,7 +94,7 @@ static double rand_double( void ) { * @param len array length * @return elapsed time in seconds */ -static double benchmark( int iterations, int len ) { +static double benchmark1( int iterations, int len ) { double elapsed; double x[ len ]; double y[ len ]; @@ -120,6 +120,39 @@ static double benchmark( int iterations, int len ) { return elapsed; } +/** +* Runs a benchmark. +* +* @param iterations number of iterations +* @param len array length +* @return elapsed time in seconds +*/ +static double benchmark2( int iterations, int len ) { + double elapsed; + double x[ len ]; + double y[ len ]; + double t; + int i; + + for ( i = 0; i < len; i++ ) { + x[ i ] = ( rand_double()*200.0 ) - 100.0; + y[ i ] = ( rand_double()*200.0 ) - 100.0; + } + t = tic(); + for ( i = 0; i < iterations; i++ ) { + c_drot_ndarray( len, x, 1, 0, y, 1, 0, 0.8, 0.6 ); + if ( y[ 0 ] != y[ 0 ] ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( y[ 0 ] != y[ 0 ] ) { + printf( "should not return NaN\n" ); + } + return elapsed; +} + /** * Main execution sequence. */ @@ -142,7 +175,14 @@ int main( void ) { for ( j = 0; j < REPEATS; j++ ) { count += 1; printf( "# c::%s:len=%d\n", NAME, len ); - elapsed = benchmark( iter, len ); + elapsed = benchmark1( iter, len ); + print_results( iter, elapsed ); + printf( "ok %d benchmark finished\n", count ); + } + for ( j = 0; j < REPEATS; j++ ) { + count += 1; + printf( "# c::%s:ndarray:len=%d\n", NAME, len ); + elapsed = benchmark2( iter, len ); print_results( iter, elapsed ); printf( "ok %d benchmark finished\n", count ); } diff --git a/lib/node_modules/@stdlib/blas/base/drot/examples/c/example.c b/lib/node_modules/@stdlib/blas/base/drot/examples/c/example.c index 86c9fd5c41b..ff492f3f55c 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/examples/c/example.c +++ b/lib/node_modules/@stdlib/blas/base/drot/examples/c/example.c @@ -25,11 +25,11 @@ int main( void ) { double y[] = { 6.0, 7.0, 8.0, 9.0, 10.0 }; // Specify the number of elements: - const int N = 5; + const int N = 3; // Specify stride lengths: - const int strideX = 1; - const int strideY = 1; + const int strideX = 2; + const int strideY = -2; // Specify angle of rotation: const double c = 0.8; @@ -42,4 +42,12 @@ int main( void ) { for ( int i = 0; i < 5; i++ ) { printf( "x[ %i ] = %lf, y[ %i ] = %lf\n", i, x[ i ], i, y[ i ] ); } + + // Apply plane rotation: + c_drot_ndarray( N, x, strideX, 0, y, strideY, 4, c, s ); + + // Print the result: + for ( int i = 0; i < 5; i++ ) { + printf( "x[ %i ] = %lf, y[ %i ] = %lf\n", i, x[ i ], i, y[ i ] ); + } } diff --git a/lib/node_modules/@stdlib/blas/base/drot/include/stdlib/blas/base/drot.h b/lib/node_modules/@stdlib/blas/base/drot/include/stdlib/blas/base/drot.h index 5042ea4cb30..2d62297f1fd 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/include/stdlib/blas/base/drot.h +++ b/lib/node_modules/@stdlib/blas/base/drot/include/stdlib/blas/base/drot.h @@ -36,6 +36,11 @@ extern "C" { */ void API_SUFFIX(c_drot)( const CBLAS_INT N, double *X, const CBLAS_INT strideX, double *Y, const CBLAS_INT strideY, const double c, const double s ); +/** +* Applies a plane rotation using alternative indexing semantics. +*/ +void API_SUFFIX(c_drot_ndarray)( const CBLAS_INT N, double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, double *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY, const double c, const double s ); + #ifdef __cplusplus } #endif diff --git a/lib/node_modules/@stdlib/blas/base/drot/lib/ndarray.native.js b/lib/node_modules/@stdlib/blas/base/drot/lib/ndarray.native.js index fd2d583bb32..f101e40b215 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/lib/ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/base/drot/lib/ndarray.native.js @@ -20,9 +20,7 @@ // MODULES // -var minViewBufferIndex = require( '@stdlib/strided/base/min-view-buffer-index' ); -var offsetView = require( '@stdlib/strided/base/offset-view' ); -var addon = require( './drot.native.js' ); +var addon = require( './../src/addon.node' ); // MAIN // @@ -52,16 +50,7 @@ var addon = require( './drot.native.js' ); * // y => [ 6.0, 4.4, ~4.6, ~4.8, 5.0 ] */ function drot( N, x, strideX, offsetX, y, strideY, offsetY, c, s ) { - var viewX; - var viewY; - - offsetX = minViewBufferIndex( N, strideX, offsetX ); - offsetY = minViewBufferIndex( N, strideY, offsetY ); - - viewX = offsetView( x, offsetX ); - viewY = offsetView( y, offsetY ); - - addon( N, viewX, strideX, viewY, strideY, c, s ); + addon.ndarray( N, x, strideX, offsetX, y, strideY, offsetY, c, s ); return y; } diff --git a/lib/node_modules/@stdlib/blas/base/drot/manifest.json b/lib/node_modules/@stdlib/blas/base/drot/manifest.json index fa3bb61162c..83614c2f493 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/manifest.json +++ b/lib/node_modules/@stdlib/blas/base/drot/manifest.json @@ -44,11 +44,12 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/napi/export", "@stdlib/napi/argv", + "@stdlib/napi/argv-double", "@stdlib/napi/argv-int64", - "@stdlib/napi/argv-strided-float64array", - "@stdlib/napi/argv-double" + "@stdlib/napi/argv-strided-float64array" ] }, { @@ -57,7 +58,8 @@ "blas": "", "wasm": false, "src": [ - "./src/drot.c" + "./src/drot.c", + "./src/drot_ndarray.c" ], "include": [ "./include" @@ -65,7 +67,8 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] }, { @@ -74,7 +77,8 @@ "blas": "", "wasm": false, "src": [ - "./src/drot.c" + "./src/drot.c", + "./src/drot_ndarray.c" ], "include": [ "./include" @@ -82,7 +86,8 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] }, @@ -104,11 +109,12 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/napi/export", "@stdlib/napi/argv", + "@stdlib/napi/argv-double", "@stdlib/napi/argv-int64", - "@stdlib/napi/argv-strided-float64array", - "@stdlib/napi/argv-double" + "@stdlib/napi/argv-strided-float64array" ] }, { @@ -128,7 +134,8 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index" ] }, { @@ -148,7 +155,8 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index" ] }, @@ -168,11 +176,12 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/napi/export", "@stdlib/napi/argv", + "@stdlib/napi/argv-double", "@stdlib/napi/argv-int64", - "@stdlib/napi/argv-strided-float64array", - "@stdlib/napi/argv-double" + "@stdlib/napi/argv-strided-float64array" ] }, { @@ -181,7 +190,8 @@ "blas": "", "wasm": false, "src": [ - "./src/drot.c" + "./src/drot.c", + "./src/drot_ndarray.c" ], "include": [ "./include" @@ -189,7 +199,8 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] }, { @@ -198,7 +209,8 @@ "blas": "", "wasm": false, "src": [ - "./src/drot.c" + "./src/drot.c", + "./src/drot_ndarray.c" ], "include": [ "./include" @@ -206,7 +218,8 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] }, @@ -227,11 +240,12 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/napi/export", "@stdlib/napi/argv", + "@stdlib/napi/argv-double", "@stdlib/napi/argv-int64", - "@stdlib/napi/argv-strided-float64array", - "@stdlib/napi/argv-double" + "@stdlib/napi/argv-strided-float64array" ] }, { @@ -250,7 +264,8 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index" ] }, { @@ -269,7 +284,8 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index" ] }, @@ -291,11 +307,12 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/napi/export", "@stdlib/napi/argv", + "@stdlib/napi/argv-double", "@stdlib/napi/argv-int64", - "@stdlib/napi/argv-strided-float64array", - "@stdlib/napi/argv-double" + "@stdlib/napi/argv-strided-float64array" ] }, { @@ -315,7 +332,8 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index" ] }, { @@ -335,7 +353,8 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index" ] }, @@ -345,7 +364,8 @@ "blas": "", "wasm": false, "src": [ - "./src/drot.c" + "./src/drot.c", + "./src/drot_ndarray.c" ], "include": [ "./include" @@ -354,11 +374,12 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset", "@stdlib/napi/export", "@stdlib/napi/argv", + "@stdlib/napi/argv-double", "@stdlib/napi/argv-int64", - "@stdlib/napi/argv-strided-float64array", - "@stdlib/napi/argv-double" + "@stdlib/napi/argv-strided-float64array" ] }, { @@ -367,7 +388,8 @@ "blas": "", "wasm": false, "src": [ - "./src/drot.c" + "./src/drot.c", + "./src/drot_ndarray.c" ], "include": [ "./include" @@ -375,7 +397,8 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] }, { @@ -384,7 +407,8 @@ "blas": "", "wasm": false, "src": [ - "./src/drot.c" + "./src/drot.c", + "./src/drot_ndarray.c" ], "include": [ "./include" @@ -392,7 +416,8 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] }, @@ -402,7 +427,8 @@ "blas": "", "wasm": true, "src": [ - "./src/drot.c" + "./src/drot.c", + "./src/drot_ndarray.c" ], "include": [ "./include" @@ -410,7 +436,8 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] } ] diff --git a/lib/node_modules/@stdlib/blas/base/drot/src/addon.c b/lib/node_modules/@stdlib/blas/base/drot/src/addon.c index c98a80dbd01..43f51971ce9 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/src/addon.c +++ b/lib/node_modules/@stdlib/blas/base/drot/src/addon.c @@ -45,4 +45,26 @@ static napi_value addon( napi_env env, napi_callback_info info ) { return NULL; } -STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) +/** +* Receives JavaScript callback invocation data. +* +* @param env environment under which the function is invoked +* @param info callback data +* @return Node-API value +*/ +static napi_value addon_method( napi_env env, napi_callback_info info ) { + STDLIB_NAPI_ARGV( env, info, argv, argc, 9 ); + STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 2 ); + STDLIB_NAPI_ARGV_INT64( env, offsetX, argv, 3 ); + STDLIB_NAPI_ARGV_INT64( env, strideY, argv, 5 ); + STDLIB_NAPI_ARGV_INT64( env, offsetY, argv, 6 ); + STDLIB_NAPI_ARGV_DOUBLE( env, c, argv, 7 ); + STDLIB_NAPI_ARGV_DOUBLE( env, s, argv, 8 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, strideX, argv, 1 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, Y, N, strideY, argv, 4 ); + API_SUFFIX(c_drot_ndarray)( N, X, strideX, offsetX, Y, strideY, offsetY, c, s ); + return NULL; +} + +STDLIB_NAPI_MODULE_EXPORT_FCN_WITH_METHOD( addon, "ndarray", addon_method ) diff --git a/lib/node_modules/@stdlib/blas/base/drot/src/drot.c b/lib/node_modules/@stdlib/blas/base/drot/src/drot.c index 14c5e8ea644..0a617c2a401 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/src/drot.c +++ b/lib/node_modules/@stdlib/blas/base/drot/src/drot.c @@ -18,6 +18,7 @@ #include "stdlib/blas/base/drot.h" #include "stdlib/blas/base/shared.h" +#include "stdlib/strided/base/stride2offset.h" /** * Applies a plane rotation. @@ -31,40 +32,8 @@ * @param s sine of the angle of rotation */ void API_SUFFIX(c_drot)( const CBLAS_INT N, double *X, const CBLAS_INT strideX, double *Y, const CBLAS_INT strideY, const double c, const double s ) { - double tmp; - CBLAS_INT ix; - CBLAS_INT iy; - CBLAS_INT i; - - if ( N <= 0 ) { - return; - } - // If both strides are equal to `1`... - if ( strideX == 1 && strideY == 1 ) { - for ( i = 0; i < N; i++ ) { - tmp = ( c * X[ i ] ) + ( s * Y[ i ] ); - Y[ i ] = ( c * Y[ i ] ) - ( s * X[ i ] ); - X[ i ] = tmp; - } - return; - } - // If both strides are not equal to `1`... - if ( strideX < 0 ) { - ix = ( 1 - N ) * strideX; - } else { - ix = 0; - } - if ( strideY < 0 ) { - iy = ( 1 - N ) * strideY; - } else { - iy = 0; - } - for ( i = 0; i < N; i++ ) { - tmp = ( c * X[ ix ] ) + ( s * Y[ iy ] ); - Y[ iy ] = ( c * Y[ iy ] ) - ( s * X[ ix ] ); - X[ ix ] = tmp; - ix += strideX; - iy += strideY; - } + CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX ); + CBLAS_INT oy = stdlib_strided_stride2offset( N, strideY ); + API_SUFFIX(c_drot_ndarray)( N, X, strideX, ox, Y, strideY, oy, c, s ); return; } diff --git a/lib/node_modules/@stdlib/blas/base/drot/src/drot_cblas.c b/lib/node_modules/@stdlib/blas/base/drot/src/drot_cblas.c index 7c557e79df0..d58272128d5 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/src/drot_cblas.c +++ b/lib/node_modules/@stdlib/blas/base/drot/src/drot_cblas.c @@ -19,6 +19,7 @@ #include "stdlib/blas/base/drot.h" #include "stdlib/blas/base/drot_cblas.h" #include "stdlib/blas/base/shared.h" +#include "stdlib/strided/base/min_view_buffer_index.h" /** * Applies a plane rotation. @@ -34,3 +35,22 @@ void API_SUFFIX(c_drot)( const CBLAS_INT N, double *X, const CBLAS_INT strideX, double *Y, const CBLAS_INT strideY, const double c, const double s ) { API_SUFFIX(cblas_drot)( N, X, strideX, Y, strideY, c, s ); } + +/** +* Applies a plane rotation using alternative indexing semantics. +* +* @param N number of indexed elements +* @param X input array +* @param strideX X stride length +* @param offsetX starting index for X +* @param Y output array +* @param strideY Y stride length +* @param offsetY starting index for Y +* @param c cosine of the angle of rotation +* @param s sine of the angle of rotation +*/ +void API_SUFFIX(c_drot_ndarray)( const CBLAS_INT N, double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, double *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY, const double c, const double s ) { + X += stdlib_strided_min_view_buffer_index( N, strideX, offsetX ); // adjust array pointer + Y += stdlib_strided_min_view_buffer_index( N, strideY, offsetY ); // adjust array pointer + API_SUFFIX(cblas_drot)( N, alpha, X, strideX, Y, strideY ); +} diff --git a/lib/node_modules/@stdlib/blas/base/drot/src/drot_f.c b/lib/node_modules/@stdlib/blas/base/drot/src/drot_f.c index 3546a520363..99e15935655 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/src/drot_f.c +++ b/lib/node_modules/@stdlib/blas/base/drot/src/drot_f.c @@ -19,6 +19,7 @@ #include "stdlib/blas/base/drot.h" #include "stdlib/blas/base/drot_fortran.h" #include "stdlib/blas/base/shared.h" +#include "stdlib/strided/base/min_view_buffer_index.h" /** * Applies a plane rotation. @@ -34,3 +35,22 @@ void API_SUFFIX(c_drot)( const CBLAS_INT N, double *X, const CBLAS_INT strideX, double *Y, const CBLAS_INT strideY, const double c, const double s ) { drot( &N, X, &strideX, Y, &strideY, &c, &s ); } + +/** +* Applies a plane rotation using alternative indexing semantics. +* +* @param N number of indexed elements +* @param X input array +* @param strideX X stride length +* @param offsetX starting index for X +* @param Y output array +* @param strideY Y stride length +* @param offsetY starting index for Y +* @param c cosine of the angle of rotation +* @param s sine of the angle of rotation +*/ +void API_SUFFIX(c_drot_ndarray)( const CBLAS_INT N, double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, double *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY, const double c, const double s ) { + X += stdlib_strided_min_view_buffer_index( N, strideX, offsetX ); // adjust array pointer + Y += stdlib_strided_min_view_buffer_index( N, strideY, offsetY ); // adjust array pointer + drot( &N, X, &strideX, Y, &strideY, &c, &s ); +} diff --git a/lib/node_modules/@stdlib/blas/base/drot/src/drot_ndarray.c b/lib/node_modules/@stdlib/blas/base/drot/src/drot_ndarray.c new file mode 100644 index 00000000000..716b441e37d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drot/src/drot_ndarray.c @@ -0,0 +1,54 @@ +/** +* @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. +*/ + +#include "stdlib/blas/base/drot.h" +#include "stdlib/blas/base/shared.h" + +/** +* Applies a plane rotation using alternative indexing semantics. +* +* @param N number of indexed elements +* @param X input array +* @param strideX X stride length +* @param offsetX starting index for X +* @param Y output array +* @param strideY Y stride length +* @param offsetY starting index for Y +* @param c cosine of the angle of rotation +* @param s sine of the angle of rotation +*/ +void API_SUFFIX(c_drot_ndarray)( const CBLAS_INT N, double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, double *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY, const double c, const double s ) { + double tmp; + CBLAS_INT ix; + CBLAS_INT iy; + CBLAS_INT i; + + if ( N <= 0 ) { + return; + } + ix = offsetX; + iy = offsetY; + for ( i = 0; i < N; i++ ) { + tmp = ( c * X[ ix ] ) + ( s * Y[ iy ] ); + Y[ iy ] = ( c * Y[ iy ] ) - ( s * X[ ix ] ); + X[ ix ] = tmp; + ix += strideX; + iy += strideY; + } + return; +} diff --git a/lib/node_modules/@stdlib/blas/base/drotm/README.md b/lib/node_modules/@stdlib/blas/base/drotm/README.md index cb081be59f5..1c3cbd62281 100644 --- a/lib/node_modules/@stdlib/blas/base/drotm/README.md +++ b/lib/node_modules/@stdlib/blas/base/drotm/README.md @@ -223,6 +223,33 @@ The function accepts the following arguments: void c_drotm( const CBLAS_INT N, double *X, const CBLAS_INT strideX, double *Y, const CBLAS_INT strideY, const double *param ); ``` +#### c_drotm_ndarray( N, \*X, strideX, offsetX, \*Y, strideY, offsetY, param ) + +Applies a modified Givens plane rotation using alternative indexing semantics. + +```c +double x[] = { 1.0, 2.0, 3.0, 4.0, 5.0 }; +double y[] = { 6.0, 7.0, 8.0, 9.0, 10.0 }; +const double param[5] = { 0.0, 0.0, 2.0, -3.0, 0.0 }; + +c_drotm_ndarray( 5, x, -1, 4, y, -1, 4, param ); +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **X**: `[inout] double*` first input array. +- **strideX**: `[in] CBLAS_INT` index increment for `X`. +- **offsetX**: `[in] CBLAS_INT` starting index for `X`. +- **Y**: `[inout] double*` second input array. +- **strideY**: `[in] CBLAS_INT` index increment for `Y`. +- **offsetY**: `[in] CBLAS_INT` starting index for `Y`. +- **param**: `[in] double` parameters for the modified Givens transformation. + +```c +void c_drotm_ndarray( const CBLAS_INT N, double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, double *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY, const double *param ); +``` + @@ -267,6 +294,14 @@ int main( void ) { for ( int i = 0; i < 5; i++ ) { printf( "x[ %i ] = %lf, y[ %i ] = %lf\n", i, x[ i ], i, y[ i ] ); } + + // Apply plane rotation: + c_drotm_ndarray( N, x, -strideX, N-1, y, -strideY, N-1, param ); + + // Print the result: + for ( int i = 0; i < 5; i++ ) { + printf( "x[ %i ] = %lf, y[ %i ] = %lf\n", i, x[ i ], i, y[ i ] ); + } } ``` diff --git a/lib/node_modules/@stdlib/blas/base/drotm/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/blas/base/drotm/benchmark/c/benchmark.length.c index acdd303740f..2af81b067cd 100644 --- a/lib/node_modules/@stdlib/blas/base/drotm/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/blas/base/drotm/benchmark/c/benchmark.length.c @@ -94,7 +94,7 @@ static double rand_double( void ) { * @param len array length * @return elapsed time in seconds */ -static double benchmark( int iterations, int len ) { +static double benchmark1( int iterations, int len ) { double elapsed; double x[ len ]; double y[ len ]; @@ -122,6 +122,41 @@ static double benchmark( int iterations, int len ) { return elapsed; } +/** +* Runs a benchmark. +* +* @param iterations number of iterations +* @param len array length +* @return elapsed time in seconds +*/ +static double benchmark2( int iterations, int len ) { + double elapsed; + double x[ len ]; + double y[ len ]; + double t; + int i; + + const double param[5] = { 0.0, 0.0, 0.0, 0.0, 0.0 }; + for ( i = 0; i < len; i++ ) { + x[ i ] = ( rand_double()*200.0 ) - 100.0; + y[ i ] = ( rand_double()*200.0 ) - 100.0; + } + + t = tic(); + for ( i = 0; i < iterations; i++ ) { + c_drotm_ndarray( len, x, 1, 0, y, 1, 0, param ); + if ( y[ 0 ] != y[ 0 ] ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( y[ 0 ] != y[ 0 ] ) { + printf( "should not return NaN\n" ); + } + return elapsed; +} + /** * Main execution sequence. */ @@ -144,7 +179,14 @@ int main( void ) { for ( j = 0; j < REPEATS; j++ ) { count += 1; printf( "# c::%s:len=%d\n", NAME, len ); - elapsed = benchmark( iter, len ); + elapsed = benchmark1( iter, len ); + print_results( iter, elapsed ); + printf( "ok %d benchmark finished\n", count ); + } + for ( j = 0; j < REPEATS; j++ ) { + count += 1; + printf( "# c::%s:ndarray:len=%d\n", NAME, len ); + elapsed = benchmark2( iter, len ); print_results( iter, elapsed ); printf( "ok %d benchmark finished\n", count ); } diff --git a/lib/node_modules/@stdlib/blas/base/drotm/examples/c/example.c b/lib/node_modules/@stdlib/blas/base/drotm/examples/c/example.c index 41f1bada0a9..ebf177a066a 100644 --- a/lib/node_modules/@stdlib/blas/base/drotm/examples/c/example.c +++ b/lib/node_modules/@stdlib/blas/base/drotm/examples/c/example.c @@ -41,4 +41,12 @@ int main( void ) { for ( int i = 0; i < 5; i++ ) { printf( "x[ %i ] = %lf, y[ %i ] = %lf\n", i, x[ i ], i, y[ i ] ); } + + // Apply plane rotation: + c_drotm_ndarray( N, x, -strideX, N-1, y, -strideY, N-1, param ); + + // Print the result: + for ( int i = 0; i < 5; i++ ) { + printf( "x[ %i ] = %lf, y[ %i ] = %lf\n", i, x[ i ], i, y[ i ] ); + } } diff --git a/lib/node_modules/@stdlib/blas/base/drotm/include/stdlib/blas/base/drotm.h b/lib/node_modules/@stdlib/blas/base/drotm/include/stdlib/blas/base/drotm.h index a2781b54bbb..a84806149be 100644 --- a/lib/node_modules/@stdlib/blas/base/drotm/include/stdlib/blas/base/drotm.h +++ b/lib/node_modules/@stdlib/blas/base/drotm/include/stdlib/blas/base/drotm.h @@ -36,6 +36,11 @@ extern "C" { */ void API_SUFFIX(c_drotm)( const CBLAS_INT N, double *X, const CBLAS_INT strideX, double *Y, const CBLAS_INT strideY, const double *param ); +/** +* Applies a modified Givens plane rotation using alternative indexing semantics. +*/ +void API_SUFFIX(c_drotm_ndarray)( const CBLAS_INT N, double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, double *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY, const double *param ); + #ifdef __cplusplus } #endif diff --git a/lib/node_modules/@stdlib/blas/base/drotm/lib/drotm.js b/lib/node_modules/@stdlib/blas/base/drotm/lib/drotm.js index a529c9c5fc5..22bdc2601d4 100644 --- a/lib/node_modules/@stdlib/blas/base/drotm/lib/drotm.js +++ b/lib/node_modules/@stdlib/blas/base/drotm/lib/drotm.js @@ -49,16 +49,8 @@ var ndarray = require( './ndarray.js' ); * // y => [ 1.7, -0.9, 0.5, 0.7, -1.6, 0.2, 2.4 ] */ function drotm( N, x, strideX, y, strideY, param ) { - var dflag; - var ix; - var iy; - - dflag = param[ 0 ]; - if ( N <= 0 || dflag === -2.0 ) { - return y; - } - ix = stride2offset( N, strideX ); - iy = stride2offset( N, strideY ); + var ix = stride2offset( N, strideX ); + var iy = stride2offset( N, strideY ); return ndarray( N, x, strideX, ix, y, strideY, iy, param ); } diff --git a/lib/node_modules/@stdlib/blas/base/drotm/lib/ndarray.js b/lib/node_modules/@stdlib/blas/base/drotm/lib/ndarray.js index d2bafae0c0f..766717ea5e3 100644 --- a/lib/node_modules/@stdlib/blas/base/drotm/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/drotm/lib/ndarray.js @@ -26,10 +26,10 @@ * @param {PositiveInteger} N - number of indexed elements * @param {Float64Array} x - first input array * @param {integer} strideX - `x` stride length -* @param {NonNegativeInteger} offsetX - starting `x` index +* @param {NonNegativeInteger} offsetX - starting index for `x` * @param {Float64Array} y - second input array * @param {integer} strideY - `y` stride length -* @param {NonNegativeInteger} offsetY - starting `y` index +* @param {NonNegativeInteger} offsetY - starting index for `y` * @param {Float64Array} param - parameters for the modified Givens transformation * @returns {Float64Array} `y` * diff --git a/lib/node_modules/@stdlib/blas/base/drotm/lib/ndarray.native.js b/lib/node_modules/@stdlib/blas/base/drotm/lib/ndarray.native.js index fde49ad2efb..e6a4bd92ff2 100644 --- a/lib/node_modules/@stdlib/blas/base/drotm/lib/ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/base/drotm/lib/ndarray.native.js @@ -20,9 +20,7 @@ // MODULES // -var minViewBufferIndex = require( '@stdlib/strided/base/min-view-buffer-index' ); -var offsetView = require( '@stdlib/strided/base/offset-view' ); -var addon = require( './drotm.native.js' ); +var addon = require( './../src/addon.node' ); // MAIN // @@ -33,10 +31,10 @@ var addon = require( './drotm.native.js' ); * @param {PositiveInteger} N - number of indexed elements * @param {Float64Array} x - first input array * @param {integer} strideX - `x` stride length -* @param {NonNegativeInteger} offsetX - starting `x` index +* @param {NonNegativeInteger} offsetX - starting index for `x` * @param {Float64Array} y - second input array * @param {integer} strideY - `y` stride length -* @param {NonNegativeInteger} offsetY - starting `y` index +* @param {NonNegativeInteger} offsetY - starting index for `y` * @param {Float64Array} param - parameters for the modified Givens transformation * @returns {Float64Array} `y` * @@ -52,16 +50,7 @@ var addon = require( './drotm.native.js' ); * // y => [ 1.7, -0.9, 0.5, 0.7, -1.6, 0.2, 2.4 ] */ function drotm( N, x, strideX, offsetX, y, strideY, offsetY, param ) { - var viewX; - var viewY; - - offsetX = minViewBufferIndex( N, strideX, offsetX ); - offsetY = minViewBufferIndex( N, strideY, offsetY ); - - viewX = offsetView( x, offsetX ); - viewY = offsetView( y, offsetY ); - - addon( N, viewX, strideX, viewY, strideY, param ); + addon.ndarray( N, x, strideX, offsetX, y, strideY, offsetY, param ); return y; } diff --git a/lib/node_modules/@stdlib/blas/base/drotm/manifest.json b/lib/node_modules/@stdlib/blas/base/drotm/manifest.json index c4a0be751a6..49b335b9139 100644 --- a/lib/node_modules/@stdlib/blas/base/drotm/manifest.json +++ b/lib/node_modules/@stdlib/blas/base/drotm/manifest.json @@ -44,6 +44,7 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/napi/export", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", @@ -57,7 +58,8 @@ "blas": "", "wasm": false, "src": [ - "./src/drotm.c" + "./src/drotm.c", + "./src/drotm_ndarray.c" ], "include": [ "./include" @@ -65,7 +67,8 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] }, { @@ -74,7 +77,8 @@ "blas": "", "wasm": false, "src": [ - "./src/drotm.c" + "./src/drotm.c", + "./src/drotm_ndarray.c" ], "include": [ "./include" @@ -82,7 +86,8 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] }, @@ -104,6 +109,7 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/napi/export", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", @@ -128,7 +134,8 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index" ] }, { @@ -148,7 +155,8 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index" ] }, @@ -168,6 +176,7 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/napi/export", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", @@ -181,7 +190,8 @@ "blas": "", "wasm": false, "src": [ - "./src/drotm.c" + "./src/drotm.c", + "./src/drotm_ndarray.c" ], "include": [ "./include" @@ -189,7 +199,8 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] }, { @@ -198,7 +209,8 @@ "blas": "", "wasm": false, "src": [ - "./src/drotm.c" + "./src/drotm.c", + "./src/drotm_ndarray.c" ], "include": [ "./include" @@ -206,7 +218,8 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] }, @@ -227,6 +240,7 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/napi/export", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", @@ -250,7 +264,8 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index" ] }, { @@ -269,7 +284,8 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index" ] }, @@ -291,6 +307,7 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/napi/export", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", @@ -315,7 +332,8 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index" ] }, { @@ -335,7 +353,8 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index" ] }, @@ -345,7 +364,8 @@ "blas": "", "wasm": false, "src": [ - "./src/drotm.c" + "./src/drotm.c", + "./src/drotm_ndarray.c" ], "include": [ "./include" @@ -354,6 +374,7 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset", "@stdlib/napi/export", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", @@ -367,7 +388,8 @@ "blas": "", "wasm": false, "src": [ - "./src/drotm.c" + "./src/drotm.c", + "./src/drotm_ndarray.c" ], "include": [ "./include" @@ -375,7 +397,8 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] }, { @@ -384,7 +407,8 @@ "blas": "", "wasm": false, "src": [ - "./src/drotm.c" + "./src/drotm.c", + "./src/drotm_ndarray.c" ], "include": [ "./include" @@ -392,7 +416,8 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] }, @@ -402,7 +427,8 @@ "blas": "", "wasm": true, "src": [ - "./src/drotm.c" + "./src/drotm.c", + "./src/drotm_ndarray.c" ], "include": [ "./include" @@ -410,7 +436,8 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] } ] diff --git a/lib/node_modules/@stdlib/blas/base/drotm/src/addon.c b/lib/node_modules/@stdlib/blas/base/drotm/src/addon.c index 2f9038b228d..4711afe7d89 100644 --- a/lib/node_modules/@stdlib/blas/base/drotm/src/addon.c +++ b/lib/node_modules/@stdlib/blas/base/drotm/src/addon.c @@ -44,4 +44,25 @@ static napi_value addon( napi_env env, napi_callback_info info ) { return NULL; } -STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) +/** +* Receives JavaScript callback invocation data. +* +* @param env environment under which the function is invoked +* @param info callback data +* @return Node-API value +*/ +static napi_value addon_method( napi_env env, napi_callback_info info ) { + STDLIB_NAPI_ARGV( env, info, argv, argc, 8 ); + STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 2 ); + STDLIB_NAPI_ARGV_INT64( env, offsetX, argv, 3 ); + STDLIB_NAPI_ARGV_INT64( env, strideY, argv, 5 ); + STDLIB_NAPI_ARGV_INT64( env, offsetY, argv, 6 ); + STDLIB_NAPI_ARGV_FLOAT64ARRAY( env, param, paramlen, argv, 7 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, strideX, argv, 1 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, Y, N, strideY, argv, 4 ); + API_SUFFIX(c_drotm_ndarray)( N, X, strideX, offsetX, Y, strideY, offsetY, param ); + return NULL; +} + +STDLIB_NAPI_MODULE_EXPORT_FCN_WITH_METHOD( addon, "ndarray", addon_method ) diff --git a/lib/node_modules/@stdlib/blas/base/drotm/src/drotm.c b/lib/node_modules/@stdlib/blas/base/drotm/src/drotm.c index f568ab1de61..ec5a3ec725e 100644 --- a/lib/node_modules/@stdlib/blas/base/drotm/src/drotm.c +++ b/lib/node_modules/@stdlib/blas/base/drotm/src/drotm.c @@ -18,6 +18,7 @@ #include "stdlib/blas/base/drotm.h" #include "stdlib/blas/base/shared.h" +#include "stdlib/strided/base/stride2offset.h" /** * Applies a plane rotation. @@ -30,107 +31,7 @@ * @param param parameters for the modified Givens transformation */ void API_SUFFIX(c_drotm)( const CBLAS_INT N, double *X, const CBLAS_INT strideX, double *Y, const CBLAS_INT strideY, const double *param ) { - CBLAS_INT ix; - CBLAS_INT iy; - double dflag; - double dh11; - double dh12; - double dh21; - double dh22; - CBLAS_INT i; - double w; - double z; - - dflag = param[ 0 ]; - if ( N <= 0 || dflag == -2.0 ) { - return; - } - if ( strideX == strideY && strideX > 0 ) { - ix = 0; - if ( dflag < 0.0 ) { - dh11 = param[ 1 ]; - dh12 = param[ 3 ]; - dh21 = param[ 2 ]; - dh22 = param[ 4 ]; - for ( i = 0; i < N; i++ ) { - w = X[ ix ]; - z = Y[ ix ]; - X[ ix ] = ( w * dh11 ) + ( z * dh12 ); - Y[ ix ] = ( w * dh21 ) + ( z * dh22 ); - ix += strideX; - } - return; - } - if ( dflag == 0.0 ) { - dh12 = param[ 3 ]; - dh21 = param[ 2 ]; - for ( i = 0; i < N; i++ ) { - w = X[ ix ]; - z = Y[ ix ]; - X[ ix ] = w + ( z * dh12 ); - Y[ ix ] = ( w * dh21 ) + z; - ix += strideX; - } - return; - } - dh11 = param[ 1 ]; - dh22 = param[ 4 ]; - for ( i = 0; i < N; i++ ) { - w = X[ ix ]; - z = Y[ ix ]; - X[ ix ] = ( w * dh11 ) + z; - Y[ ix ] = -w + ( z * dh22 ); - ix += strideX; - } - return; - } - if ( strideX < 0 ) { - ix = ( 1 - N ) * strideX; - } else { - ix = 0; - } - if ( strideY < 0 ) { - iy = ( 1 - N ) * strideY; - } else { - iy = 0; - } - if ( dflag < 0.0 ) { - dh11 = param[ 1 ]; - dh12 = param[ 3 ]; - dh21 = param[ 2 ]; - dh22 = param[ 4 ]; - for ( i = 0; i < N; i++ ) { - w = X[ ix ]; - z = Y[ iy ]; - X[ ix ] = ( w * dh11 ) + ( z * dh12 ); - Y[ iy ] = ( w * dh21 ) + ( z * dh22 ); - ix += strideX; - iy += strideY; - } - return; - } - if ( dflag == 0.0 ) { - dh12 = param[ 3 ]; - dh21 = param[ 2 ]; - for ( i = 0; i < N; i++ ) { - w = X[ ix ]; - z = Y[ iy ]; - X[ ix ] = w + ( z * dh12 ); - Y[ iy ] = ( w * dh21 ) + z; - ix += strideX; - iy += strideY; - } - return; - } - dh11 = param[ 1 ]; - dh22 = param[ 4 ]; - for ( i = 0; i < N; i++ ) { - w = X[ ix ]; - z = Y[ iy ]; - X[ ix ] = ( w * dh11 ) + z; - Y[ iy ] = -w + ( z * dh22 ); - ix += strideX; - iy += strideY; - } - return; + CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX ); + CBLAS_INT oy = stdlib_strided_stride2offset( N, strideY ); + API_SUFFIX(c_drotm_ndarray)( N, X, strideX, ox, Y, strideY, oy, param ); } diff --git a/lib/node_modules/@stdlib/blas/base/drotm/src/drotm_cblas.c b/lib/node_modules/@stdlib/blas/base/drotm/src/drotm_cblas.c index 5dc04f172c0..c228a40bda1 100644 --- a/lib/node_modules/@stdlib/blas/base/drotm/src/drotm_cblas.c +++ b/lib/node_modules/@stdlib/blas/base/drotm/src/drotm_cblas.c @@ -19,6 +19,7 @@ #include "stdlib/blas/base/drotm.h" #include "stdlib/blas/base/drotm_cblas.h" #include "stdlib/blas/base/shared.h" +#include "stdlib/strided/base/min_view_buffer_index.h" /** * Applies a modified Givens plane rotation. @@ -33,3 +34,21 @@ void API_SUFFIX(c_drotm)( const CBLAS_INT N, double *X, const CBLAS_INT strideX, double *Y, const CBLAS_INT strideY, const double *param ) { API_SUFFIX(cblas_drotm)( N, X, strideX, Y, strideY, param ); } + +/** +* Applies a modified Givens plane rotation using alternative indexing semantics. +* +* @param N number of indexed elements +* @param X first input array +* @param strideX X stride length +* @param offsetX starting index for X +* @param Y second input array +* @param strideY Y stride length +* @param offsetY starting index for Y +* @param param parameters for the modified Givens transformation +*/ +void API_SUFFIX(c_drotm_ndarray)( const CBLAS_INT N, double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, double *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY, const double *param ) { + X += stdlib_strided_min_view_buffer_index( N, strideX, offsetX ); // adjust array pointer + Y += stdlib_strided_min_view_buffer_index( N, strideY, offsetY ); // adjust array pointer + API_SUFFIX(cblas_drotm)( N, X, strideX, Y, strideY, param ); +} diff --git a/lib/node_modules/@stdlib/blas/base/drotm/src/drotm_f.c b/lib/node_modules/@stdlib/blas/base/drotm/src/drotm_f.c index b1c3bcb3583..889a7f7bb01 100644 --- a/lib/node_modules/@stdlib/blas/base/drotm/src/drotm_f.c +++ b/lib/node_modules/@stdlib/blas/base/drotm/src/drotm_f.c @@ -19,6 +19,7 @@ #include "stdlib/blas/base/drotm.h" #include "stdlib/blas/base/drotm_fortran.h" #include "stdlib/blas/base/shared.h" +#include "stdlib/strided/base/min_view_buffer_index.h" /** * Applies a modified Givens plane rotation. @@ -33,3 +34,21 @@ void API_SUFFIX(c_drotm)( const CBLAS_INT N, double *X, const CBLAS_INT strideX, double *Y, const CBLAS_INT strideY, const double *param ) { drotm( &N, X, &strideX, Y, &strideY, param ); } + +/** +* Applies a modified Givens plane rotation using alternative indexing semantics. +* +* @param N number of indexed elements +* @param X first input array +* @param strideX X stride length +* @param offsetX starting index for X +* @param Y second input array +* @param strideY Y stride length +* @param offsetY starting index for Y +* @param param parameters for the modified Givens transformation +*/ +void API_SUFFIX(c_drotm_ndarray)( const CBLAS_INT N, double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, double *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY, const double *param ) { + X += stdlib_strided_min_view_buffer_index( N, strideX, offsetX ); // adjust array pointer + Y += stdlib_strided_min_view_buffer_index( N, strideY, offsetY ); // adjust array pointer + drotm( &N, X, &strideX, Y, &strideY, param ); +} diff --git a/lib/node_modules/@stdlib/blas/base/drotm/src/drotm_ndarray.c b/lib/node_modules/@stdlib/blas/base/drotm/src/drotm_ndarray.c new file mode 100644 index 00000000000..5bcd16dccbc --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drotm/src/drotm_ndarray.c @@ -0,0 +1,129 @@ +/** +* @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. +*/ + +#include "stdlib/blas/base/drotm.h" +#include "stdlib/blas/base/shared.h" + +/** +* Applies a plane rotation. +* +* @param N number of indexed elements +* @param X first input array +* @param strideX X stride length +* @param offsetX starting index for X +* @param Y second input array +* @param strideY Y stride length +* @param offsetY starting index for Y +* @param param parameters for the modified Givens transformation +*/ +void API_SUFFIX(c_drotm_ndarray)( const CBLAS_INT N, double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, double *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY, const double *param ) { + CBLAS_INT ix; + CBLAS_INT iy; + double dflag; + double dh11; + double dh12; + double dh21; + double dh22; + CBLAS_INT i; + double w; + double z; + + dflag = param[ 0 ]; + if ( N <= 0 || dflag == -2.0 ) { + return; + } + ix = offsetX; + iy = offsetY; + if ( strideX == strideY && strideX > 0 ) { + if ( dflag < 0.0 ) { + dh11 = param[ 1 ]; + dh12 = param[ 3 ]; + dh21 = param[ 2 ]; + dh22 = param[ 4 ]; + for ( i = 0; i < N; i++ ) { + w = X[ ix ]; + z = Y[ ix ]; + X[ ix ] = ( w * dh11 ) + ( z * dh12 ); + Y[ ix ] = ( w * dh21 ) + ( z * dh22 ); + ix += strideX; + } + return; + } + if ( dflag == 0.0 ) { + dh12 = param[ 3 ]; + dh21 = param[ 2 ]; + for ( i = 0; i < N; i++ ) { + w = X[ ix ]; + z = Y[ ix ]; + X[ ix ] = w + ( z * dh12 ); + Y[ ix ] = ( w * dh21 ) + z; + ix += strideX; + } + return; + } + dh11 = param[ 1 ]; + dh22 = param[ 4 ]; + for ( i = 0; i < N; i++ ) { + w = X[ ix ]; + z = Y[ ix ]; + X[ ix ] = ( w * dh11 ) + z; + Y[ ix ] = -w + ( z * dh22 ); + ix += strideX; + } + return; + } + if ( dflag < 0.0 ) { + dh11 = param[ 1 ]; + dh12 = param[ 3 ]; + dh21 = param[ 2 ]; + dh22 = param[ 4 ]; + for ( i = 0; i < N; i++ ) { + w = X[ ix ]; + z = Y[ iy ]; + X[ ix ] = ( w * dh11 ) + ( z * dh12 ); + Y[ iy ] = ( w * dh21 ) + ( z * dh22 ); + ix += strideX; + iy += strideY; + } + return; + } + if ( dflag == 0.0 ) { + dh12 = param[ 3 ]; + dh21 = param[ 2 ]; + for ( i = 0; i < N; i++ ) { + w = X[ ix ]; + z = Y[ iy ]; + X[ ix ] = w + ( z * dh12 ); + Y[ iy ] = ( w * dh21 ) + z; + ix += strideX; + iy += strideY; + } + return; + } + dh11 = param[ 1 ]; + dh22 = param[ 4 ]; + for ( i = 0; i < N; i++ ) { + w = X[ ix ]; + z = Y[ iy ]; + X[ ix ] = ( w * dh11 ) + z; + Y[ iy ] = -w + ( z * dh22 ); + ix += strideX; + iy += strideY; + } + return; +} diff --git a/lib/node_modules/@stdlib/blas/base/dscal/README.md b/lib/node_modules/@stdlib/blas/base/dscal/README.md index 81be24e7f42..0716abd284b 100644 --- a/lib/node_modules/@stdlib/blas/base/dscal/README.md +++ b/lib/node_modules/@stdlib/blas/base/dscal/README.md @@ -77,7 +77,7 @@ dscal( 3, 5.0, x1, 2 ); // x0 => [ 1.0, -10.0, 3.0, -20.0, 5.0, -30.0 ] ``` -If either `N` or `stride` is less than or equal to `0`, the function returns `x` unchanged. +If `N` is less than or equal to `0`, the function returns `x` unchanged. #### dscal.ndarray( N, alpha, x, stride, offset ) @@ -193,6 +193,28 @@ The function accepts the following arguments: void c_dscal( const CBLAS_INT N, const double alpha, double *X, const CBLAS_INT stride ); ``` +#### c_dscal_ndarray( N, alpha, \*X, stride, offset ) + +Multiplies each element of a double-precision floating-point vector by a constant using alternative indexing semantics. + +```c +double x[] = { 1.0, 2.0, 3.0, 4.0 }; + +c_dscal_ndarray( 4, 5.0, x, 1, 0 ); +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **alpha**: `[in] double` scalar constant. +- **X**: `[inout] double*` input array. +- **stride**: `[in] CBLAS_INT` index increment for `X`. +- **offset**: `[in] CBLAS_INT` starting index for `X`. + +```c +void c_dscal_ndarray( const CBLAS_INT N, const double alpha, double *X, const CBLAS_INT stride, const CBLAS_INT offset ); +``` + @@ -223,10 +245,18 @@ int main( void ) { const int N = 8; // Specify a stride: - const int strideX = 1; + const int stride = 1; + + // Scale the vector: + c_dscal( N, 5.0, x, stride ); + + // Print the result: + for ( int i = 0; i < 8; i++ ) { + printf( "x[ %i ] = %lf\n", i, x[ i ] ); + } // Scale the vector: - c_dscal( N, 5.0, x, strideX ); + c_dscal_ndarray( N, 5.0, x, -stride, N-1 ); // Print the result: for ( int i = 0; i < 8; i++ ) { diff --git a/lib/node_modules/@stdlib/blas/base/dscal/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/blas/base/dscal/benchmark/c/benchmark.length.c index e4736730136..53453be2991 100644 --- a/lib/node_modules/@stdlib/blas/base/dscal/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/blas/base/dscal/benchmark/c/benchmark.length.c @@ -94,7 +94,7 @@ static double rand_double( void ) { * @param len array length * @return elapsed time in seconds */ -static double benchmark( int iterations, int len ) { +static double benchmark1( int iterations, int len ) { double elapsed; double x[ len ]; double t; @@ -118,6 +118,37 @@ static double benchmark( int iterations, int len ) { return elapsed; } +/** +* Runs a benchmark. +* +* @param iterations number of iterations +* @param len array length +* @return elapsed time in seconds +*/ +static double benchmark2( int iterations, int len ) { + double elapsed; + double x[ len ]; + double t; + int i; + + for ( i = 0; i < len; i++ ) { + x[ i ] = ( rand_double()*200.0 ) - 100.0; + } + t = tic(); + for ( i = 0; i < iterations; i++ ) { + c_dscal_ndarray( len, 5.0, x, 1, 0 ); + if ( x[ 0 ] != x[ 0 ] ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( x[ 0 ] != x[ 0 ] ) { + printf( "should not return NaN\n" ); + } + return elapsed; +} + /** * Main execution sequence. */ @@ -140,7 +171,14 @@ int main( void ) { for ( j = 0; j < REPEATS; j++ ) { count += 1; printf( "# c::%s:len=%d\n", NAME, len ); - elapsed = benchmark( iter, len ); + elapsed = benchmark1( iter, len ); + print_results( iter, elapsed ); + printf( "ok %d benchmark finished\n", count ); + } + for ( j = 0; j < REPEATS; j++ ) { + count += 1; + printf( "# c::%s:ndarray:len=%d\n", NAME, len ); + elapsed = benchmark2( iter, len ); print_results( iter, elapsed ); printf( "ok %d benchmark finished\n", count ); } diff --git a/lib/node_modules/@stdlib/blas/base/dscal/docs/repl.txt b/lib/node_modules/@stdlib/blas/base/dscal/docs/repl.txt index b2ff25d608a..611b788f461 100644 --- a/lib/node_modules/@stdlib/blas/base/dscal/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/base/dscal/docs/repl.txt @@ -9,7 +9,7 @@ Indexing is relative to the first index. To introduce an offset, use typed array views. - If `N <= 0` or `stride <= 0`, the function returns `x` unchanged. + If `N <= 0` the function returns `x` unchanged. Parameters ---------- diff --git a/lib/node_modules/@stdlib/blas/base/dscal/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/base/dscal/docs/types/index.d.ts index 443f3a3bfc0..487ce6f0eb3 100644 --- a/lib/node_modules/@stdlib/blas/base/dscal/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/base/dscal/docs/types/index.d.ts @@ -28,7 +28,7 @@ interface Routine { * @param N - number of indexed elements * @param alpha - constant * @param x - input array - * @param stride - stride length + * @param stride - index increment * @returns input array * * @example @@ -47,7 +47,7 @@ interface Routine { * @param N - number of indexed elements * @param alpha - constant * @param x - input array - * @param stride - stride length + * @param stride - index increment * @param offset - starting index * @returns input array * @@ -68,7 +68,7 @@ interface Routine { * @param N - number of indexed elements * @param alpha - constant * @param x - input array -* @param stride - stride length +* @param stride - index increment * @returns input array * * @example diff --git a/lib/node_modules/@stdlib/blas/base/dscal/examples/c/example.c b/lib/node_modules/@stdlib/blas/base/dscal/examples/c/example.c index 432487bbf0c..283ca4d9345 100644 --- a/lib/node_modules/@stdlib/blas/base/dscal/examples/c/example.c +++ b/lib/node_modules/@stdlib/blas/base/dscal/examples/c/example.c @@ -36,4 +36,12 @@ int main( void ) { for ( int i = 0; i < 8; i++ ) { printf( "x[ %i ] = %lf\n", i, x[ i ] ); } + + // Scale the vector: + c_dscal_ndarray( N, 5.0, x, -strideX, N-1 ); + + // Print the result: + for ( int i = 0; i < 8; i++ ) { + printf( "x[ %i ] = %lf\n", i, x[ i ] ); + } } diff --git a/lib/node_modules/@stdlib/blas/base/dscal/include/stdlib/blas/base/dscal.h b/lib/node_modules/@stdlib/blas/base/dscal/include/stdlib/blas/base/dscal.h index e3150a8accf..55e5b48dbf9 100644 --- a/lib/node_modules/@stdlib/blas/base/dscal/include/stdlib/blas/base/dscal.h +++ b/lib/node_modules/@stdlib/blas/base/dscal/include/stdlib/blas/base/dscal.h @@ -36,6 +36,11 @@ extern "C" { */ void API_SUFFIX(c_dscal)( const CBLAS_INT N, const double alpha, double *X, const CBLAS_INT stride ); +/** +* Multiplies each element of a double-precision floating-point vector by a constant using alternative indexing semantics. +*/ +void API_SUFFIX(c_dscal_ndarray)( const CBLAS_INT N, const double alpha, double *X, const CBLAS_INT stride, const CBLAS_INT offset ); + #ifdef __cplusplus } #endif diff --git a/lib/node_modules/@stdlib/blas/base/dscal/lib/dscal.js b/lib/node_modules/@stdlib/blas/base/dscal/lib/dscal.js index b51f598fcea..21332869745 100644 --- a/lib/node_modules/@stdlib/blas/base/dscal/lib/dscal.js +++ b/lib/node_modules/@stdlib/blas/base/dscal/lib/dscal.js @@ -18,9 +18,10 @@ 'use strict'; -// VARIABLES // +// MODULES // -var M = 5; +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require( './ndarray.js' ); // MAIN // @@ -31,7 +32,7 @@ var M = 5; * @param {PositiveInteger} N - number of indexed elements * @param {number} alpha - scalar * @param {Float64Array} x - input array -* @param {PositiveInteger} stride - index increment +* @param {integer} stride - index increment * @returns {Float64Array} input array * * @example @@ -43,39 +44,8 @@ var M = 5; * // x => [ -10.0, 5.0, 15.0, -25.0, 20.0, 0.0, -5.0, -15.0 ] */ function dscal( N, alpha, x, stride ) { - var i; - var m; - - if ( N <= 0 || stride <= 0 || alpha === 1.0 ) { - return x; - } - // Use loop unrolling if the stride is equal to `1`... - if ( stride === 1 ) { - m = N % M; - - // If we have a remainder, run a clean-up loop... - if ( m > 0 ) { - for ( i = 0; i < m; i++ ) { - x[ i ] *= alpha; - } - } - if ( N < M ) { - return x; - } - for ( i = m; i < N; i += M ) { - x[ i ] *= alpha; - x[ i+1 ] *= alpha; - x[ i+2 ] *= alpha; - x[ i+3 ] *= alpha; - x[ i+4 ] *= alpha; - } - return x; - } - N *= stride; - for ( i = 0; i < N; i += stride ) { - x[ i ] *= alpha; - } - return x; + var ox = stride2offset( N, stride ); + return ndarray( N, alpha, x, stride, ox ); } diff --git a/lib/node_modules/@stdlib/blas/base/dscal/lib/dscal.native.js b/lib/node_modules/@stdlib/blas/base/dscal/lib/dscal.native.js index 742c1ad8b11..d17d329ad3e 100644 --- a/lib/node_modules/@stdlib/blas/base/dscal/lib/dscal.native.js +++ b/lib/node_modules/@stdlib/blas/base/dscal/lib/dscal.native.js @@ -31,7 +31,7 @@ var addon = require( './../src/addon.node' ); * @param {PositiveInteger} N - number of indexed elements * @param {number} alpha - scalar * @param {Float64Array} x - input array -* @param {PositiveInteger} stride - index increment +* @param {integer} stride - index increment * @returns {Float64Array} input array * * @example diff --git a/lib/node_modules/@stdlib/blas/base/dscal/lib/ndarray.native.js b/lib/node_modules/@stdlib/blas/base/dscal/lib/ndarray.native.js index 149e4c9713e..88a69f64c82 100644 --- a/lib/node_modules/@stdlib/blas/base/dscal/lib/ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/base/dscal/lib/ndarray.native.js @@ -20,9 +20,7 @@ // MODULES // -var minViewBufferIndex = require( '@stdlib/strided/base/min-view-buffer-index' ); -var offsetView = require( '@stdlib/strided/base/offset-view' ); -var addon = require( './dscal.native.js' ); +var addon = require( './../src/addon.node' ); // MAIN // @@ -46,13 +44,7 @@ var addon = require( './dscal.native.js' ); * // x => [ 1.0, -2.0, 3.0, -20.0, 25.0, -30.0 ] */ function dscal( N, alpha, x, stride, offset ) { - var view; - offset = minViewBufferIndex( N, stride, offset ); - if ( stride < 0 ) { - stride *= -1; - } - view = offsetView( x, offset ); - addon( N, alpha, view, stride ); + addon.ndarray( N, alpha, x, stride, offset ); return x; } diff --git a/lib/node_modules/@stdlib/blas/base/dscal/manifest.json b/lib/node_modules/@stdlib/blas/base/dscal/manifest.json index c6c1578c53e..7adcba295f5 100644 --- a/lib/node_modules/@stdlib/blas/base/dscal/manifest.json +++ b/lib/node_modules/@stdlib/blas/base/dscal/manifest.json @@ -44,10 +44,11 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/napi/export", "@stdlib/napi/argv", - "@stdlib/napi/argv-double", "@stdlib/napi/argv-int64", + "@stdlib/napi/argv-double", "@stdlib/napi/argv-strided-float64array" ] }, @@ -57,7 +58,8 @@ "blas": "", "wasm": false, "src": [ - "./src/dscal.c" + "./src/dscal.c", + "./src/dscal_ndarray.c" ], "include": [ "./include" @@ -65,7 +67,8 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] }, { @@ -74,7 +77,8 @@ "blas": "", "wasm": false, "src": [ - "./src/dscal.c" + "./src/dscal.c", + "./src/dscal_ndarray.c" ], "include": [ "./include" @@ -82,7 +86,8 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] }, @@ -104,10 +109,11 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/napi/export", "@stdlib/napi/argv", - "@stdlib/napi/argv-double", "@stdlib/napi/argv-int64", + "@stdlib/napi/argv-double", "@stdlib/napi/argv-strided-float64array" ] }, @@ -128,7 +134,8 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index" ] }, { @@ -148,7 +155,8 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index" ] }, @@ -168,10 +176,11 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/napi/export", "@stdlib/napi/argv", - "@stdlib/napi/argv-double", "@stdlib/napi/argv-int64", + "@stdlib/napi/argv-double", "@stdlib/napi/argv-strided-float64array" ] }, @@ -181,7 +190,8 @@ "blas": "", "wasm": false, "src": [ - "./src/dscal.c" + "./src/dscal.c", + "./src/dscal_ndarray.c" ], "include": [ "./include" @@ -189,7 +199,8 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] }, { @@ -198,7 +209,8 @@ "blas": "", "wasm": false, "src": [ - "./src/dscal.c" + "./src/dscal.c", + "./src/dscal_ndarray.c" ], "include": [ "./include" @@ -206,7 +218,8 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] }, @@ -227,10 +240,11 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/napi/export", "@stdlib/napi/argv", - "@stdlib/napi/argv-double", "@stdlib/napi/argv-int64", + "@stdlib/napi/argv-double", "@stdlib/napi/argv-strided-float64array" ] }, @@ -250,7 +264,8 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index" ] }, { @@ -269,7 +284,8 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index" ] }, @@ -291,10 +307,11 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/napi/export", "@stdlib/napi/argv", - "@stdlib/napi/argv-double", "@stdlib/napi/argv-int64", + "@stdlib/napi/argv-double", "@stdlib/napi/argv-strided-float64array" ] }, @@ -315,7 +332,8 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index" ] }, { @@ -335,7 +353,8 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index" ] }, @@ -345,7 +364,8 @@ "blas": "", "wasm": false, "src": [ - "./src/dscal.c" + "./src/dscal.c", + "./src/dscal_ndarray.c" ], "include": [ "./include" @@ -354,10 +374,11 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset", "@stdlib/napi/export", "@stdlib/napi/argv", - "@stdlib/napi/argv-double", "@stdlib/napi/argv-int64", + "@stdlib/napi/argv-double", "@stdlib/napi/argv-strided-float64array" ] }, @@ -367,7 +388,8 @@ "blas": "", "wasm": false, "src": [ - "./src/dscal.c" + "./src/dscal.c", + "./src/dscal_ndarray.c" ], "include": [ "./include" @@ -375,7 +397,8 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] }, { @@ -384,7 +407,8 @@ "blas": "", "wasm": false, "src": [ - "./src/dscal.c" + "./src/dscal.c", + "./src/dscal_ndarray.c" ], "include": [ "./include" @@ -392,7 +416,8 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] }, @@ -402,7 +427,8 @@ "blas": "", "wasm": true, "src": [ - "./src/dscal.c" + "./src/dscal.c", + "./src/dscal_ndarray.c" ], "include": [ "./include" @@ -410,7 +436,8 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] } ] diff --git a/lib/node_modules/@stdlib/blas/base/dscal/src/addon.c b/lib/node_modules/@stdlib/blas/base/dscal/src/addon.c index 13a42f4187a..e6f55f055fe 100644 --- a/lib/node_modules/@stdlib/blas/base/dscal/src/addon.c +++ b/lib/node_modules/@stdlib/blas/base/dscal/src/addon.c @@ -36,10 +36,28 @@ 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_DOUBLE( env, alpha, argv, 1 ); - STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 ); - STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, strideX, argv, 2 ); - API_SUFFIX(c_dscal)( N, alpha, X, strideX ); + STDLIB_NAPI_ARGV_INT64( env, stride, argv, 3 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, stride, argv, 2 ); + API_SUFFIX(c_dscal)( N, alpha, X, stride ); return NULL; } -STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) +/** +* Receives JavaScript callback invocation data. +* +* @param env environment under which the function is invoked +* @param info callback data +* @return Node-API value +*/ +static napi_value addon_method( napi_env env, napi_callback_info info ) { + STDLIB_NAPI_ARGV( env, info, argv, argc, 5 ); + STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); + STDLIB_NAPI_ARGV_DOUBLE( env, alpha, argv, 1 ); + STDLIB_NAPI_ARGV_INT64( env, stride, argv, 3 ); + STDLIB_NAPI_ARGV_INT64( env, offset, argv, 4 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, stride, argv, 2 ); + API_SUFFIX(c_dscal_ndarray)( N, alpha, X, stride, offset ); + return NULL; +} + +STDLIB_NAPI_MODULE_EXPORT_FCN_WITH_METHOD( addon, "ndarray", addon_method ) diff --git a/lib/node_modules/@stdlib/blas/base/dscal/src/dscal.c b/lib/node_modules/@stdlib/blas/base/dscal/src/dscal.c index 712b4d62ab6..f98cdab0fef 100644 --- a/lib/node_modules/@stdlib/blas/base/dscal/src/dscal.c +++ b/lib/node_modules/@stdlib/blas/base/dscal/src/dscal.c @@ -18,6 +18,7 @@ #include "stdlib/blas/base/dscal.h" #include "stdlib/blas/base/shared.h" +#include "stdlib/strided/base/stride2offset.h" /** * Multiplies a double-precision floating-point vector `X` by a constant. @@ -28,36 +29,6 @@ * @param stride index increment */ void API_SUFFIX(c_dscal)( const CBLAS_INT N, const double alpha, double *X, const CBLAS_INT stride ) { - CBLAS_INT m; - CBLAS_INT i; - - if ( N <= 0 || stride <= 0 || alpha == 1.0 ) { - return; - } - // Use loop unrolling if the stride is equal to `1`... - if ( stride == 1 ) { - m = N % 5; - - // If we have a remainder, run a clean-up loop... - if ( m > 0 ) { - for ( i = 0; i < m; i++ ) { - X[ i ] *= alpha; - } - } - if ( N < 5 ) { - return; - } - for ( i = m; i < N; i += 5 ) { - X[ i ] *= alpha; - X[ i+1 ] *= alpha; - X[ i+2 ] *= alpha; - X[ i+3 ] *= alpha; - X[ i+4 ] *= alpha; - } - return; - } - for ( i = 0; i < N*stride; i += stride ) { - X[ i ] *= alpha; - } - return; + CBLAS_INT ox = stdlib_strided_stride2offset( N, stride ); + API_SUFFIX(c_dscal_ndarray)( N, alpha, X, stride, ox ); } diff --git a/lib/node_modules/@stdlib/blas/base/dscal/src/dscal_cblas.c b/lib/node_modules/@stdlib/blas/base/dscal/src/dscal_cblas.c index 6613aad2dd7..2de64f05b48 100644 --- a/lib/node_modules/@stdlib/blas/base/dscal/src/dscal_cblas.c +++ b/lib/node_modules/@stdlib/blas/base/dscal/src/dscal_cblas.c @@ -19,6 +19,7 @@ #include "stdlib/blas/base/dscal.h" #include "stdlib/blas/base/dscal_cblas.h" #include "stdlib/blas/base/shared.h" +#include "stdlib/strided/base/min_view_buffer_index.h" /** * Multiplies a double-precision floating-point vector `X` by a constant. @@ -29,5 +30,27 @@ * @param stride index increment */ void API_SUFFIX(c_dscal)( const CBLAS_INT N, const double alpha, double *X, const CBLAS_INT stride ) { - API_SUFFIX(cblas_dscal)( N, alpha, X, stride ); + CBLAS_INT sx = stride; + if ( sx < 0 ) { + sx = -sx; + } + API_SUFFIX(cblas_dscal)( N, alpha, X, sx ); +} + +/** +* Multiplies a double-precision floating-point vector `X` by a constant using alternative indexing semantics. +* +* @param N number of indexed elements +* @param alpha scalar +* @param X input array +* @param stride index increment +* @param offset starting index +*/ +void API_SUFFIX(c_dscal_ndarray)( const CBLAS_INT N, const double alpha, double *X, const CBLAS_INT stride, const CBLAS_INT offset ) { + CBLAS_INT sx = stride; + X += stdlib_strided_min_view_buffer_index( N, stride, offset ); // adjust array pointer + if ( sx < 0 ) { + sx = -sx; + } + API_SUFFIX(cblas_dscal)( N, alpha, X, sx ); } diff --git a/lib/node_modules/@stdlib/blas/base/dscal/src/dscal_f.c b/lib/node_modules/@stdlib/blas/base/dscal/src/dscal_f.c index 254e5083dbd..57f359952d8 100644 --- a/lib/node_modules/@stdlib/blas/base/dscal/src/dscal_f.c +++ b/lib/node_modules/@stdlib/blas/base/dscal/src/dscal_f.c @@ -19,6 +19,7 @@ #include "stdlib/blas/base/dscal.h" #include "stdlib/blas/base/dscal_fortran.h" #include "stdlib/blas/base/shared.h" +#include "stdlib/strided/base/min_view_buffer_index.h" /** * Multiplies a double-precision floating-point vector `X` by a constant. @@ -29,5 +30,27 @@ * @param stride index increment */ void API_SUFFIX(c_dscal)( const CBLAS_INT N, const double alpha, double *X, const CBLAS_INT stride ) { - dscal( &N, &alpha, X, &stride ); + CBLAS_INT sx = stride; + if ( sx < 0 ) { + sx = -sx; + } + dscal( &N, &alpha, X, &sx ); +} + +/** +* Multiplies a double-precision floating-point vector `X` by a constant using alternative indexing semantics. +* +* @param N number of indexed elements +* @param alpha scalar +* @param X input array +* @param stride index increment +* @param offset starting index +*/ +void API_SUFFIX(c_dscal_ndarray)( const CBLAS_INT N, const double alpha, double *X, const CBLAS_INT stride, const CBLAS_INT offset ) { + CBLAS_INT sx = stride; + if ( sx < 0 ) { + sx = -sx; + } + X += stdlib_strided_min_view_buffer_index( N, stride, offset ); // adjust array pointer + dscal( &N, &alpha, X, &sx ); } diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapx/src/dapx.c b/lib/node_modules/@stdlib/blas/base/dscal/src/dscal_ndarray.c similarity index 59% rename from lib/node_modules/@stdlib/blas/ext/base/dapx/src/dapx.c rename to lib/node_modules/@stdlib/blas/base/dscal/src/dscal_ndarray.c index 31e2ca26d10..5d63e2dec12 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapx/src/dapx.c +++ b/lib/node_modules/@stdlib/blas/base/dscal/src/dscal_ndarray.c @@ -16,54 +16,56 @@ * limitations under the License. */ -#include "stdlib/blas/ext/base/dapx.h" -#include +#include "stdlib/blas/base/dscal.h" +#include "stdlib/blas/base/shared.h" + +static const CBLAS_INT M = 5; /** -* Adds a constant to each element in a double-precision floating-point strided array. +* Multiplies a double-precision floating-point vector `X` by a constant using alternative indexing semantics. * * @param N number of indexed elements * @param alpha scalar * @param X input array * @param stride index increment +* @param offset starting index */ -void c_dapx( const int64_t N, const double alpha, double *X, const int64_t stride ) { - int64_t ix; - int64_t m; - int64_t i; +void API_SUFFIX(c_dscal_ndarray)( const CBLAS_INT N, const double alpha, double *X, const CBLAS_INT stride, const CBLAS_INT offset ) { + CBLAS_INT ix; + CBLAS_INT i; + CBLAS_INT m; - if ( N <= 0 || alpha == 0.0 ) { + if ( N <= 0 || alpha == 1.0 ) { return; } + ix = offset; + // Use loop unrolling if the stride is equal to `1`... if ( stride == 1 ) { - m = N % 5; + m = N % M; // If we have a remainder, run a clean-up loop... if ( m > 0 ) { for ( i = 0; i < m; i++ ) { - X[ i ] += alpha; + X[ ix ] *= alpha; + ix += stride; } } - if ( N < 5 ) { + if ( N < M ) { return; } - for ( i = m; i < N; i += 5 ) { - X[ i ] += alpha; - X[ i+1 ] += alpha; - X[ i+2 ] += alpha; - X[ i+3 ] += alpha; - X[ i+4 ] += alpha; + for ( i = m; i < N; i += M ) { + X[ ix ] *= alpha; + X[ ix+1 ] *= alpha; + X[ ix+2 ] *= alpha; + X[ ix+3 ] *= alpha; + X[ ix+4 ] *= alpha; + ix += M; } return; } - if ( stride < 0 ) { - ix = (1-N) * stride; - } else { - ix = 0; - } for ( i = 0; i < N; i++ ) { - X[ ix ] += alpha; + X[ ix ] *= alpha; ix += stride; } return; diff --git a/lib/node_modules/@stdlib/blas/base/dscal/test/test.dscal.js b/lib/node_modules/@stdlib/blas/base/dscal/test/test.dscal.js index e4c327a0cfc..3e07fd0f412 100644 --- a/lib/node_modules/@stdlib/blas/base/dscal/test/test.dscal.js +++ b/lib/node_modules/@stdlib/blas/base/dscal/test/test.dscal.js @@ -139,19 +139,27 @@ tape( 'the function supports specifying a stride', function test( t ) { t.end(); }); -tape( 'if provided a `stride` less than or equal to `0`, the function returns `x` unchanged', function test( t ) { +tape( 'the function supports specifying a negative stride', function test( t ) { var expected; var x; - x = new Float64Array( [ 3.0, -4.0, 1.0 ] ); - expected = new Float64Array( [ 3.0, -4.0, 1.0 ] ); - - dscal( x.length, 5.0, x, 0 ); - t.deepEqual( x, expected, 'returns expected value' ); + x = new Float64Array([ + 2.0, // 2 + -3.0, + -5.0, // 1 + 7.0, + 6.0 // 0 + ]); + expected = new Float64Array([ + 10.0, // 2 + -3.0, + -25.0, // 1 + 7.0, + 30.0 // 0 + ]); - dscal( x.length, 5.0, x, -1 ); + dscal( 3, 5.0, x, -2 ); t.deepEqual( x, expected, 'returns expected value' ); - t.end(); }); diff --git a/lib/node_modules/@stdlib/blas/base/dscal/test/test.dscal.native.js b/lib/node_modules/@stdlib/blas/base/dscal/test/test.dscal.native.js index f7263194166..53fed2022f2 100644 --- a/lib/node_modules/@stdlib/blas/base/dscal/test/test.dscal.native.js +++ b/lib/node_modules/@stdlib/blas/base/dscal/test/test.dscal.native.js @@ -148,19 +148,27 @@ tape( 'the function supports specifying a stride', opts, function test( t ) { t.end(); }); -tape( 'if provided a `stride` less than or equal to `0`, the function returns `x` unchanged', opts, function test( t ) { +tape( 'the function supports specifying a negative stride', opts, function test( t ) { var expected; var x; - x = new Float64Array( [ 3.0, -4.0, 1.0 ] ); - expected = new Float64Array( [ 3.0, -4.0, 1.0 ] ); - - dscal( x.length, 5.0, x, 0 ); - t.deepEqual( x, expected, 'returns expected value' ); + x = new Float64Array([ + 2.0, // 2 + -3.0, + -5.0, // 1 + 7.0, + 6.0 // 0 + ]); + expected = new Float64Array([ + 10.0, // 2 + -3.0, + -25.0, // 1 + 7.0, + 30.0 // 0 + ]); - dscal( x.length, 5.0, x, -1 ); + dscal( 3, 5.0, x, -2 ); t.deepEqual( x, expected, 'returns expected value' ); - t.end(); }); diff --git a/lib/node_modules/@stdlib/blas/base/dscal/test/test.ndarray.native.js b/lib/node_modules/@stdlib/blas/base/dscal/test/test.ndarray.native.js index e6fadd05ade..24963cf346a 100644 --- a/lib/node_modules/@stdlib/blas/base/dscal/test/test.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/base/dscal/test/test.ndarray.native.js @@ -167,7 +167,7 @@ tape( 'the function supports specifying a negative stride', opts, function test( 30.0 // 0 ]); - dscal( 3, 5.0, x, -2, x.length-1 ); + dscal( 3, 5.0, x, -2, 4 ); t.deepEqual( x, expected, 'returns expected value' ); t.end(); }); diff --git a/lib/node_modules/@stdlib/blas/base/dsdot/README.md b/lib/node_modules/@stdlib/blas/base/dsdot/README.md index 0ff4c3e0131..cc11f49ee0e 100644 --- a/lib/node_modules/@stdlib/blas/base/dsdot/README.md +++ b/lib/node_modules/@stdlib/blas/base/dsdot/README.md @@ -227,6 +227,32 @@ The function accepts the following arguments: double c_dsdot( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, const float *Y, const CBLAS_INT strideY ); ``` +#### c_dsdot_ndarray( N, \*X, strideX, offsetX, \*Y, strideY, offsetY ) + +Computes the dot product of two single-precision floating-point vectors with extended accumulation and result and using alternative indexing semantics. + +```c +const float x[] = { 4.0f, 2.0f, -3.0f, 5.0f, -1.0f }; +const float y[] = { 2.0f, 6.0f, -1.0f, -4.0f, 8.0f }; + +double v = c_dsdot_ndarray( 5, x, 1, 0, y, 1, 0 ); +// returns -5.0 +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **X**: `[in] float*` first input array. +- **strideX**: `[in] CBLAS_INT` index increment for `X`. +- **offsetX**: `[in] CBLAS_INT` starting index for `X`. +- **Y**: `[in] float*` second input array. +- **strideY**: `[in] CBLAS_INT` index increment for `Y`. +- **offsetY**: `[in] CBLAS_INT` starting index for `Y`. + +```c +double c_dsdot_ndarray( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, const float *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY ); +``` + @@ -266,6 +292,12 @@ int main( void ) { // Print the result: printf( "dot product: %lf\n", d ); + + // Compute the dot product: + d = c_dsdot_ndarray( N, x, strideX, 0, y, strideY, N-1 ); + + // Print the result: + printf( "dot product: %lf\n", d ); } ``` diff --git a/lib/node_modules/@stdlib/blas/base/dsdot/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/blas/base/dsdot/benchmark/c/benchmark.length.c index 0b4914f6fac..bbe74f7e00f 100644 --- a/lib/node_modules/@stdlib/blas/base/dsdot/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/blas/base/dsdot/benchmark/c/benchmark.length.c @@ -94,7 +94,7 @@ static float rand_float( void ) { * @param len array length * @return elapsed time in seconds */ -static double benchmark( int iterations, int len ) { +static double benchmark1( int iterations, int len ) { double elapsed; float x[ len ]; float y[ len ]; @@ -122,6 +122,41 @@ static double benchmark( int iterations, int len ) { return elapsed; } +/** +* Runs a benchmark. +* +* @param iterations number of iterations +* @param len array length +* @return elapsed time in seconds +*/ +static double benchmark2( int iterations, int len ) { + double elapsed; + float x[ len ]; + float y[ len ]; + double z; + double t; + int i; + + for ( i = 0; i < len; i++ ) { + x[ i ] = ( rand_float()*20000.0f ) - 10000.0f; + y[ i ] = ( rand_float()*20000.0f ) - 10000.0f; + } + z = 0.0; + t = tic(); + for ( i = 0; i < iterations; i++ ) { + z = c_dsdot_ndarray( len, x, 1, 0, y, 1, 0 ); + if ( z != z ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( z != z ) { + printf( "should not return NaN\n" ); + } + return elapsed; +} + /** * Main execution sequence. */ @@ -144,7 +179,14 @@ int main( void ) { for ( j = 0; j < REPEATS; j++ ) { count += 1; printf( "# c::%s:len=%d\n", NAME, len ); - elapsed = benchmark( iter, len ); + elapsed = benchmark1( iter, len ); + print_results( iter, elapsed ); + printf( "ok %d benchmark finished\n", count ); + } + for ( j = 0; j < REPEATS; j++ ) { + count += 1; + printf( "# c::%s:ndarray:len=%d\n", NAME, len ); + elapsed = benchmark2( iter, len ); print_results( iter, elapsed ); printf( "ok %d benchmark finished\n", count ); } diff --git a/lib/node_modules/@stdlib/blas/base/dsdot/examples/c/example.c b/lib/node_modules/@stdlib/blas/base/dsdot/examples/c/example.c index 7c3054f271f..7164804d9d1 100644 --- a/lib/node_modules/@stdlib/blas/base/dsdot/examples/c/example.c +++ b/lib/node_modules/@stdlib/blas/base/dsdot/examples/c/example.c @@ -36,4 +36,10 @@ int main( void ) { // Print the result: printf( "dot product: %lf\n", d ); + + // Compute the dot product: + d = c_dsdot_ndarray( N, x, strideX, 0, y, strideY, N-1 ); + + // Print the result: + printf( "dot product: %lf\n", d ); } diff --git a/lib/node_modules/@stdlib/blas/base/dsdot/include/stdlib/blas/base/dsdot.h b/lib/node_modules/@stdlib/blas/base/dsdot/include/stdlib/blas/base/dsdot.h index deeead972be..424068fb3b2 100644 --- a/lib/node_modules/@stdlib/blas/base/dsdot/include/stdlib/blas/base/dsdot.h +++ b/lib/node_modules/@stdlib/blas/base/dsdot/include/stdlib/blas/base/dsdot.h @@ -36,6 +36,11 @@ extern "C" { */ double API_SUFFIX(c_dsdot)( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, const float *Y, const CBLAS_INT strideY ); +/** +* Computes the dot product of two single-precision floating-point vectors with extended accumulation and result and using alternative indexing semantics. +*/ +double API_SUFFIX(c_dsdot_ndarray)( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, const float *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY ); + #ifdef __cplusplus } #endif diff --git a/lib/node_modules/@stdlib/blas/base/dsdot/lib/ndarray.native.js b/lib/node_modules/@stdlib/blas/base/dsdot/lib/ndarray.native.js index 9174e07bb5b..0f131ea1ca2 100644 --- a/lib/node_modules/@stdlib/blas/base/dsdot/lib/ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/base/dsdot/lib/ndarray.native.js @@ -20,9 +20,7 @@ // MODULES // -var minViewBufferIndex = require( '@stdlib/strided/base/min-view-buffer-index' ); -var offsetView = require( '@stdlib/strided/base/offset-view' ); -var addon = require( './dsdot.native.js' ); +var addon = require( './../src/addon.node' ); // MAIN // @@ -49,16 +47,7 @@ var addon = require( './dsdot.native.js' ); * // returns -5.0 */ function dsdot( N, x, strideX, offsetX, y, strideY, offsetY ) { - var viewX; - var viewY; - - offsetX = minViewBufferIndex( N, strideX, offsetX ); - offsetY = minViewBufferIndex( N, strideY, offsetY ); - - viewX = offsetView( x, offsetX ); - viewY = offsetView( y, offsetY ); - - return addon( N, viewX, strideX, viewY, strideY ); + return addon.ndarray( N, x, strideX, offsetX, y, strideY, offsetY ); } diff --git a/lib/node_modules/@stdlib/blas/base/dsdot/manifest.json b/lib/node_modules/@stdlib/blas/base/dsdot/manifest.json index 934a31c1b36..1ab42dde326 100644 --- a/lib/node_modules/@stdlib/blas/base/dsdot/manifest.json +++ b/lib/node_modules/@stdlib/blas/base/dsdot/manifest.json @@ -45,6 +45,7 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/napi/export", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", @@ -58,7 +59,8 @@ "blas": "", "wasm": false, "src": [ - "./src/dsdot.c" + "./src/dsdot.c", + "./src/dsdot_ndarray.c" ], "include": [ "./include" @@ -66,7 +68,8 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] }, { @@ -75,7 +78,8 @@ "blas": "", "wasm": false, "src": [ - "./src/dsdot.c" + "./src/dsdot.c", + "./src/dsdot_ndarray.c" ], "include": [ "./include" @@ -83,7 +87,8 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] }, @@ -105,6 +110,7 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/napi/export", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", @@ -129,7 +135,8 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index" ] }, { @@ -149,7 +156,8 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index" ] }, @@ -170,6 +178,7 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/napi/export", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", @@ -183,7 +192,8 @@ "blas": "", "wasm": false, "src": [ - "./src/dsdot.c" + "./src/dsdot.c", + "./src/dsdot_ndarray.c" ], "include": [ "./include" @@ -191,7 +201,8 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] }, { @@ -200,7 +211,8 @@ "blas": "", "wasm": false, "src": [ - "./src/dsdot.c" + "./src/dsdot.c", + "./src/dsdot_ndarray.c" ], "include": [ "./include" @@ -208,7 +220,8 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] }, @@ -229,6 +242,7 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/napi/export", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", @@ -252,7 +266,8 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index" ] }, { @@ -271,7 +286,8 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index" ] }, @@ -293,6 +309,7 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/napi/export", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", @@ -317,7 +334,8 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index" ] }, { @@ -337,7 +355,8 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index" ] }, @@ -347,7 +366,8 @@ "blas": "", "wasm": false, "src": [ - "./src/dsdot.c" + "./src/dsdot.c", + "./src/dsdot_ndarray.c" ], "include": [ "./include" @@ -356,6 +376,7 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset", "@stdlib/napi/export", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", @@ -369,7 +390,8 @@ "blas": "", "wasm": false, "src": [ - "./src/dsdot.c" + "./src/dsdot.c", + "./src/dsdot_ndarray.c" ], "include": [ "./include" @@ -377,7 +399,8 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] }, { @@ -386,7 +409,8 @@ "blas": "", "wasm": false, "src": [ - "./src/dsdot.c" + "./src/dsdot.c", + "./src/dsdot_ndarray.c" ], "include": [ "./include" @@ -394,7 +418,8 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] }, @@ -404,7 +429,8 @@ "blas": "", "wasm": true, "src": [ - "./src/dsdot.c" + "./src/dsdot.c", + "./src/dsdot_ndarray.c" ], "include": [ "./include" @@ -412,7 +438,8 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] } ] diff --git a/lib/node_modules/@stdlib/blas/base/dsdot/src/addon.c b/lib/node_modules/@stdlib/blas/base/dsdot/src/addon.c index 5563de86e7e..fbaa0fe1134 100644 --- a/lib/node_modules/@stdlib/blas/base/dsdot/src/addon.c +++ b/lib/node_modules/@stdlib/blas/base/dsdot/src/addon.c @@ -43,4 +43,24 @@ static napi_value addon( napi_env env, napi_callback_info info ) { return v; } -STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) +/** +* Receives JavaScript callback invocation data. +* +* @param env environment under which the function is invoked +* @param info callback data +* @return Node-API value +*/ +static napi_value addon_method( napi_env env, napi_callback_info info ) { + STDLIB_NAPI_ARGV( env, info, argv, argc, 7 ); + STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 2 ); + STDLIB_NAPI_ARGV_INT64( env, offsetX, argv, 3 ); + STDLIB_NAPI_ARGV_INT64( env, strideY, argv, 5 ); + STDLIB_NAPI_ARGV_INT64( env, offsetY, argv, 6 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 1 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, Y, N, strideY, argv, 4 ); + STDLIB_NAPI_CREATE_DOUBLE( env, API_SUFFIX(c_dsdot_ndarray)( N, X, strideX, offsetX, Y, strideY, offsetY ), v ); + return v; +} + +STDLIB_NAPI_MODULE_EXPORT_FCN_WITH_METHOD( addon, "ndarray", addon_method ) 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 686d97f0080..394a80b4255 100644 --- a/lib/node_modules/@stdlib/blas/base/dsdot/src/dsdot.c +++ b/lib/node_modules/@stdlib/blas/base/dsdot/src/dsdot.c @@ -18,6 +18,7 @@ #include "stdlib/blas/base/dsdot.h" #include "stdlib/blas/base/shared.h" +#include "stdlib/strided/base/stride2offset.h" /** * Computes the dot product of two single-precision floating-point vectors with extended accumulation and result. @@ -30,49 +31,8 @@ * @return the dot product */ double API_SUFFIX(c_dsdot)( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, const float *Y, const CBLAS_INT strideY ) { - double dot; - CBLAS_INT ix; - CBLAS_INT iy; - CBLAS_INT m; - CBLAS_INT i; - - dot = 0.0; - if ( N <= 0 ) { - return dot; - } - // If both strides are equal to `1`, use unrolled loops... - if ( strideX == 1 && strideY == 1 ) { - m = N % 5; - - // If we have a remainder, do a clean-up loop... - if ( m > 0 ) { - for ( i = 0; i < m; i++ ) { - dot += (double)X[ i ] * (double)Y[ i ]; - } - } - if ( N < 5 ) { - return dot; - } - for ( i = m; i < N; i += 5 ) { - dot += ( (double)X[i]*(double)Y[i] ) + ( (double)X[i+1]*(double)Y[i+1]) + ( (double)X[i+2]*(double)Y[i+2] ) + ( (double)X[i+3]*(double)Y[i+3] ) + ( (double)X[i+4]*(double)Y[i+4] ); - } - return dot; - } - if ( strideX < 0 ) { - ix = (1-N) * strideX; - } else { - ix = 0; - } - if ( strideY < 0 ) { - iy = (1-N) * strideY; - } else { - iy = 0; - } - for ( i = 0; i < N; i++ ) { - dot += (double)X[ ix ] * (double)Y[ iy ]; - ix += strideX; - iy += strideY; - } - return dot; + CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX ); + CBLAS_INT oy = stdlib_strided_stride2offset( N, strideY ); + return API_SUFFIX(c_dsdot_ndarray)( N, X, strideX, ox, Y, strideY, oy ); } 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 d31e98bfa6e..5b42e30ee0f 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 @@ -19,6 +19,7 @@ #include "stdlib/blas/base/dsdot.h" #include "stdlib/blas/base/dsdot_cblas.h" #include "stdlib/blas/base/shared.h" +#include "stdlib/strided/base/min_view_buffer_index.h" /** * Computes the dot product of two single-precision floating-point vectors with extended accumulation and result. @@ -28,8 +29,26 @@ * @param strideX X stride length * @param Y second array * @param strideY Y stride length -* @return the dot product +* @return dot product */ double API_SUFFIX(c_dsdot)( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, const float *Y, const CBLAS_INT strideY ) { return API_SUFFIX(cblas_dsdot)( N, X, strideX, Y, strideY ); } + +/** +* Computes the dot product of two single-precision floating-point vectors with extended accumulation and result and using alternative indexing semantics. +* +* @param N number of indexed elements +* @param X first array +* @param strideX X stride length +* @param offsetX starting index for X +* @param Y second array +* @param strideY Y stride length +* @param offsetY starting index for Y +* @return dot product +*/ +double API_SUFFIX(c_dsdot_ndarray)( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, const float *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY ) { + X += stdlib_strided_min_view_buffer_index( N, strideX, offsetX ); // adjust array pointer + Y += stdlib_strided_min_view_buffer_index( N, strideY, offsetY ); // adjust array pointer + return API_SUFFIX(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 4b3955e82fc..d94a3352041 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 @@ -19,6 +19,7 @@ #include "stdlib/blas/base/dsdot.h" #include "stdlib/blas/base/dsdot_fortran.h" #include "stdlib/blas/base/shared.h" +#include "stdlib/strided/base/min_view_buffer_index.h" /** * Computes the dot product of two single-precision floating-point vectors with extended accumulation and result. @@ -28,10 +29,31 @@ * @param strideX X stride length * @param Y second array * @param strideY Y stride length -* @return the dot product +* @return dot product */ double API_SUFFIX(c_dsdot)( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, const float *Y, const CBLAS_INT strideY ) { double dot; dsdotsub( &N, X, &strideX, Y, &strideY, &dot ); return dot; } + +/** +* Computes the dot product of two single-precision floating-point vectors with extended accumulation and result and using alternative indexing semantics. +* +* @param N number of indexed elements +* @param X first array +* @param strideX X stride length +* @param offsetX starting index for X +* @param Y second array +* @param strideY Y stride length +* @param offsetY starting index for Y +* @return dot product +*/ +double API_SUFFIX(c_dsdot_ndarray)( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, const float *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY ) { + double dot; + + X += stdlib_strided_min_view_buffer_index( N, strideX, offsetX ); // adjust array pointer + Y += stdlib_strided_min_view_buffer_index( N, strideY, offsetY ); // adjust array pointer + dsdotsub( &N, X, &strideX, Y, &strideY, &dot ); + return dot; +} diff --git a/lib/node_modules/@stdlib/blas/base/dsdot/src/dsdot_ndarray.c b/lib/node_modules/@stdlib/blas/base/dsdot/src/dsdot_ndarray.c new file mode 100644 index 00000000000..672f3a59035 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dsdot/src/dsdot_ndarray.c @@ -0,0 +1,79 @@ +/** +* @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. +*/ + +#include "stdlib/blas/base/dsdot.h" +#include "stdlib/blas/base/shared.h" + +static const CBLAS_INT M = 5; + +/** +* Computes the dot product of two single-precision floating-point vectors with extended accumulation and result and using alternative indexing semantics. +* +* @param N number of indexed elements +* @param X first array +* @param strideX X stride length +* @param offsetX starting index for X +* @param Y second array +* @param strideY Y stride length +* @param offsetY starting index for Y +* @return dot product +*/ +double API_SUFFIX(c_dsdot_ndarray)( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, const float *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY ) { + double dot; + CBLAS_INT ix; + CBLAS_INT iy; + CBLAS_INT m; + CBLAS_INT i; + + dot = 0.0; + if ( N <= 0 ) { + return dot; + } + ix = offsetX; + iy = offsetY; + + // If both strides are equal to `1`, use unrolled loops... + if ( strideX == 1 && strideY == 1 ) { + m = N % M; + + // If we have a remainder, do a clean-up loop... + if ( m > 0 ) { + for ( i = 0; i < m; i++ ) { + dot += (double)X[ ix ] * (double)Y[ iy ]; + ix += strideX; + iy += strideY; + } + } + if ( N < M ) { + return dot; + } + for ( i = m; i < N; i += M ) { + dot += ( (double)X[ ix ]*(double)Y[ iy ] ) + ( (double)X[ ix+1 ]*(double)Y[ iy+1 ]) + ( (double)X[ ix+2 ]*(double)Y[ iy+2 ] ) + ( (double)X[ ix+3 ]*(double)Y[ iy+3 ] ) + ( (double)X[ ix+4 ]*(double)Y[ iy+4 ] ); + ix += M; + iy += M; + } + return dot; + } + for ( i = 0; i < N; i++ ) { + dot += (double)X[ ix ] * (double)Y[ iy ]; + ix += strideX; + iy += strideY; + } + return dot; +} + diff --git a/lib/node_modules/@stdlib/blas/base/sasum/README.md b/lib/node_modules/@stdlib/blas/base/sasum/README.md index 8a270f4b0de..a79dfb368ce 100644 --- a/lib/node_modules/@stdlib/blas/base/sasum/README.md +++ b/lib/node_modules/@stdlib/blas/base/sasum/README.md @@ -97,7 +97,7 @@ var sum = sasum( 3, x1, 2 ); // returns 12.0 ``` -If either `N` or `stride` is less than or equal to `0`, the function returns `0`. +If either `N` is less than or equal to `0`, the function returns `0`. #### sasum.ndarray( N, x, stride, offset ) @@ -170,6 +170,129 @@ console.log( out ); + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/blas/base/sasum.h" +``` + +#### c_sasum( N, \*X, stride ) + +Computes the sum of [absolute values][@stdlib/math/base/special/abs]. + +```c +const float x[] = { 1.0f, -2.0f, 3.0f, -4.0f, 5.0f, -6.0f, 7.0f, -8.0f }; + +float sum = c_sasum( 8, x, 1 ); +// returns 36.0f +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **X**: `[in] float*` input array. +- **stride**: `[in] CBLAS_INT` index increment for `X`. + +```c +float c_sasum( const CBLAS_INT N, const float *X, const CBLAS_INT stride ); +``` + +#### c_sasum_ndarray( N, \*X, stride, offset ) + +Computes the sum of [absolute values][@stdlib/math/base/special/abs] using alternative indexing semantics. + +```c +const float x[] = { 1.0f, -2.0f, 3.0f, -4.0f, 5.0f, -6.0f, 7.0f, -8.0f }; + +float sum = c_sasum_ndarray( 8, x, -1, 7 ); +// returns 36.0f +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **X**: `[in] float*` input array. +- **stride**: `[in] CBLAS_INT` index increment for `X`. +- **offset**: `[in] CBLAS_INT` starting index for `X`. + +```c +float c_sasum_ndarray( const CBLAS_INT N, const float *X, const CBLAS_INT stride, const CBLAS_INT offset ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/blas/base/sasum.h" +#include + +int main( void ) { + // Create a strided array: + const float x[] = { 1.0f, -2.0f, 3.0f, -4.0f, 5.0f, -6.0f, 7.0f, -8.0f }; + + // Specify the number of elements: + const int N = 8; + + // Specify a stride: + const int stride = 1; + + // Compute the sum of absolute values: + float sum = c_sasum( N, x, stride ); + + // Print the result: + printf( "sum: %f\n", sum ); + + // Compute the sum of absolute values: + sum = c_sasum_ndarray( N, x, -stride, N-1 ); + + // Print the result: + printf( "sum: %f\n", sum ); +} +``` + +
+ + + +
+ + + @@ -267,6 +294,14 @@ int main( void ) { for ( int i = 0; i < 5; i++ ) { printf( "x[ %i ] = %f, y[ %i ] = %f\n", i, x[ i ], i, y[ i ] ); } + + // Apply plane rotation: + c_srotm_ndarray( N, x, -strideX, N-1, y, -strideY, N-1, param ); + + // Print the result: + for ( int i = 0; i < 5; i++ ) { + printf( "x[ %i ] = %f, y[ %i ] = %f\n", i, x[ i ], i, y[ i ] ); + } } ``` diff --git a/lib/node_modules/@stdlib/blas/base/srotm/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/blas/base/srotm/benchmark/c/benchmark.length.c index b8a5597f2a3..fb37d69a76e 100644 --- a/lib/node_modules/@stdlib/blas/base/srotm/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/blas/base/srotm/benchmark/c/benchmark.length.c @@ -94,7 +94,7 @@ static float rand_float( void ) { * @param len array length * @return elapsed time in seconds */ -static double benchmark( int iterations, int len ) { +static double benchmark1( int iterations, int len ) { double elapsed; float x[ len ]; float y[ len ]; @@ -122,6 +122,41 @@ static double benchmark( int iterations, int len ) { return elapsed; } +/** +* Runs a benchmark. +* +* @param iterations number of iterations +* @param len array length +* @return elapsed time in seconds +*/ +static double benchmark2( int iterations, int len ) { + double elapsed; + float x[ len ]; + float y[ len ]; + double t; + int i; + + const float param[5] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }; + for ( i = 0; i < len; i++ ) { + x[ i ] = ( rand_float()*200.0f ) - 100.0f; + y[ i ] = ( rand_float()*200.0f ) - 100.0f; + } + + t = tic(); + for ( i = 0; i < iterations; i++ ) { + c_srotm_ndarray( len, x, 1, 0, y, 1, 0, param ); + if ( y[ 0 ] != y[ 0 ] ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( y[ 0 ] != y[ 0 ] ) { + printf( "should not return NaN\n" ); + } + return elapsed; +} + /** * Main execution sequence. */ @@ -144,7 +179,14 @@ int main( void ) { for ( j = 0; j < REPEATS; j++ ) { count += 1; printf( "# c::%s:len=%d\n", NAME, len ); - elapsed = benchmark( iter, len ); + elapsed = benchmark1( iter, len ); + print_results( iter, elapsed ); + printf( "ok %d benchmark finished\n", count ); + } + for ( j = 0; j < REPEATS; j++ ) { + count += 1; + printf( "# c::%s:ndarray:len=%d\n", NAME, len ); + elapsed = benchmark2( iter, len ); print_results( iter, elapsed ); printf( "ok %d benchmark finished\n", count ); } diff --git a/lib/node_modules/@stdlib/blas/base/srotm/examples/c/example.c b/lib/node_modules/@stdlib/blas/base/srotm/examples/c/example.c index 033f115a9f7..2f73fc99d48 100644 --- a/lib/node_modules/@stdlib/blas/base/srotm/examples/c/example.c +++ b/lib/node_modules/@stdlib/blas/base/srotm/examples/c/example.c @@ -41,4 +41,12 @@ int main( void ) { for ( int i = 0; i < 5; i++ ) { printf( "x[ %i ] = %f, y[ %i ] = %f\n", i, x[ i ], i, y[ i ] ); } + + // Apply plane rotation: + c_srotm_ndarray( N, x, -strideX, N-1, y, -strideY, N-1, param ); + + // Print the result: + for ( int i = 0; i < 5; i++ ) { + printf( "x[ %i ] = %f, y[ %i ] = %f\n", i, x[ i ], i, y[ i ] ); + } } diff --git a/lib/node_modules/@stdlib/blas/base/srotm/include/stdlib/blas/base/srotm.h b/lib/node_modules/@stdlib/blas/base/srotm/include/stdlib/blas/base/srotm.h index b7507179f0f..3ea129f453a 100644 --- a/lib/node_modules/@stdlib/blas/base/srotm/include/stdlib/blas/base/srotm.h +++ b/lib/node_modules/@stdlib/blas/base/srotm/include/stdlib/blas/base/srotm.h @@ -36,6 +36,11 @@ extern "C" { */ void API_SUFFIX(c_srotm)( const CBLAS_INT N, float *X, const CBLAS_INT strideX, float *Y, const CBLAS_INT strideY, const float *param ); +/** +* Applies a modified Givens plane rotation using alternative indexing semantics. +*/ +void API_SUFFIX(c_srotm_ndarray)( const CBLAS_INT N, float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, float *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY, const float *param ); + #ifdef __cplusplus } #endif diff --git a/lib/node_modules/@stdlib/blas/base/srotm/lib/ndarray.js b/lib/node_modules/@stdlib/blas/base/srotm/lib/ndarray.js index 186079dd3c0..094b2691a15 100644 --- a/lib/node_modules/@stdlib/blas/base/srotm/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/srotm/lib/ndarray.js @@ -31,10 +31,10 @@ var f32 = require( '@stdlib/number/float64/base/to-float32' ); * @param {PositiveInteger} N - number of indexed elements * @param {Float32Array} x - first input array * @param {integer} strideX - `x` stride length -* @param {NonNegativeInteger} offsetX - starting `x` index +* @param {NonNegativeInteger} offsetX - starting index for `x` * @param {Float32Array} y - second input array * @param {integer} strideY - `y` stride length -* @param {NonNegativeInteger} offsetY - starting `y` index +* @param {NonNegativeInteger} offsetY - starting index for `y` * @param {Float32Array} param - parameters for the modified Givens transformation * @returns {Float32Array} `y` * diff --git a/lib/node_modules/@stdlib/blas/base/srotm/lib/ndarray.native.js b/lib/node_modules/@stdlib/blas/base/srotm/lib/ndarray.native.js index 5c0ce5ec198..308290c8274 100644 --- a/lib/node_modules/@stdlib/blas/base/srotm/lib/ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/base/srotm/lib/ndarray.native.js @@ -20,9 +20,7 @@ // MODULES // -var minViewBufferIndex = require( '@stdlib/strided/base/min-view-buffer-index' ); -var offsetView = require( '@stdlib/strided/base/offset-view' ); -var addon = require( './srotm.native.js' ); +var addon = require( './../src/addon.node' ); // MAIN // @@ -33,10 +31,10 @@ var addon = require( './srotm.native.js' ); * @param {PositiveInteger} N - number of indexed elements * @param {Float32Array} x - first input array * @param {integer} strideX - `x` stride length -* @param {NonNegativeInteger} offsetX - starting `x` index +* @param {NonNegativeInteger} offsetX - starting index for `x` * @param {Float32Array} y - second input array * @param {integer} strideY - `y` stride length -* @param {NonNegativeInteger} offsetY - starting `y` index +* @param {NonNegativeInteger} offsetY - starting index for `y` * @param {Float32Array} param - parameters for the modified Givens transformation * @returns {Float32Array} `y` * @@ -52,16 +50,7 @@ var addon = require( './srotm.native.js' ); * // y => [ ~1.7, ~-0.9, ~0.5, ~0.7, ~-1.6, ~0.2, ~2.4 ] */ function srotm( N, x, strideX, offsetX, y, strideY, offsetY, param ) { - var viewX; - var viewY; - - offsetX = minViewBufferIndex( N, strideX, offsetX ); - offsetY = minViewBufferIndex( N, strideY, offsetY ); - - viewX = offsetView( x, offsetX ); - viewY = offsetView( y, offsetY ); - - addon( N, viewX, strideX, viewY, strideY, param ); + addon.ndarray( N, x, strideX, offsetX, y, strideY, offsetY, param ); return y; } diff --git a/lib/node_modules/@stdlib/blas/base/srotm/lib/srotm.js b/lib/node_modules/@stdlib/blas/base/srotm/lib/srotm.js index c4e028821d3..b80a75bc6ad 100644 --- a/lib/node_modules/@stdlib/blas/base/srotm/lib/srotm.js +++ b/lib/node_modules/@stdlib/blas/base/srotm/lib/srotm.js @@ -49,16 +49,8 @@ var ndarray = require( './ndarray.js' ); * // y => [ ~1.7, ~-0.9, ~0.5, ~0.7, ~-1.6, ~0.2, ~2.4 ] */ function srotm( N, x, strideX, y, strideY, param ) { - var sflag; - var ix; - var iy; - - sflag = param[ 0 ]; - if ( N <= 0 || sflag === -2.0 ) { - return y; - } - ix = stride2offset( N, strideX ); - iy = stride2offset( N, strideY ); + var ix = stride2offset( N, strideX ); + var iy = stride2offset( N, strideY ); return ndarray( N, x, strideX, ix, y, strideY, iy, param ); } diff --git a/lib/node_modules/@stdlib/blas/base/srotm/manifest.json b/lib/node_modules/@stdlib/blas/base/srotm/manifest.json index 717d6dd283b..fec31a73753 100644 --- a/lib/node_modules/@stdlib/blas/base/srotm/manifest.json +++ b/lib/node_modules/@stdlib/blas/base/srotm/manifest.json @@ -44,6 +44,7 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/napi/export", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", @@ -57,7 +58,8 @@ "blas": "", "wasm": false, "src": [ - "./src/srotm.c" + "./src/srotm.c", + "./src/srotm_ndarray.c" ], "include": [ "./include" @@ -65,7 +67,8 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] }, { @@ -74,7 +77,8 @@ "blas": "", "wasm": false, "src": [ - "./src/srotm.c" + "./src/srotm.c", + "./src/srotm_ndarray.c" ], "include": [ "./include" @@ -82,7 +86,8 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] }, @@ -104,6 +109,7 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/napi/export", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", @@ -128,7 +134,8 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index" ] }, { @@ -148,7 +155,8 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index" ] }, @@ -168,6 +176,7 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/napi/export", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", @@ -181,7 +190,8 @@ "blas": "", "wasm": false, "src": [ - "./src/srotm.c" + "./src/srotm.c", + "./src/srotm_ndarray.c" ], "include": [ "./include" @@ -189,7 +199,8 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] }, { @@ -198,7 +209,8 @@ "blas": "", "wasm": false, "src": [ - "./src/srotm.c" + "./src/srotm.c", + "./src/srotm_ndarray.c" ], "include": [ "./include" @@ -206,7 +218,8 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] }, @@ -227,6 +240,7 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/napi/export", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", @@ -250,7 +264,8 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index" ] }, { @@ -269,7 +284,8 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index" ] }, @@ -291,6 +307,7 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/napi/export", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", @@ -315,7 +332,8 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index" ] }, { @@ -335,7 +353,8 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index" ] }, @@ -345,7 +364,8 @@ "blas": "", "wasm": false, "src": [ - "./src/srotm.c" + "./src/srotm.c", + "./src/srotm_ndarray.c" ], "include": [ "./include" @@ -354,6 +374,7 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset", "@stdlib/napi/export", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", @@ -367,7 +388,8 @@ "blas": "", "wasm": false, "src": [ - "./src/srotm.c" + "./src/srotm.c", + "./src/srotm_ndarray.c" ], "include": [ "./include" @@ -375,7 +397,8 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] }, { @@ -384,7 +407,8 @@ "blas": "", "wasm": false, "src": [ - "./src/srotm.c" + "./src/srotm.c", + "./src/srotm_ndarray.c" ], "include": [ "./include" @@ -392,7 +416,8 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] }, @@ -402,7 +427,8 @@ "blas": "", "wasm": true, "src": [ - "./src/srotm.c" + "./src/srotm.c", + "./src/srotm_ndarray.c" ], "include": [ "./include" @@ -410,7 +436,8 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] } ] diff --git a/lib/node_modules/@stdlib/blas/base/srotm/src/addon.c b/lib/node_modules/@stdlib/blas/base/srotm/src/addon.c index f7b4faf9af5..bc183c64358 100644 --- a/lib/node_modules/@stdlib/blas/base/srotm/src/addon.c +++ b/lib/node_modules/@stdlib/blas/base/srotm/src/addon.c @@ -44,4 +44,25 @@ static napi_value addon( napi_env env, napi_callback_info info ) { return NULL; } -STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) +/** +* Receives JavaScript callback invocation data. +* +* @param env environment under which the function is invoked +* @param info callback data +* @return Node-API value +*/ +static napi_value addon_method( napi_env env, napi_callback_info info ) { + STDLIB_NAPI_ARGV( env, info, argv, argc, 8 ); + STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 2 ); + STDLIB_NAPI_ARGV_INT64( env, offsetX, argv, 3 ); + STDLIB_NAPI_ARGV_INT64( env, strideY, argv, 5 ); + STDLIB_NAPI_ARGV_INT64( env, offsetY, argv, 6 ); + STDLIB_NAPI_ARGV_FLOAT32ARRAY( env, param, paramlen, argv, 7 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 1 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, Y, N, strideY, argv, 4 ); + API_SUFFIX(c_srotm_ndarray)( N, X, strideX, offsetX, Y, strideY, offsetY, param ); + return NULL; +} + +STDLIB_NAPI_MODULE_EXPORT_FCN_WITH_METHOD( addon, "ndarray", addon_method ) diff --git a/lib/node_modules/@stdlib/blas/base/srotm/src/srotm.c b/lib/node_modules/@stdlib/blas/base/srotm/src/srotm.c index 01402944f29..129f69fac6f 100644 --- a/lib/node_modules/@stdlib/blas/base/srotm/src/srotm.c +++ b/lib/node_modules/@stdlib/blas/base/srotm/src/srotm.c @@ -18,6 +18,7 @@ #include "stdlib/blas/base/srotm.h" #include "stdlib/blas/base/shared.h" +#include "stdlib/strided/base/stride2offset.h" /** * Applies a plane rotation. @@ -30,107 +31,7 @@ * @param param parameters for the modified Givens transformation */ void API_SUFFIX(c_srotm)( const CBLAS_INT N, float *X, const CBLAS_INT strideX, float *Y, const CBLAS_INT strideY, const float *param ) { - CBLAS_INT ix; - CBLAS_INT iy; - float sflag; - float sh11; - float sh12; - float sh21; - float sh22; - CBLAS_INT i; - float w; - float z; - - sflag = param[ 0 ]; - if ( N <= 0 || sflag == -2.0f ) { - return; - } - if ( strideX == strideY && strideX > 0 ) { - ix = 0; - if ( sflag < 0.0f ) { - sh11 = param[ 1 ]; - sh12 = param[ 3 ]; - sh21 = param[ 2 ]; - sh22 = param[ 4 ]; - for ( i = 0; i < N; i++ ) { - w = X[ ix ]; - z = Y[ ix ]; - X[ ix ] = ( w * sh11 ) + ( z * sh12 ); - Y[ ix ] = ( w * sh21 ) + ( z * sh22 ); - ix += strideX; - } - return; - } - if ( sflag == 0.0f ) { - sh12 = param[ 3 ]; - sh21 = param[ 2 ]; - for ( i = 0; i < N; i++ ) { - w = X[ ix ]; - z = Y[ ix ]; - X[ ix ] = w + ( z * sh12 ); - Y[ ix ] = ( w * sh21 ) + z; - ix += strideX; - } - return; - } - sh11 = param[ 1 ]; - sh22 = param[ 4 ]; - for ( i = 0; i < N; i++ ) { - w = X[ ix ]; - z = Y[ ix ]; - X[ ix ] = ( w * sh11 ) + z; - Y[ ix ] = -w + ( z * sh22 ); - ix += strideX; - } - return; - } - if ( strideX < 0 ) { - ix = ( 1 - N ) * strideX; - } else { - ix = 0; - } - if ( strideY < 0 ) { - iy = ( 1 - N ) * strideY; - } else { - iy = 0; - } - if ( sflag < 0.0f ) { - sh11 = param[ 1 ]; - sh12 = param[ 3 ]; - sh21 = param[ 2 ]; - sh22 = param[ 4 ]; - for ( i = 0; i < N; i++ ) { - w = X[ ix ]; - z = Y[ iy ]; - X[ ix ] = ( w * sh11 ) + ( z * sh12 ); - Y[ iy ] = ( w * sh21 ) + ( z * sh22 ); - ix += strideX; - iy += strideY; - } - return; - } - if ( sflag == 0.0f ) { - sh12 = param[ 3 ]; - sh21 = param[ 2 ]; - for ( i = 0; i < N; i++ ) { - w = X[ ix ]; - z = Y[ iy ]; - X[ ix ] = w + ( z * sh12 ); - Y[ iy ] = ( w * sh21 ) + z; - ix += strideX; - iy += strideY; - } - return; - } - sh11 = param[ 1 ]; - sh22 = param[ 4 ]; - for ( i = 0; i < N; i++ ) { - w = X[ ix ]; - z = Y[ iy ]; - X[ ix ] = ( w * sh11 ) + z; - Y[ iy ] = -w + ( z * sh22 ); - ix += strideX; - iy += strideY; - } - return; + CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX ); + CBLAS_INT oy = stdlib_strided_stride2offset( N, strideY ); + API_SUFFIX(c_srotm_ndarray)( N, X, strideX, ox, Y, strideY, oy, param ); } diff --git a/lib/node_modules/@stdlib/blas/base/srotm/src/srotm_cblas.c b/lib/node_modules/@stdlib/blas/base/srotm/src/srotm_cblas.c index d0afb1c0cbd..52cc0b688ce 100644 --- a/lib/node_modules/@stdlib/blas/base/srotm/src/srotm_cblas.c +++ b/lib/node_modules/@stdlib/blas/base/srotm/src/srotm_cblas.c @@ -19,6 +19,7 @@ #include "stdlib/blas/base/srotm.h" #include "stdlib/blas/base/srotm_cblas.h" #include "stdlib/blas/base/shared.h" +#include "stdlib/strided/base/min_view_buffer_index.h" /** * Applies a modified Givens plane rotation. @@ -33,3 +34,21 @@ void API_SUFFIX(c_srotm)( const CBLAS_INT N, float *X, const CBLAS_INT strideX, float *Y, const CBLAS_INT strideY, const float *param ) { API_SUFFIX(cblas_srotm)( N, X, strideX, Y, strideY, param ); } + +/** +* Applies a modified Givens plane rotation using alternative indexing semantics. +* +* @param N number of indexed elements +* @param X first input array +* @param strideX X stride length +* @param offsetX starting index for X +* @param Y second input array +* @param strideY Y stride length +* @param offsetY starting index for Y +* @param param parameters for the modified Givens transformation +*/ +void API_SUFFIX(c_srotm_ndarray)( const CBLAS_INT N, float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, float *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY, const float *param ) { + X += stdlib_strided_min_view_buffer_index( N, strideX, offsetX ); // adjust array pointer + Y += stdlib_strided_min_view_buffer_index( N, strideY, offsetY ); // adjust array pointer + API_SUFFIX(cblas_srotm)( N, X, strideX, Y, strideY, param ); +} diff --git a/lib/node_modules/@stdlib/blas/base/srotm/src/srotm_f.c b/lib/node_modules/@stdlib/blas/base/srotm/src/srotm_f.c index 00ab7376fd0..6dac6ee9f75 100644 --- a/lib/node_modules/@stdlib/blas/base/srotm/src/srotm_f.c +++ b/lib/node_modules/@stdlib/blas/base/srotm/src/srotm_f.c @@ -19,6 +19,7 @@ #include "stdlib/blas/base/srotm.h" #include "stdlib/blas/base/srotm_fortran.h" #include "stdlib/blas/base/shared.h" +#include "stdlib/strided/base/min_view_buffer_index.h" /** * Applies a modified Givens plane rotation. @@ -33,3 +34,21 @@ void API_SUFFIX(c_srotm)( const CBLAS_INT N, float *X, const CBLAS_INT strideX, float *Y, const CBLAS_INT strideY, const float *param ) { srotm( &N, X, &strideX, Y, &strideY, param ); } + +/** +* Applies a modified Givens plane rotation using alternative indexing semantics. +* +* @param N number of indexed elements +* @param X first input array +* @param strideX X stride length +* @param offsetX starting index for X +* @param Y second input array +* @param strideY Y stride length +* @param offsetY starting index for Y +* @param param parameters for the modified Givens transformation +*/ +void API_SUFFIX(c_srotm_ndarray)( const CBLAS_INT N, float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, float *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY, const float *param ) { + X += stdlib_strided_min_view_buffer_index( N, strideX, offsetX ); // adjust array pointer + Y += stdlib_strided_min_view_buffer_index( N, strideY, offsetY ); // adjust array pointer + srotm( &N, X, &strideX, Y, &strideY, param ); +} diff --git a/lib/node_modules/@stdlib/blas/base/srotm/src/srotm_ndarray.c b/lib/node_modules/@stdlib/blas/base/srotm/src/srotm_ndarray.c new file mode 100644 index 00000000000..53306fbb946 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/srotm/src/srotm_ndarray.c @@ -0,0 +1,129 @@ +/** +* @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. +*/ + +#include "stdlib/blas/base/srotm.h" +#include "stdlib/blas/base/shared.h" + +/** +* Applies a plane rotation using alternative indexing semantics. +* +* @param N number of indexed elements +* @param X first input array +* @param strideX X stride length +* @param offsetX starting index for X +* @param Y second input array +* @param strideY Y stride length +* @param offsetY starting index for Y +* @param param parameters for the modified Givens transformation +*/ +void API_SUFFIX(c_srotm_ndarray)( const CBLAS_INT N, float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, float *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY, const float *param ) { + CBLAS_INT ix; + CBLAS_INT iy; + float sflag; + CBLAS_INT i; + float sh11; + float sh12; + float sh21; + float sh22; + float w; + float z; + + sflag = param[ 0 ]; + if ( N <= 0 || sflag == -2.0f ) { + return; + } + ix = offsetX; + iy = offsetY; + if ( strideX == strideY && strideX > 0 ) { + if ( sflag < 0.0f ) { + sh11 = param[ 1 ]; + sh12 = param[ 3 ]; + sh21 = param[ 2 ]; + sh22 = param[ 4 ]; + for ( i = 0; i < N; i++ ) { + w = X[ ix ]; + z = Y[ ix ]; + X[ ix ] = ( w * sh11 ) + ( z * sh12 ); + Y[ ix ] = ( w * sh21 ) + ( z * sh22 ); + ix += strideX; + } + return; + } + if ( sflag == 0.0f ) { + sh12 = param[ 3 ]; + sh21 = param[ 2 ]; + for ( i = 0; i < N; i++ ) { + w = X[ ix ]; + z = Y[ ix ]; + X[ ix ] = w + ( z * sh12 ); + Y[ ix ] = ( w * sh21 ) + z; + ix += strideX; + } + return; + } + sh11 = param[ 1 ]; + sh22 = param[ 4 ]; + for ( i = 0; i < N; i++ ) { + w = X[ ix ]; + z = Y[ ix ]; + X[ ix ] = ( w * sh11 ) + z; + Y[ ix ] = -w + ( z * sh22 ); + ix += strideX; + } + return; + } + if ( sflag < 0.0f ) { + sh11 = param[ 1 ]; + sh12 = param[ 3 ]; + sh21 = param[ 2 ]; + sh22 = param[ 4 ]; + for ( i = 0; i < N; i++ ) { + w = X[ ix ]; + z = Y[ iy ]; + X[ ix ] = ( w * sh11 ) + ( z * sh12 ); + Y[ iy ] = ( w * sh21 ) + ( z * sh22 ); + ix += strideX; + iy += strideY; + } + return; + } + if ( sflag == 0.0f ) { + sh12 = param[ 3 ]; + sh21 = param[ 2 ]; + for ( i = 0; i < N; i++ ) { + w = X[ ix ]; + z = Y[ iy ]; + X[ ix ] = w + ( z * sh12 ); + Y[ iy ] = ( w * sh21 ) + z; + ix += strideX; + iy += strideY; + } + return; + } + sh11 = param[ 1 ]; + sh22 = param[ 4 ]; + for ( i = 0; i < N; i++ ) { + w = X[ ix ]; + z = Y[ iy ]; + X[ ix ] = ( w * sh11 ) + z; + Y[ iy ] = -w + ( z * sh22 ); + ix += strideX; + iy += strideY; + } + return; +} diff --git a/lib/node_modules/@stdlib/blas/base/zaxpy/lib/zaxpy.js b/lib/node_modules/@stdlib/blas/base/zaxpy/lib/zaxpy.js index b3121457f43..62b51107cb4 100644 --- a/lib/node_modules/@stdlib/blas/base/zaxpy/lib/zaxpy.js +++ b/lib/node_modules/@stdlib/blas/base/zaxpy/lib/zaxpy.js @@ -20,8 +20,8 @@ // MODULES // -var stride2offset = require('@stdlib/strided/base/stride2offset'); -var ndarray = require('./ndarray.js'); +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require( './ndarray.js' ); // MAIN // diff --git a/lib/node_modules/@stdlib/blas/dswap/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/dswap/docs/types/index.d.ts index 672b8fc8464..748698aad5e 100644 --- a/lib/node_modules/@stdlib/blas/dswap/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/dswap/docs/types/index.d.ts @@ -33,7 +33,7 @@ import { float64ndarray } from '@stdlib/types/ndarray'; * * @param x - first input array * @param y - second input array -* @param dim - dimension for which to compute the dot product (default: -1) +* @param dim - dimension along which to interchange vectors (default: -1) * @throws first argument must be a non-zero-dimensional ndarray containing double-precision floating-point numbers * @throws second argument must be a non-zero-dimensional ndarray containing double-precision floating-point numbers * @throws input arrays must have the same shape diff --git a/lib/node_modules/@stdlib/blas/dswap/lib/main.js b/lib/node_modules/@stdlib/blas/dswap/lib/main.js index d3181b07210..1a713c94a05 100644 --- a/lib/node_modules/@stdlib/blas/dswap/lib/main.js +++ b/lib/node_modules/@stdlib/blas/dswap/lib/main.js @@ -20,18 +20,8 @@ // MODULES // -var isFloat64ndarrayLike = require( '@stdlib/assert/is-float64ndarray-like' ); -var isNegativeInteger = require( '@stdlib/assert/is-negative-integer' ).isPrimitive; -var isReadOnly = require( '@stdlib/ndarray/base/assert/is-read-only' ); -var hasEqualValues = require( '@stdlib/array/base/assert/has-equal-values-indexed' ); -var min = require( '@stdlib/math/base/special/fast/min' ); -var without = require( '@stdlib/array/base/without' ); -var ndarraylike2ndarray = require( '@stdlib/ndarray/base/ndarraylike2ndarray' ); -var normalizeIndex = require( '@stdlib/ndarray/base/normalize-index' ); -var nditerStacks = require( '@stdlib/ndarray/iter/stacks' ); -var numel = require( '@stdlib/ndarray/base/numel' ); var base = require( '@stdlib/blas/base/dswap' ).ndarray; -var format = require( '@stdlib/string/format' ); +var factory = require( '@stdlib/blas/tools/swap-factory' ); // MAIN // @@ -39,6 +29,8 @@ var format = require( '@stdlib/string/format' ); /** * Interchanges two double-precision floating-point vectors. * +* @name dswap +* @type {Function} * @param {ndarrayLike} x - first input array * @param {ndarrayLike} y - second input array * @param {NegativeInteger} [dim] - dimension along which to interchange elements @@ -66,86 +58,7 @@ var format = require( '@stdlib/string/format' ); * var ybuf = y.data; * // returns [ 4.0, 2.0, -3.0, 5.0, -1.0 ] */ -function dswap( x, y ) { - var dim; - var xsh; - var ysh; - var xit; - var yit; - var xc; - var yc; - var vx; - var vy; - var dm; - var S; - var N; - var i; - if ( !isFloat64ndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray containing double-precision floating-point numbers. Value: `%s`.', x ) ); - } - if ( !isFloat64ndarrayLike( y ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an ndarray containing double-precision floating-point numbers. Value: `%s`.', y ) ); - } - if ( isReadOnly( x ) || isReadOnly( y ) ) { - throw new Error( 'invalid argument. Cannot write to read-only array.' ); - } - // Convert the input arrays to "base" ndarrays: - xc = ndarraylike2ndarray( x ); - yc = ndarraylike2ndarray( y ); - - // Resolve the input array shapes: - xsh = xc.shape; - ysh = yc.shape; - - // Validate that we've been provided non-zero-dimensional arrays... - if ( xsh.length < 1 ) { - throw new TypeError( format( 'invalid argument. First argument must have at least one dimension.' ) ); - } - if ( ysh.length < 1 ) { - throw new TypeError( format( 'invalid argument. Second argument must have at least one dimension.' ) ); - } - // Validate that the arrays have the same shape... - if ( !hasEqualValues( xsh, ysh ) ) { - throw new Error( 'invalid arguments. The first and second arguments must have the same shape.' ); - } - // Validate that the dimension argument is a negative integer... - if ( arguments.length > 2 ) { - dim = arguments[ 2 ]; - if ( !isNegativeInteger( dim ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be a negative integer. Value: `%s`.', dim ) ); - } - } else { - dim = -1; - } - // Validate that a provided dimension index is within bounds... - dm = min( xsh.length, ysh.length ) - 1; - dim = normalizeIndex( dim, dm ); - if ( dim === -1 ) { - throw new RangeError( format( 'invalid argument. Third argument must be a value on the interval: [%d,%d]. Value: `%d`.', -dm, -1, arguments[ 2 ] ) ); - } - // Resolve the size of the interchange dimension: - S = xsh[ dim ]; - - // If we are only provided one-dimensional input arrays, we can skip iterating over stacks... - if ( xsh.length === 1 ) { - base( S, xc.data, xc.strides[0], xc.offset, yc.data, yc.strides[0], yc.offset ); // eslint-disable-line max-len - return y; - } - // Resolve the number of stacks: - N = numel( without( xsh, dim ) ); - - // Create iterators for iterating over stacks of vectors: - xit = nditerStacks( xc, [ dim ] ); - yit = nditerStacks( yc, [ dim ] ); - - // Interchange each pair of vectors... - for ( i = 0; i < N; i++ ) { - vx = xit.next().value; - vy = yit.next().value; - base( S, vx.data, vx.strides[0], vx.offset, vy.data, vy.strides[0], vy.offset ); // eslint-disable-line max-len - } - return y; -} +var dswap = factory( base, 'float64' ); // EXPORTS // diff --git a/lib/node_modules/@stdlib/blas/ext/base/cfill/README.md b/lib/node_modules/@stdlib/blas/ext/base/cfill/README.md index 374964e5d8c..e66274afa8a 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/cfill/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/cfill/README.md @@ -30,7 +30,7 @@ limitations under the License. var cfill = require( '@stdlib/blas/ext/base/cfill' ); ``` -#### cfill( N, alpha, x, stride ) +#### cfill( N, alpha, x, strideX ) Fills a single-precision complex floating-point strided array `x` with a specified scalar constant `alpha`. @@ -63,7 +63,7 @@ The function has the following parameters: - **N**: number of indexed elements. - **alpha**: scalar constant. - **x**: input [`Complex64Array`][@stdlib/array/complex64]. -- **stride**: index increment. +- **strideX**: index increment. The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to fill every other element @@ -143,7 +143,7 @@ im = imagf( y ); // returns 10.0 ``` -#### cfill.ndarray( N, alpha, x, stride, offset ) +#### cfill.ndarray( N, alpha, x, strideX, offsetX ) Fills a single-precision complex floating-point strided array `x` with a specified scalar constant `alpha` using alternative indexing semantics. @@ -173,9 +173,9 @@ var im = imagf( y ); The function has the following additional parameters: -- **offset**: starting index. +- **offsetX**: 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 two elements of the strided array +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 two elements of the strided array ```javascript var Float32Array = require( '@stdlib/array/float32' ); @@ -240,16 +240,15 @@ im = imagf( y ); ```javascript -var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var Complex64Array = require( '@stdlib/array/complex64' ); var Complex64 = require( '@stdlib/complex/float32/ctor' ); var cfill = require( '@stdlib/blas/ext/base/cfill' ); -function rand() { - return new Complex64( discreteUniform( 0, 10 ), discreteUniform( -5, 5 ) ); -} - -var x = filledarrayBy( 10, 'complex64', rand ); +var xbuf = discreteUniform( 20, -100, 100, { + 'dtype': 'float32' +}); +var x = new Complex64Array( xbuf.buffer ); var alpha = new Complex64( 10.0, 10.0 ); cfill( x.length, alpha, x, 1 ); @@ -260,6 +259,131 @@ console.log( x.get( 0 ).toString() ); + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/blas/ext/base/cfill.h" +``` + +#### stdlib_strided_cfill( N, alpha, \*X, strideX ) + +Fills a single-precision floating-point strided array `X` with a specified scalar constant `alpha`. + +```c +float x[] = { 1.0f, 2.0f, 3.0f, 4.0f }; +const stdlib_complex64_t alpha = stdlib_complex64( 2.0f, 2.0f ); + +stdlib_strided_cfill( 2, alpha, (stdlib_complex64_t *)x, 1 ); +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **alpha**: `[in] stdlib_complex64_t` scalar constant. +- **X**: `[out] stdlib_complex64_t*` input array. +- **strideX**: `[in] CBLAS_INT` index increment for `X`. + +```c +void stdlib_strided_cfill( const CBLAS_INT N, const stdlib_complex64_t alpha, stdlib_complex64_t *X, const CBLAS_INT strideX ); +``` + +#### stdlib_strided_cfill_ndarray( N, alpha, \*X, strideX, offsetX ) + +Fills a single-precision complex floating-point strided array `X` with a specified scalar constant `alpha` using alternative indexing semantics. + +```c +float x[] = { 1.0f, 2.0f, 3.0f, 4.0f }; +const stdlib_complex64_t alpha = stdlib_complex64( 2.0f, 2.0f ); + +stdlib_strided_cfill_ndarray( 4, alpha, (stdlib_complex64_t *x), 1, 0 ); +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **alpha**: `[in] stlib_complex64_t` scalar constant. +- **X**: `[out] stdlib_complex64_t*` input array. +- **strideX**: `[in] CBLAS_INT` index increment for `X`. +- **offsetX**: `[in] CBLAS_INT` starting index for `X`. + +```c +void stdlib_strided_cfill_ndarray( const CBLAS_INT N, const stdlib_complex64_t alpha, stdlib_complex_64_t *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/blas/ext/base/cfill.h" +#include "stdlib/complex/float32/ctor.h" +#include + +int main( void ) { + // Create a strided array of interleaved real and imaginary components: + float x[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f }; + + // Create a complex scalar: + const stdlib_complex64_t alpha = stdlib_complex64( 2.0f, 2.0f ); + + // Specify the number of indexed elements: + const int N = 4; + + // Specify a stride: + const int strideX = 1; + + // Fill the array: + stdlib_strided_cfill( N, alpha, (stdlib_complex_64_t *)x, strideX ); + + // Print the result: + for ( int i = 0; i < N; i++ ) { + printf( "x[ %i ] = %f + %fj\n", i, x[ i*2 ], x[ (i*2)+1 ] ); + } +} +``` + +
+ + + + + + +