diff --git a/.github/workflows/check_duplicate_prs.yml b/.github/workflows/check_duplicate_prs.yml new file mode 100644 index 000000000000..19f0a2ab58a2 --- /dev/null +++ b/.github/workflows/check_duplicate_prs.yml @@ -0,0 +1,74 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2025 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +# Workflow name: +name: check_duplicate_prs + +# Workflow triggers: +on: + # Run the workflow daily at 3 AM UTC: + schedule: + - cron: '0 3 * * *' + + # Allow the workflow to be manually run: + workflow_dispatch: + +# Global permissions: +permissions: + # Allow read-only access to the repository contents: + contents: read + +# Workflow jobs: +jobs: + + # Define a job for checking duplicate PRs... + check_duplicates: + + # Define a display name: + name: 'Check Duplicate PRs' + + # Ensure the job does not run on forks: + if: github.repository == 'stdlib-js/stdlib' + + # Define the type of virtual host machine: + runs-on: ubuntu-latest + + # Define the sequence of job steps... + steps: + # Checkout the repository: + - name: 'Checkout repository' + # Pin action to full length commit SHA + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + # Specify whether to remove untracked files before checking out the repository: + clean: false + + # Limit clone depth to the most recent commit: + fetch-depth: 1 + + # Specify whether to download Git-LFS files: + lfs: false + timeout-minutes: 10 + + # Check for duplicate PRs: + - name: 'Check for duplicate PRs' + env: + GITHUB_TOKEN: ${{ secrets.STDLIB_BOT_PAT_REPO_WRITE }} + run: | + . "$GITHUB_WORKSPACE/.github/workflows/scripts/check_duplicate_prs" + timeout-minutes: 15 diff --git a/.github/workflows/first_time_greeting.yml b/.github/workflows/first_time_greeting.yml index 4933c2a7d2ef..0c1deb398606 100644 --- a/.github/workflows/first_time_greeting.yml +++ b/.github/workflows/first_time_greeting.yml @@ -20,7 +20,11 @@ name: first_time_greeting # Workflow triggers: -on: [pull_request_target, issues] +on: + pull_request_target: + types: [opened] + issues: + types: [opened] # Global permissions: permissions: diff --git a/.github/workflows/scripts/check_duplicate_prs b/.github/workflows/scripts/check_duplicate_prs new file mode 100755 index 000000000000..a03745e8ecf3 --- /dev/null +++ b/.github/workflows/scripts/check_duplicate_prs @@ -0,0 +1,239 @@ +#!/usr/bin/env bash +# +# @license Apache-2.0 +# +# Copyright (c) 2025 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT 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 to identify potentially duplicate pull requests based on the issues they resolve. +# +# Usage: check_duplicate_prs +# +# Environment variables: +# +# GITHUB_TOKEN GitHub token for authentication. + +# shellcheck disable=SC2317 + +# Ensure that the exit status of pipelines is non-zero in the event that at least one of the commands in a pipeline fails: +set -o pipefail + + +# VARIABLES # + +# GitHub API base URL: +github_api_url="https://api.github.com" + +# Repository owner and name: +repo_owner="stdlib-js" +repo_name="stdlib" + +# Label to add/remove for duplicate PRs: +duplicate_label="Potential Duplicate" + + +# FUNCTIONS # + +# Error handler. +# +# $1 - error status +on_error() { + echo 'ERROR: An error was encountered during execution.' >&2 + exit "$1" +} + +# Prints a success message. +print_success() { + echo 'Success!' >&2 +} + +# Performs a GitHub API request. +# +# $1 - HTTP method (GET, POST, PATCH, etc.) +# $2 - API endpoint +# $3 - data for POST/PATCH requests +github_api() { + local method="$1" + local endpoint="$2" + local data="$3" + + # 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 + + # For POST/PATCH requests, always set the Content-Type header: + if [ "$method" != "GET" ]; then + headers+=("-H" "Content-Type: application/json") + fi + + # Make the API request: + if [ -n "${data}" ]; then + curl -s -X "${method}" "${headers[@]}" -d "${data}" "${github_api_url}${endpoint}" + else + curl -s -X "${method}" "${headers[@]}" "${github_api_url}${endpoint}" + fi +} + +# Extracts issue numbers resolved/closed in PRs for stdlib-js/stdlib. +# +# $1 - PR body text +extract_resolved_issues() { + local body="$1" + echo "$body" | grep -Eio "(resolves|closes|close|fix|fixes|fixed|resolve)[[:space:]]*(#[0-9]+|https?://github\.com/stdlib-js/stdlib/issues/[0-9]+)" | + grep -Eo "([0-9]+)$" | sort -u +} + +# Removes a label from a PR. +# +# $1 - PR number +# $2 - label name +remove_label() { + local pr_number="$1" + local label="$2" + + github_api "DELETE" "/repos/${repo_owner}/${repo_name}/issues/${pr_number}/labels/${label}" || true +} + +# Main execution sequence. +main() { + echo "Fetching open pull requests..." + + # Get all open PRs with pagination: + open_prs="[]" + page=1 + + while true; do + # Fetch current page of PRs: + page_data=$(github_api "GET" "/repos/${repo_owner}/${repo_name}/pulls?state=open&per_page=100&page=${page}") + + # Check if we got any results: + page_count=$(echo "$page_data" | jq length) + + if [ "$page_count" -eq 0 ]; then + # No more results, break the loop + break + fi + + # Merge results with our accumulated results: + open_prs=$(echo "$open_prs" "$page_data" | jq -s '.[0] + .[1]') + + # Move to next page: + page=$((page + 1)) + done + + # Check if we found any PRs: + pr_count=$(echo "$open_prs" | jq length) + if [ "$pr_count" -eq 0 ]; then + echo "No open pull requests found." + print_success + exit 0 + fi + + echo "Found ${pr_count} open pull requests." + + # Create arrays to store mappings and track labeled PRs: + declare -a issue_prs_keys + declare -a issue_prs_values + declare -a labeled_prs_list + + # Get all issues with the duplicate label in one API call + echo "Fetching PRs with duplicate label..." + encoded_label=${duplicate_label// /%20} + labeled_prs_data=$(github_api "GET" "/repos/${repo_owner}/${repo_name}/issues?labels=${encoded_label}&state=open&per_page=100") + + if ! echo "$labeled_prs_data" | jq -e 'if type=="array" then true else false end' > /dev/null 2>&1; then + echo "Warning: Invalid response when fetching labeled PRs: ${labeled_prs_data}" >&2 + elif [ -n "$labeled_prs_data" ]; then + while IFS= read -r labeled_pr; do + pr_number=$(echo "$labeled_pr" | jq -r '.number') + labeled_prs_list+=("$pr_number") + done < <(echo "$labeled_prs_data" | jq -c '.[]') + fi + echo "Found ${#labeled_prs_list[@]} PRs with duplicate label" + + # Process each PR to build issue mappings: + echo "Processing PRs for issue references..." + pr_count=0 + while IFS= read -r pr; do + pr_number=$(echo "$pr" | jq -r '.number') + pr_body=$(echo "$pr" | jq -r '.body') + resolved_issues=$(extract_resolved_issues "$pr_body") + + pr_count=$((pr_count + 1)) + if [ $((pr_count % 50)) -eq 0 ]; then + echo "Processed ${pr_count} PRs..." + fi + + for issue in $resolved_issues; do + # Find existing issue index + index=-1 + for i in "${!issue_prs_keys[@]}"; do + if [ "${issue_prs_keys[$i]}" = "$issue" ]; then + index=$i + break + fi + done + if [ "$index" -eq -1 ]; then + issue_prs_keys+=("$issue") + issue_prs_values+=("$pr_number") + else + issue_prs_values[index]="${issue_prs_values[index]} $pr_number" + fi + done + done < <(echo "${open_prs}" | jq -c '.[]') + + # Process the mappings to find duplicates: + declare -a should_be_labeled_list + + for i in "${!issue_prs_keys[@]}"; do + read -r -a prs <<< "${issue_prs_values[$i]}" + if [ ${#prs[@]} -gt 1 ]; then + for pr in "${prs[@]}"; do + should_be_labeled_list+=("$pr") + done + fi + done + + echo "PRs that should have label: ${should_be_labeled_list[*]}" + echo "PRs that currently have label: ${labeled_prs_list[*]}" + + for pr in "${labeled_prs_list[@]}"; do + echo "Checking if PR #${pr} should still have label..." + if ! printf '%s\n' "${should_be_labeled_list[@]}" | grep -q "^${pr}$"; then + echo "Removing duplicate label from PR #${pr}..." + remove_label "$pr" "$duplicate_label" + fi + done + + for pr in "${should_be_labeled_list[@]}"; do + echo "Checking if PR #${pr} needs label..." + if ! printf '%s\n' "${labeled_prs_list[@]}" | grep -q "^${pr}$"; then + echo "Adding duplicate label to PR #${pr}..." + github_api "POST" "/repos/${repo_owner}/${repo_name}/issues/${pr}/labels" \ + "{\"labels\":[\"${duplicate_label}\"]}" + else + echo "PR #${pr} already has label, skipping..." + fi + done + + print_success + exit 0 +} + +# Run main: +main diff --git a/.github/workflows/scripts/create_address_commit_comments_issues b/.github/workflows/scripts/create_address_commit_comments_issues index bb1a14db7787..cdb133a27a06 100755 --- a/.github/workflows/scripts/create_address_commit_comments_issues +++ b/.github/workflows/scripts/create_address_commit_comments_issues @@ -267,7 +267,11 @@ update_commit_map() { if [ "$found" -eq 0 ]; then commit_keys+=("$key") commit_counts+=("1") - commit_comments+=("- ${link}"$'\n\n'" > **Line ${line}**: ${formatted_body}"$'\n\n'" ${code_snippet}") + if [ "$line" = "null" ]; then + commit_comments+=("- ${link}"$'\n\n'" > ${formatted_body}"$'\n\n'" ${code_snippet}") + else + commit_comments+=("- ${link}"$'\n\n'" > **Line ${line}**: ${formatted_body}"$'\n\n'" ${code_snippet}") + fi fi } diff --git a/.github/workflows/scripts/first_time_greeting b/.github/workflows/scripts/first_time_greeting index 90d8d0fc3aec..d7fef5297ccb 100755 --- a/.github/workflows/scripts/first_time_greeting +++ b/.github/workflows/scripts/first_time_greeting @@ -133,53 +133,53 @@ main() { # Post a comment on the PR: comment=":wave: Hi there! :wave: - And thank you for opening your first pull request! We will review it shortly. :runner: :dash: +And thank you for opening your first pull request! We will review it shortly. :runner: :dash: - ## Getting Started +## Getting Started - - Please read our [contributing guidelines][stdlib-contributing] if you haven't already. - - For development guidance, refer to the [development guide][stdlib-development]. +- Please read our [contributing guidelines][stdlib-contributing] if you haven't already. +- For development guidance, refer to the [development guide][stdlib-development]. - ## Next Steps +## Next Steps - 1. A project maintainer will approve GitHub Actions workflows for your PR. - 2. All CI checks must pass before your submission can be fully reviewed. - 3. You'll need to address any failures in linting or unit tests. +1. A project maintainer will approve GitHub Actions workflows for your PR. +2. All CI checks must pass before your submission can be fully reviewed. +3. You'll need to address any failures in linting or unit tests. - ## Running Tests Locally +## Running Tests Locally - You can use \`make\` to run any of the CI commands locally from the **root directory** of the stdlib repository: +You can use \`make\` to run any of the CI commands locally from the **root directory** of the stdlib repository: - \`\`\`bash - # Run tests for all packages in the math namespace: - make test TESTS_FILTER=\".*/@stdlib/math/.*\" +\`\`\`bash +# Run tests for all packages in the math namespace: +make test TESTS_FILTER=\".*/@stdlib/math/.*\" - # Run benchmarks for a specific package: - make benchmark BENCHMARKS_FILTER=\".*/@stdlib/math/base/special/sin/.*\" - \`\`\` +# Run benchmarks for a specific package: +make benchmark BENCHMARKS_FILTER=\".*/@stdlib/math/base/special/sin/.*\" +\`\`\` - If you haven't heard back from us within two weeks, please ping us by tagging the \"reviewers\" team in a comment on this PR. +If you haven't heard back from us within two weeks, please ping us by tagging the \"reviewers\" team in a comment on this PR. - If you have any further questions while waiting for a response, please join our [Gitter channel][stdlib-gitter] to chat with project maintainers and other community members. +If you have any further questions while waiting for a response, please join our [Gitter channel][stdlib-gitter] to chat with project maintainers and other community members. - We appreciate your contribution! +We appreciate your contribution! - ## Documentation Links +## Documentation Links - - [Contributing Guidelines][stdlib-contributing] - - [Developtment Guide][stdlib-development] - - [Gitter channel][stdlib-gitter] - - [make rules for running examples][make-docs-examples] - - [make rules for running unit tests][make-docs-test] - - [make rules for running benchmarks][make-docs-benchmark] +- [Contributing Guidelines][stdlib-contributing] +- [Developtment Guide][stdlib-development] +- [Gitter channel][stdlib-gitter] +- [make rules for running examples][make-docs-examples] +- [make rules for running unit tests][make-docs-test] +- [make rules for running benchmarks][make-docs-benchmark] - [stdlib-contributing]: https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md - [stdlib-development]: https://github.com/stdlib-js/stdlib/blob/develop/docs/contributing/development.md - [stdlib-gitter]: https://gitter.im/stdlib-js/stdlib +[stdlib-contributing]: https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md +[stdlib-development]: https://github.com/stdlib-js/stdlib/blob/develop/docs/contributing/development.md +[stdlib-gitter]: https://gitter.im/stdlib-js/stdlib - [make-docs-examples]: https://github.com/stdlib-js/stdlib/blob/develop/tools/make/lib/examples/README.md - [make-docs-test]: https://github.com/stdlib-js/stdlib/blob/develop/tools/make/lib/test/README.md - [make-docs-benchmark]: https://github.com/stdlib-js/stdlib/blob/develop/tools/make/lib/benchmark/README.md" +[make-docs-examples]: https://github.com/stdlib-js/stdlib/blob/develop/tools/make/lib/examples/README.md +[make-docs-test]: https://github.com/stdlib-js/stdlib/blob/develop/tools/make/lib/test/README.md +[make-docs-benchmark]: https://github.com/stdlib-js/stdlib/blob/develop/tools/make/lib/benchmark/README.md" if ! github_api "POST" "/repos/${repo_owner}/${repo_name}/issues/${issue_number}/comments" "{\"body\":$(echo "${comment}" | jq -R -s -c .)}"; then echo "Failed to post comment on PR." on_error 1 @@ -196,13 +196,13 @@ main() { if [ "${num_issues}" = "1" ]; then # Post a comment on the issue: - comment="wave: Hi there! :wave: + comment=":wave: Hi there! :wave: - And thank you for opening your first issue! We will get back to you shortly. :runner: :dash: +And thank you for opening your first issue! We will get back to you shortly. :runner: :dash: - If you have any further questions while waiting for a response, please join our [Gitter channel][stdlib-gitter] to chat with project maintainers and other community members. +If you have any further questions while waiting for a response, please join our [Gitter channel][stdlib-gitter] to chat with project maintainers and other community members. - [stdlib-gitter]: https://gitter.im/stdlib-js/stdlib" +[stdlib-gitter]: https://gitter.im/stdlib-js/stdlib" if ! github_api "POST" "/repos/${repo_owner}/${repo_name}/issues/${issue_number}/comments" "{\"body\":$(echo "${comment}" | jq -R -s -c .)}"; then echo "Failed to post comment on issue." on_error 1 diff --git a/CONTRIBUTORS b/CONTRIBUTORS index ce6a757cf04a..b64b73e9ad10 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -181,6 +181,7 @@ Yuvi Mittal <128018763+yuvi-mittal@users.noreply.github.com> ditsu <170345142+ditsus@users.noreply.github.com> ekambains fadiothman22 <48636283+fadiothman22@users.noreply.github.com> +iraandrushko <71790513+iraandrushko@users.noreply.github.com> lohithganni <116790357+lohithganni@users.noreply.github.com> olenkabilonizhka <62379231+olenkabilonizhka@users.noreply.github.com> pranav-1720 <123018993+pranav-1720@users.noreply.github.com> diff --git a/docs/assets/talks/fossasia_bangkok_2025_gunj_joshi.png b/docs/assets/talks/fossasia_bangkok_2025_gunj_joshi.png new file mode 100644 index 000000000000..4c46c11baa3a Binary files /dev/null and b/docs/assets/talks/fossasia_bangkok_2025_gunj_joshi.png differ diff --git a/docs/git-notes/63ff1011a64fd1c968babb7ae368f25dcbc3f5cf.txt b/docs/git-notes/63ff1011a64fd1c968babb7ae368f25dcbc3f5cf.txt new file mode 100644 index 000000000000..8b1f6df57625 --- /dev/null +++ b/docs/git-notes/63ff1011a64fd1c968babb7ae368f25dcbc3f5cf.txt @@ -0,0 +1,13 @@ +--- +type: amend-message +--- +feat: add C implementation for `stats/base/dists/gumbel/skewness` + +PR-URL: #4650 +Closes: #3654 + +Co-authored-by: Philipp Burckhardt +Co-authored-by: stdlib-bot +Reviewed-by: Philipp Burckhardt +Signed-off-by: Philipp Burckhardt +Signed-off-by: Shabareesh Shetty <139731143+ShabiShett07@users.noreply.github.com> diff --git a/docs/talks.md b/docs/talks.md index 45b7596c1b6b..2dfa7b1c1265 100644 --- a/docs/talks.md +++ b/docs/talks.md @@ -26,6 +26,17 @@ limitations under the License. ## 2025 +### Numeric and Scientific Computing inside your Web Browser + +> [Gunj Joshi][gunjjoshi], FOSSASIA, March 2025 + +
+ + Numeric and Scientific Computing inside your Web Browser + +
+
+ ### Exploring stdlib: JavaScript's Answer to Technical Computing > [Athan Reines][kgryte], Inspiring Computing, February 2025 diff --git a/lib/node_modules/@stdlib/blas/base/dgemm/lib/ndarray.js b/lib/node_modules/@stdlib/blas/base/dgemm/lib/ndarray.js index 4b4b1cd6e5c6..f07227dcab8e 100644 --- a/lib/node_modules/@stdlib/blas/base/dgemm/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/dgemm/lib/ndarray.js @@ -82,6 +82,12 @@ function dgemm( transA, transB, M, N, K, alpha, A, strideA1, strideA2, offsetA, if ( K < 0 ) { throw new RangeError( format( 'invalid argument. Fifth argument must be a nonnegative integer. Value: `%d`.', K ) ); } + if ( strideC1 === 0 ) { + throw new RangeError( format( 'invalid argument. Seventeenth argument must be non-zero.', strideC1 ) ); + } + if ( strideC2 === 0 ) { + throw new RangeError( format( 'invalid argument. Eighteenth argument must be non-zero.', strideC2 ) ); + } return base( transA, transB, M, N, K, alpha, A, strideA1, strideA2, offsetA, B, strideB1, strideB2, offsetB, beta, C, strideC1, strideC2, offsetC ); // eslint-disable-line max-len } diff --git a/lib/node_modules/@stdlib/blas/base/dgemm/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/base/dgemm/test/test.ndarray.js index d8f193ad8bbd..31c374ec1b1c 100644 --- a/lib/node_modules/@stdlib/blas/base/dgemm/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/dgemm/test/test.ndarray.js @@ -224,6 +224,52 @@ tape( 'the function throws an error if provided an invalid fifth argument', func } }); +tape( 'the function throws an error if provided an invalid seventeenth argument', function test( t ) { + var values; + var data; + var i; + + data = rarbrcntantb; + + values = [ + 0 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + dgemm( data.transA, data.transB, data.M, data.N, data.K, data.alpha, new Float64Array( data.A ), data.strideA1, data.strideA2, data.offsetA, new Float64Array( data.B ), data.strideB1, data.strideB2, data.offsetB, data.beta, new Float64Array( data.C ), value, data.strideC2, data.offsetC ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid eighteenth argument', function test( t ) { + var values; + var data; + var i; + + data = rarbrcntantb; + + values = [ + 0 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + dgemm( data.transA, data.transB, data.M, data.N, data.K, data.alpha, new Float64Array( data.A ), data.strideA1, data.strideA2, data.offsetA, new Float64Array( data.B ), data.strideB1, data.strideB2, data.offsetB, data.beta, new Float64Array( data.C ), data.strideC1, value, data.offsetC ); + }; + } +}); + tape( 'the function performs the matrix-matrix operation `C = α*op(A)*op(B) + β*C` (column_major, column_major, column_major, no-transpose, no-transpose)', function test( t ) { var expected; var data; diff --git a/lib/node_modules/@stdlib/blas/base/dgemv/lib/ndarray.js b/lib/node_modules/@stdlib/blas/base/dgemv/lib/ndarray.js index 4e25ea9d2f01..a7e65c564f63 100644 --- a/lib/node_modules/@stdlib/blas/base/dgemv/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/dgemv/lib/ndarray.js @@ -73,10 +73,10 @@ function dgemv( trans, M, N, alpha, A, strideA1, strideA2, offsetA, x, strideX, throw new RangeError( format( 'invalid argument. Third argument must be a nonnegative integer. Value: `%d`.', N ) ); } if ( strideX === 0 ) { - throw new RangeError( format( 'invalid argument. Tenth argument must be non-zero.' ) ); + throw new RangeError( format( 'invalid argument. Tenth argument must be non-zero. Value: `%d`.', strideX ) ); } if ( strideY === 0 ) { - throw new RangeError( format( 'invalid argument. Fourteenth argument must be non-zero.' ) ); + throw new RangeError( format( 'invalid argument. Fourteenth argument must be non-zero. Value: `%d`.', strideY ) ); } // Check if we can early return... if ( M === 0 || N === 0 || ( alpha === 0.0 && beta === 1.0 ) ) { diff --git a/lib/node_modules/@stdlib/blas/base/dtrsv/lib/ndarray.js b/lib/node_modules/@stdlib/blas/base/dtrsv/lib/ndarray.js index 2b1632d1bcc9..7199372ef4ba 100644 --- a/lib/node_modules/@stdlib/blas/base/dtrsv/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/dtrsv/lib/ndarray.js @@ -72,6 +72,12 @@ function dtrsv( uplo, trans, diag, N, A, strideA1, strideA2, offsetA, x, strideX if ( N < 0 ) { throw new RangeError( format( 'invalid argument. Fourth argument must be a nonnegative integer. Value: `%d`.', N ) ); } + if ( strideA1 === 0 ) { + throw new RangeError( format( 'invalid argument. Sixth argument must be non-zero. Value: `%d`.', strideA1 ) ); + } + if ( strideA2 === 0 ) { + throw new RangeError( format( 'invalid argument. Seventh argument must be non-zero. Value: `%d`.', strideA2 ) ); + } if ( strideX === 0 ) { throw new RangeError( format( 'invalid argument. Tenth argument must be non-zero. Value: `%d`.', strideX ) ); } diff --git a/lib/node_modules/@stdlib/blas/base/dtrsv/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/base/dtrsv/test/test.ndarray.js index d9bf45e70ad8..159d9422279c 100644 --- a/lib/node_modules/@stdlib/blas/base/dtrsv/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/dtrsv/test/test.ndarray.js @@ -180,6 +180,52 @@ tape( 'the function throws an error if provided an invalid fourth argument', fun } }); +tape( 'the function throws an error if provided an invalid sixth argument', function test( t ) { + var values; + var data; + var i; + + data = rutu; + + values = [ + 0 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + dtrsv( data.uplo, data.trans, data.diag, data.N, new Float64Array( data.A ), value, data.strideA2, data.offsetA, new Float64Array( data.x ), data.strideX, data.offsetX ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid seventh argument', function test( t ) { + var values; + var data; + var i; + + data = rutu; + + values = [ + 0 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + dtrsv( data.uplo, data.trans, data.diag, data.N, new Float64Array( data.A ), data.strideA1, value, data.offsetA, new Float64Array( data.x ), data.strideX, data.offsetX ); + }; + } +}); + tape( 'the function throws an error if provided an invalid tenth argument', function test( t ) { var values; var data; diff --git a/lib/node_modules/@stdlib/blas/base/sgemm/lib/ndarray.js b/lib/node_modules/@stdlib/blas/base/sgemm/lib/ndarray.js index 41a397b9c6d8..14878216f3a2 100644 --- a/lib/node_modules/@stdlib/blas/base/sgemm/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/sgemm/lib/ndarray.js @@ -82,6 +82,12 @@ function sgemm( transA, transB, M, N, K, alpha, A, strideA1, strideA2, offsetA, if ( K < 0 ) { throw new RangeError( format( 'invalid argument. Fifth argument must be a nonnegative integer. Value: `%d`.', K ) ); } + if ( strideC1 === 0 ) { + throw new RangeError( format( 'invalid argument. Seventeenth argument must be non-zero.', strideC1 ) ); + } + if ( strideC2 === 0 ) { + throw new RangeError( format( 'invalid argument. Eighteenth argument must be non-zero.', strideC2 ) ); + } return base( transA, transB, M, N, K, alpha, A, strideA1, strideA2, offsetA, B, strideB1, strideB2, offsetB, beta, C, strideC1, strideC2, offsetC ); // eslint-disable-line max-len } diff --git a/lib/node_modules/@stdlib/blas/base/sgemm/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/base/sgemm/test/test.ndarray.js index f46f49b8796a..67d1ec501666 100644 --- a/lib/node_modules/@stdlib/blas/base/sgemm/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/sgemm/test/test.ndarray.js @@ -224,6 +224,52 @@ tape( 'the function throws an error if provided an invalid fifth argument', func } }); +tape( 'the function throws an error if provided an invalid seventeenth argument', function test( t ) { + var values; + var data; + var i; + + data = rarbrcntantb; + + values = [ + 0 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + sgemm( data.transA, data.transB, data.M, data.N, data.K, data.alpha, new Float32Array( data.A ), data.strideA1, data.strideA2, data.offsetA, new Float32Array( data.B ), data.strideB1, data.strideB2, data.offsetB, data.beta, new Float32Array( data.C ), value, data.strideC2, data.offsetC ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid eighteenth argument', function test( t ) { + var values; + var data; + var i; + + data = rarbrcntantb; + + values = [ + 0 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + sgemm( data.transA, data.transB, data.M, data.N, data.K, data.alpha, new Float32Array( data.A ), data.strideA1, data.strideA2, data.offsetA, new Float32Array( data.B ), data.strideB1, data.strideB2, data.offsetB, data.beta, new Float32Array( data.C ), data.strideC1, value, data.offsetC ); + }; + } +}); + tape( 'the function performs the matrix-matrix operation `C = α*op(A)*op(B) + β*C` (column_major, column_major, column_major, no-transpose, no-transpose)', function test( t ) { var expected; var data; diff --git a/lib/node_modules/@stdlib/blas/base/sgemv/lib/ndarray.js b/lib/node_modules/@stdlib/blas/base/sgemv/lib/ndarray.js index d31a8be5cfc0..e16eb245b948 100644 --- a/lib/node_modules/@stdlib/blas/base/sgemv/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/sgemv/lib/ndarray.js @@ -73,10 +73,10 @@ function sgemv( trans, M, N, alpha, A, strideA1, strideA2, offsetA, x, strideX, throw new RangeError( format( 'invalid argument. Fourth argument must be a nonnegative integer. Value: `%d`.', N ) ); } if ( strideX === 0 ) { - throw new RangeError( format( 'invalid argument. Eleventh argument must be non-zero.' ) ); + throw new RangeError( format( 'invalid argument. Tenth argument must be non-zero. Value: `%d`.', strideX ) ); } if ( strideY === 0 ) { - throw new RangeError( format( 'invalid argument. Fifteenth argument must be non-zero.' ) ); + throw new RangeError( format( 'invalid argument. Fourteenth argument must be non-zero. Value: `%d`.', strideY ) ); } // Check if we can early return... if ( M === 0 || N === 0 || ( alpha === 0.0 && beta === 1.0 ) ) { diff --git a/lib/node_modules/@stdlib/blas/base/snrm2/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/base/snrm2/test/test.ndarray.js index a377dd57f1b6..24b8e864e89b 100644 --- a/lib/node_modules/@stdlib/blas/base/snrm2/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/snrm2/test/test.ndarray.js @@ -22,6 +22,7 @@ var tape = require( 'tape' ); var Float32Array = require( '@stdlib/array/float32' ); +var isnan = require( '@stdlib/assert/is-nan' ); var EPS = require( '@stdlib/constants/float32/eps' ); var abs = require( '@stdlib/math/base/special/abs' ); var snrm2 = require( './../lib/ndarray.js' ); @@ -83,6 +84,31 @@ tape( 'the function calculates the L2-norm of a vector', function test( t ) { z = snrm2( x.length, x, 1, 0 ); isApprox( t, z, 4.0, 1.0 ); + x = new Float32Array( [ 9.0e-20, 9.0e-20, 1.2e-19 ] ); + + z = snrm2( x.length, x, 1, 0 ); + isApprox( t, z, 1.7492856287692852e-19, 1.0 ); + + x = new Float32Array( [ 1.0e-20, 1.0e-20, 1.0e-20, 1.0e-20 ] ); + + z = snrm2( x.length, x, 1, 0 ); + isApprox( t, z, 1.999999936531045e-20, 1.0 ); + + x = new Float32Array( [ 1.0e20, 1.0e5, 1.0e20, 1.0e5 ] ); + + z = snrm2( x.length, x, 1, 0 ); + t.strictEqual( z, 141421358199525600000.0, 'returns expected value' ); + + x = new Float32Array( [ 1.0e-20, 1.0e5, 1.0e-20, 1.0e5 ] ); + + z = snrm2( x.length, x, 1, 0 ); + t.strictEqual( z, 141421.359375, 'returns expected value' ); + + x = new Float32Array( [ 1.4e-19, 1.5e-19, 1.4e-19, 0.0 ] ); + + z = snrm2( x.length, x, 1, 0 ); + isApprox( t, z, 2.4839484162537295e-19, 1.0 ); + t.end(); }); @@ -101,6 +127,23 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu t.end(); }); +tape( 'the function returns NaN if provided an array element equal to NaN', function test( t ) { + var actual; + var x; + + x = new Float32Array( [ 1.4e40, NaN ] ); + + actual = snrm2( 2, x, 1, 0 ); + t.strictEqual( isnan( actual ), true, 'returns expected value' ); + + x = new Float32Array( [ 1.0, -2.0, NaN, 5.0, 3.0 ] ); + + actual = snrm2( 3, x, 1, 0 ); + t.strictEqual( isnan( actual ), true, 'returns expected value' ); + + t.end(); +}); + tape( 'the function supports a `stride` parameter', function test( t ) { var N; var x; diff --git a/lib/node_modules/@stdlib/blas/base/snrm2/test/test.ndarray.native.js b/lib/node_modules/@stdlib/blas/base/snrm2/test/test.ndarray.native.js index b21dda7b9459..2da97e775d63 100644 --- a/lib/node_modules/@stdlib/blas/base/snrm2/test/test.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/base/snrm2/test/test.ndarray.native.js @@ -23,6 +23,7 @@ var resolve = require( 'path' ).resolve; var tape = require( 'tape' ); var Float32Array = require( '@stdlib/array/float32' ); +var isnan = require( '@stdlib/assert/is-nan' ); var EPS = require( '@stdlib/constants/float32/eps' ); var abs = require( '@stdlib/math/base/special/abs' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -92,6 +93,31 @@ tape( 'the function calculates the L2-norm of a vector', opts, function test( t z = snrm2( x.length, x, 1, 0 ); isApprox( t, z, 4.0, 1.0 ); + x = new Float32Array( [ 9.0e-20, 9.0e-20, 1.2e-19 ] ); + + z = snrm2( x.length, x, 1, 0 ); + isApprox( t, z, 1.7492856287692852e-19, 1.0 ); + + x = new Float32Array( [ 1.0e-20, 1.0e-20, 1.0e-20, 1.0e-20 ] ); + + z = snrm2( x.length, x, 1, 0 ); + isApprox( t, z, 1.999999936531045e-20, 1.0 ); + + x = new Float32Array( [ 1.0e20, 1.0e5, 1.0e20, 1.0e5 ] ); + + z = snrm2( x.length, x, 1, 0 ); + t.strictEqual( z, 141421358199525600000.0, 'returns expected value' ); + + x = new Float32Array( [ 1.0e-20, 1.0e5, 1.0e-20, 1.0e5 ] ); + + z = snrm2( x.length, x, 1, 0 ); + t.strictEqual( z, 141421.359375, 'returns expected value' ); + + x = new Float32Array( [ 1.4e-19, 1.5e-19, 1.4e-19, 0.0 ] ); + + z = snrm2( x.length, x, 1, 0 ); + isApprox( t, z, 2.4839484162537295e-19, 1.0 ); + t.end(); }); @@ -110,6 +136,23 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu t.end(); }); +tape( 'the function returns NaN if provided an array element equal to NaN', opts, function test( t ) { + var actual; + var x; + + x = new Float32Array( [ 1.4e40, NaN ] ); + + actual = snrm2( 2, x, 1, 0 ); + t.strictEqual( isnan( actual ), true, 'returns expected value' ); + + x = new Float32Array( [ 1.0, -2.0, NaN, 5.0, 3.0 ] ); + + actual = snrm2( 3, x, 1, 0 ); + t.strictEqual( isnan( actual ), true, 'returns expected value' ); + + t.end(); +}); + tape( 'the function supports a `stride` parameter', opts, function test( t ) { var N; var x; diff --git a/lib/node_modules/@stdlib/blas/base/snrm2/test/test.snrm2.js b/lib/node_modules/@stdlib/blas/base/snrm2/test/test.snrm2.js index 5cc4cd1ceab4..e9e0fe763f38 100644 --- a/lib/node_modules/@stdlib/blas/base/snrm2/test/test.snrm2.js +++ b/lib/node_modules/@stdlib/blas/base/snrm2/test/test.snrm2.js @@ -22,6 +22,7 @@ var tape = require( 'tape' ); var Float32Array = require( '@stdlib/array/float32' ); +var isnan = require( '@stdlib/assert/is-nan' ); var EPS = require( '@stdlib/constants/float32/eps' ); var abs = require( '@stdlib/math/base/special/abs' ); var snrm2 = require( './../lib/snrm2.js' ); @@ -83,6 +84,31 @@ tape( 'the function calculates the L2-norm of a vector', function test( t ) { z = snrm2( x.length, x, 1 ); isApprox( t, z, 4.0, 1.0 ); + x = new Float32Array( [ 9.0e-20, 9.0e-20, 1.2e-19 ] ); + + z = snrm2( x.length, x, 1 ); + isApprox( t, z, 1.7492856287692852e-19, 1.0 ); + + x = new Float32Array( [ 1.0e-20, 1.0e-20, 1.0e-20, 1.0e-20 ] ); + + z = snrm2( x.length, x, 1 ); + isApprox( t, z, 1.999999936531045e-20, 1.0 ); + + x = new Float32Array( [ 1.0e20, 1.0e5, 1.0e20, 1.0e5 ] ); + + z = snrm2( x.length, x, 1 ); + t.strictEqual( z, 141421358199525600000.0, 'returns expected value' ); + + x = new Float32Array( [ 1.0e-20, 1.0e5, 1.0e-20, 1.0e5 ] ); + + z = snrm2( x.length, x, 1 ); + t.strictEqual( z, 141421.359375, 'returns expected value' ); + + x = new Float32Array( [ 1.4e-19, 1.5e-19, 1.4e-19, 0.0 ] ); + + z = snrm2( x.length, x, 1 ); + isApprox( t, z, 2.4839484162537295e-19, 1.0 ); + t.end(); }); @@ -101,6 +127,23 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu t.end(); }); +tape( 'the function returns NaN if provided an array element equal to NaN', function test( t ) { + var actual; + var x; + + x = new Float32Array( [ 1.4e40, NaN ] ); + + actual = snrm2( 2, x, 1 ); + t.strictEqual( isnan( actual ), true, 'returns expected value' ); + + x = new Float32Array( [ 1.0, -2.0, NaN, 5.0, 3.0 ] ); + + actual = snrm2( 3, x, 1 ); + t.strictEqual( isnan( actual ), true, 'returns expected value' ); + + t.end(); +}); + tape( 'the function supports a `stride` parameter', function test( t ) { var N; var x; diff --git a/lib/node_modules/@stdlib/blas/base/snrm2/test/test.snrm2.native.js b/lib/node_modules/@stdlib/blas/base/snrm2/test/test.snrm2.native.js index fa9bc7aa06d4..f143ec2d0557 100644 --- a/lib/node_modules/@stdlib/blas/base/snrm2/test/test.snrm2.native.js +++ b/lib/node_modules/@stdlib/blas/base/snrm2/test/test.snrm2.native.js @@ -23,6 +23,7 @@ var resolve = require( 'path' ).resolve; var tape = require( 'tape' ); var Float32Array = require( '@stdlib/array/float32' ); +var isnan = require( '@stdlib/assert/is-nan' ); var EPS = require( '@stdlib/constants/float32/eps' ); var abs = require( '@stdlib/math/base/special/abs' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -92,6 +93,31 @@ tape( 'the function calculates the L2-norm of a vector', opts, function test( t z = snrm2( x.length, x, 1 ); isApprox( t, z, 4.0, 1.0 ); + x = new Float32Array( [ 9.0e-20, 9.0e-20, 1.2e-19 ] ); + + z = snrm2( x.length, x, 1 ); + isApprox( t, z, 1.7492856287692852e-19, 1.0 ); + + x = new Float32Array( [ 1.0e-20, 1.0e-20, 1.0e-20, 1.0e-20 ] ); + + z = snrm2( x.length, x, 1 ); + isApprox( t, z, 1.999999936531045e-20, 1.0 ); + + x = new Float32Array( [ 1.0e20, 1.0e5, 1.0e20, 1.0e5 ] ); + + z = snrm2( x.length, x, 1 ); + t.strictEqual( z, 141421358199525600000.0, 'returns expected value' ); + + x = new Float32Array( [ 1.0e-20, 1.0e5, 1.0e-20, 1.0e5 ] ); + + z = snrm2( x.length, x, 1 ); + t.strictEqual( z, 141421.359375, 'returns expected value' ); + + x = new Float32Array( [ 1.4e-19, 1.5e-19, 1.4e-19, 0.0 ] ); + + z = snrm2( x.length, x, 1 ); + isApprox( t, z, 2.4839484162537295e-19, 1.0 ); + t.end(); }); @@ -110,6 +136,23 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu t.end(); }); +tape( 'the function returns NaN if provided an array element equal to NaN', opts, function test( t ) { + var actual; + var x; + + x = new Float32Array( [ 1.4e40, NaN ] ); + + actual = snrm2( 2, x, 1 ); + t.strictEqual( isnan( actual ), true, 'returns expected value' ); + + x = new Float32Array( [ 1.0, -2.0, NaN, 5.0, 3.0 ] ); + + actual = snrm2( 3, x, 1 ); + t.strictEqual( isnan( actual ), true, 'returns expected value' ); + + t.end(); +}); + tape( 'the function supports a `stride` parameter', opts, function test( t ) { var N; var x; diff --git a/lib/node_modules/@stdlib/blas/base/ssyr/lib/ndarray.js b/lib/node_modules/@stdlib/blas/base/ssyr/lib/ndarray.js index 25d73510924b..5fd020560ee8 100644 --- a/lib/node_modules/@stdlib/blas/base/ssyr/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/ssyr/lib/ndarray.js @@ -64,6 +64,12 @@ function ssyr( uplo, N, alpha, x, strideX, offsetX, A, strideA1, strideA2, offse if ( strideX === 0 ) { throw new RangeError( format( 'invalid argument. Fifth argument must be non-zero. Value: `%d`.', strideX ) ); } + if ( strideA1 === 0 ) { + throw new RangeError( format( 'invalid argument. Eighth argument must be non-zero. Value: `%d`.', strideA1 ) ); + } + if ( strideA2 === 0 ) { + throw new RangeError( format( 'invalid argument. Ninth argument must be non-zero. Value: `%d`.', strideA2 ) ); + } if ( N === 0 || alpha === 0.0 ) { return A; } diff --git a/lib/node_modules/@stdlib/blas/base/ssyr/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/base/ssyr/test/test.ndarray.js index c0041585d733..b804216bf0ba 100644 --- a/lib/node_modules/@stdlib/blas/base/ssyr/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/ssyr/test/test.ndarray.js @@ -139,6 +139,52 @@ tape( 'the function throws an error if provided an invalid fifth argument', func } }); +tape( 'the function throws an error if provided an invalid eighth argument', function test( t ) { + var values; + var data; + var i; + + data = ru; + + values = [ + 0 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + ssyr( data.uplo, data.N, data.alpha, new Float32Array( data.x ), data.strideX, data.offsetX, new Float32Array( data.A ), value, data.strideA2, data.offsetA ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid ninth argument', function test( t ) { + var values; + var data; + var i; + + data = ru; + + values = [ + 0 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + ssyr( data.uplo, data.N, data.alpha, new Float32Array( data.x ), data.strideX, data.offsetX, new Float32Array( data.A ), data.strideA1, value, data.offsetA ); + }; + } +}); + tape( 'the function performs the symmetric rank 1 operation `A = α*x*x^T + A` (row-major, upper)', function test( t ) { var expected; var data; diff --git a/lib/node_modules/@stdlib/blas/base/strsv/lib/ndarray.js b/lib/node_modules/@stdlib/blas/base/strsv/lib/ndarray.js index a476b810796e..5c0df6200ef0 100644 --- a/lib/node_modules/@stdlib/blas/base/strsv/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/strsv/lib/ndarray.js @@ -72,6 +72,12 @@ function strsv( uplo, trans, diag, N, A, strideA1, strideA2, offsetA, x, strideX if ( N < 0 ) { throw new RangeError( format( 'invalid argument. Fourth argument must be a nonnegative integer. Value: `%d`.', N ) ); } + if ( strideA1 === 0 ) { + throw new RangeError( format( 'invalid argument. Sixth argument must be non-zero. Value: `%d`.', strideA1 ) ); + } + if ( strideA2 === 0 ) { + throw new RangeError( format( 'invalid argument. Seventh argument must be non-zero. Value: `%d`.', strideA2 ) ); + } if ( strideX === 0 ) { throw new RangeError( format( 'invalid argument. Tenth argument must be non-zero. Value: `%d`.', strideX ) ); } diff --git a/lib/node_modules/@stdlib/blas/base/strsv/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/base/strsv/test/test.ndarray.js index 22437c1b5f17..a5daf9354277 100644 --- a/lib/node_modules/@stdlib/blas/base/strsv/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/strsv/test/test.ndarray.js @@ -180,6 +180,52 @@ tape( 'the function throws an error if provided an invalid fourth argument', fun } }); +tape( 'the function throws an error if provided an invalid sixth argument', function test( t ) { + var values; + var data; + var i; + + data = rutu; + + values = [ + 0 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + strsv( data.uplo, data.trans, data.diag, data.N, new Float32Array( data.A ), value, data.strideA2, data.offsetA, new Float32Array( data.x ), data.strideX, data.offsetX ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid seventh argument', function test( t ) { + var values; + var data; + var i; + + data = rutu; + + values = [ + 0 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + strsv( data.uplo, data.trans, data.diag, data.N, new Float32Array( data.A ), data.strideA1, value, data.offsetA, new Float32Array( data.x ), data.strideX, data.offsetX ); + }; + } +}); + tape( 'the function throws an error if provided an invalid tenth argument', function test( t ) { var values; var data; diff --git a/lib/node_modules/@stdlib/blas/base/wasm/dswap/lib/module.js b/lib/node_modules/@stdlib/blas/base/wasm/dswap/lib/module.js index 0406fa0f44d0..100cfd58123a 100644 --- a/lib/node_modules/@stdlib/blas/base/wasm/dswap/lib/module.js +++ b/lib/node_modules/@stdlib/blas/base/wasm/dswap/lib/module.js @@ -83,10 +83,11 @@ var wasmBinary = require( './binary.js' ); * * // Read out the results: * var viewX = zeros( N, dtype ); -* var viewY = zeros( N, dtype ); * dswap.read( xptr, viewX ); -* dswap.read( yptr, viewY ); * // viewX => [ 1.0, 1.0, 1.0, 1.0, 1.0 ] +* +* var viewY = zeros( N, dtype ); +* dswap.read( yptr, viewY ); * // viewY => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] */ function Module( memory ) { @@ -166,10 +167,11 @@ inherits( Module, WasmModule ); * * // Read out the results: * var viewX = zeros( N, dtype ); -* var viewY = zeros( N, dtype ); * dswap.read( xptr, viewX ); -* dswap.read( yptr, viewY ); * // viewX => [ 1.0, 1.0, 1.0, 1.0, 1.0 ] +* +* var viewY = zeros( N, dtype ); +* dswap.read( yptr, viewY ); * // viewY => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] */ setReadOnly( Module.prototype, 'main', function dswap( N, xptr, strideX, yptr, strideY ) { // eslint-disable-line stdlib/jsdoc-doctest-decimal-point @@ -236,10 +238,11 @@ setReadOnly( Module.prototype, 'main', function dswap( N, xptr, strideX, yptr, s * * // Read out the results: * var viewX = zeros( N, dtype ); -* var viewY = zeros( N, dtype ); * dswap.read( xptr, viewX ); -* dswap.read( yptr, viewY ); * // viewX => [ 1.0, 1.0, 1.0, 1.0, 1.0 ] +* +* var viewY = zeros( N, dtype ); +* dswap.read( yptr, viewY ); * // viewY => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] */ setReadOnly( Module.prototype, 'ndarray', function dswap( N, xptr, strideX, offsetX, yptr, strideY, offsetY ) { // eslint-disable-line stdlib/jsdoc-doctest-decimal-point diff --git a/lib/node_modules/@stdlib/blas/base/wasm/sswap/README.md b/lib/node_modules/@stdlib/blas/base/wasm/sswap/README.md new file mode 100644 index 000000000000..0cce73bae09c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/wasm/sswap/README.md @@ -0,0 +1,347 @@ + + +# sswap + +> Interchange two single-precision floating point vectors. + +
+ +## Usage + +```javascript +var sswap = require( '@stdlib/blas/base/wasm/sswap' ); +``` + +#### sswap.main( N, x, strideX, y, strideY ) + +Interchanges two single-precision floating point vectors. + +```javascript +var Float32Array = require( '@stdlib/array/float32' ); + +var x = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +var y = new Float32Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ); + +sswap.main( x.length, x, 1, y, 1 ); +// x => [ 1.0, 1.0, 1.0, 1.0, 1.0 ] +// y => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] +``` + +The function has the following parameters: + +- **N**: number of indexed elements. +- **x**: input [`Float32Array`][@stdlib/array/float32]. +- **strideX**: index increment for `x`. +- **y**: input [`Float32Array`][@stdlib/array/float32]. +- **strideY**: index increment for `y`. + +The `N` and stride parameters determine which elements in the strided arrays are accessed at runtime. For example, to swap every other element from `x` with elements `y` in reverse order, + +```javascript +var Float32Array = require( '@stdlib/array/float32' ); + +var x = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +var y = new Float32Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); + +sswap.main( 3, x, 2, y, -1 ); +// y => [ 5.0, 3.0, 1.0, 1.0, 1.0, 1.0 ] +``` + +Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. + + + +```javascript +var Float32Array = require( '@stdlib/array/float32' ); + +// Initial arrays... +var x0 = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +var y0 = new Float32Array( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); + +// Create offset views... +var x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element +var y1 = new Float32Array( y0.buffer, y0.BYTES_PER_ELEMENT*3 ); // start at 4th element + +sswap.main( 3, x1, -2, y1, 1 ); +// y0 => [ 7.0, 8.0, 9.0, 6.0, 4.0, 2.0 ] +``` + +#### sswap.ndarray( N, x, strideX, offsetX, y, strideY, offsetY ) + +Interchanges two single-precision floating point vectors using alternative indexing semantics. + +```javascript +var Float32Array = require( '@stdlib/array/float32' ); + +var x = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +var y = new Float32Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ); + +sswap.ndarray( x.length, x, 1, 0, y, 1, 0 ); +// x => [ 1.0, 1.0, 1.0, 1.0, 1.0 ] +// y => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] +``` + +The function has the following additional parameters: + +- **offsetX**: starting index for `x`. +- **offsetY**: starting index for `y`. + +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameters support indexing semantics based on starting indices. For example, to swap every other value in `x` starting from the second value with the last `N` elements in `y`,..., + +```javascript +var Float32Array = require( '@stdlib/array/float32' ); + +var x = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +var y = new Float32Array( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); + +sswap.ndarray( 3, x, 2, 1, y, -1, y.length-1 ); +// x => [ 1.0, 12.0, 3.0, 11.0, 5.0, 10.0 ] +// y => [ 7.0, 8.0, 9.0, 6.0, 4.0, 2.0 ] +``` + +* * * + +### Module + +#### sswap.Module( memory ) + +Returns a new WebAssembly [module wrapper][@stdlib/wasm/module-wrapper] instance which uses the provided WebAssembly [memory][@stdlib/wasm/memory] instance as its underlying memory. + + + +```javascript +var Memory = require( '@stdlib/wasm/memory' ); + +// 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 sswap.Module( mem ); +// returns + +// Initialize the routine: +mod.initializeSync(); +``` + +#### sswap.Module.prototype.main( N, xp, sx, yp, sy ) + +Interchanges two single-precision floating point vectors. + + + +```javascript +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 mod = new sswap.Module( mem ); +// returns + +// Initialize the routine: +mod.initializeSync(); + +// Define a vector data type: +var dtype = 'float32'; + +// 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: +mod.write( xptr, oneTo( N, dtype ) ); +mod.write( yptr, ones( N, dtype ) ); + +// Perform computation: +mod.main( N, xptr, 1, yptr, 1 ); + +// Read out the results: +var viewX = zeros( N, dtype ); +var viewY = zeros( N, dtype ); +mod.read( xptr, viewX ); +mod.read( yptr, viewY ); + +console.log( viewX ); +// => [ 1.0, 1.0, 1.0, 1.0, 1.0 ] + +console.log( viewY ); +// => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] +``` + +The function has the following parameters: + +- **N**: number of indexed elements. +- **xp**: input [`Float32Array`][@stdlib/array/float32] pointer (i.e., byte offset). +- **sx**: index increment for `x`. +- **yp**: input [`Float32Array`][@stdlib/array/float32] pointer (i.e., byte offset). +- **sy**: index increment for `y`. + +#### sswap.Module.prototype.ndarray( N, xp, sx, ox, yp, sy, oy ) + +Interchanges two single-precision floating point vectors using alternative indexing semantics. + + + +```javascript +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 mod = new sswap.Module( mem ); +// returns + +// Initialize the routine: +mod.initializeSync(); + +// Define a vector data type: +var dtype = 'float32'; + +// 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: +mod.write( xptr, oneTo( N, dtype ) ); +mod.write( yptr, ones( N, dtype ) ); + +// Perform computation: +mod.ndarray( N, xptr, 1, 0, yptr, 1, 0 ); + +// Read out the results: +var viewX = zeros( N, dtype ); +var viewY = zeros( N, dtype ); +mod.read( xptr, viewX ); +mod.read( yptr, viewY ); + +console.log( viewX ); +// => [ 1.0, 1.0, 1.0, 1.0, 1.0 ] + +console.log( viewY ); +// => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] +``` + +The function has the following additional parameters: + +- **ox**: starting index for `x`. +- **oy**: starting index for `y`. + +
+ + + +
+ +* * * + +## Notes + +- If `N <= 0`, both vectors are unchanged. +- This package implements routines using WebAssembly. When provided arrays which are not allocated on a `sswap` module memory instance, data must be explicitly copied to module memory prior to computation. Data movement may entail a performance cost, and, thus, if you are using arrays external to module memory, you should prefer using [`@stdlib/blas/base/sswap`][@stdlib/blas/base/sswap]. However, if working with arrays which are allocated and explicitly managed on module memory, you can achieve better performance when compared to the pure JavaScript implementations found in [`@stdlib/blas/base/sswap`][@stdlib/blas/base/sswap]. Beware that such performance gains may come at the cost of additional complexity when having to perform manual memory management. Choosing between implementations depends heavily on the particular needs and constraints of your application, with no one choice universally better than the other. +- `sswap()` corresponds to the [BLAS][blas] level 1 function [`sswap`][sswap]. + +
+ + + +
+ +* * * + +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var sswap = require( '@stdlib/blas/base/wasm/sswap' ); + +var opts = { + 'dtype': 'float32' +}; +var x = discreteUniform( 10, 0, 100, opts ); +console.log( x ); + +var y = discreteUniform( x.length, 0, 10, opts ); +console.log( y ); + +sswap.ndarray( x.length, x, 1, 0, y, -1, y.length-1 ); +console.log( y ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/base/wasm/sswap/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/base/wasm/sswap/benchmark/benchmark.js new file mode 100644 index 000000000000..0e987e7d1bdf --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/wasm/sswap/benchmark/benchmark.js @@ -0,0 +1,106 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 hasWebAssemblySupport = require( '@stdlib/assert/has-wasm-support' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var pkg = require( './../package.json' ).name; +var sswap = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': !hasWebAssemblySupport() +}; +var options = { + 'dtype': 'float32' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = uniform( len, -100.0, 100.0, options ); + var y = uniform( len, -100.0, 100.0, options ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + sswap.main( x.length, x, 1, y, 1 ); + if ( isnan( y[ i%y.length ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y[ i%y.length ] ) ) { + b.fail( 'should not return NaN' ); + } + 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, opts, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/wasm/sswap/benchmark/benchmark.module.js b/lib/node_modules/@stdlib/blas/base/wasm/sswap/benchmark/benchmark.module.js new file mode 100644 index 000000000000..38ab98136b36 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/wasm/sswap/benchmark/benchmark.module.js @@ -0,0 +1,66 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 hasWebAssemblySupport = require( '@stdlib/assert/has-wasm-support' ); +var Memory = require( '@stdlib/wasm/memory' ); +var pkg = require( './../package.json' ).name; +var sswap = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': !hasWebAssemblySupport() +}; + + +// MAIN // + +bench( pkg+':Module:constructor', opts, function benchmark( b ) { + var values; + var o; + var v; + var i; + + o = { + 'initial': 0 + }; + values = [ + new Memory( o ), + new Memory( o ) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = new sswap.Module( values[ i%values.length ] ); + if ( typeof v !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( typeof v !== 'object' ) { + b.fail( 'should return an object' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/wasm/sswap/benchmark/benchmark.module.main.js b/lib/node_modules/@stdlib/blas/base/wasm/sswap/benchmark/benchmark.module.main.js new file mode 100644 index 000000000000..8b6b60f73089 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/wasm/sswap/benchmark/benchmark.module.main.js @@ -0,0 +1,138 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 hasWebAssemblySupport = require( '@stdlib/assert/has-wasm-support' ); +var Memory = require( '@stdlib/wasm/memory' ); +var bytesPerElement = require( '@stdlib/ndarray/base/bytes-per-element' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var pkg = require( './../package.json' ).name; +var sswap = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': !hasWebAssemblySupport() +}; +var options = { + 'dtype': 'float32' +}; + + +// 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 byteOffset; + var view; + var xptr; + var yptr; + var mod; + var mem; + var nb; + var i; + + // Create a new BLAS routine interface: + mem = new Memory({ + 'initial': 0 + }); + mod = new sswap.Module( mem ); + + // Initialize the module: + mod.initializeSync(); // eslint-disable-line node/no-sync + + // Reallocate the underlying memory to allow storing two vectors: + nb = bytesPerElement( options.dtype ); + mod.realloc( len*2*nb ); + + // Define pointers (i.e., byte offsets) to the first vector elements: + xptr = 0; + yptr = len * nb; + + // Write random values to module memory: + mod.write( xptr, uniform( len, -100.0, 100.0, options ) ); + mod.write( yptr, uniform( len, -100.0, 100.0, options ) ); + + // Retrieve a DataView of module memory: + view = mod.view; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + mod.main( len, xptr, 1, yptr, 1 ); + byteOffset = yptr + ( (i%len)*nb ); + if ( isnan( view.getFloat32( byteOffset, true ) ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( view.getFloat32( byteOffset, true ) ) ) { + b.fail( 'should not return NaN' ); + } + 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+'::module,pointers:len='+len, opts, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/wasm/sswap/benchmark/benchmark.module.ndarray.js b/lib/node_modules/@stdlib/blas/base/wasm/sswap/benchmark/benchmark.module.ndarray.js new file mode 100644 index 000000000000..8c6994495887 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/wasm/sswap/benchmark/benchmark.module.ndarray.js @@ -0,0 +1,138 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 hasWebAssemblySupport = require( '@stdlib/assert/has-wasm-support' ); +var Memory = require( '@stdlib/wasm/memory' ); +var bytesPerElement = require( '@stdlib/ndarray/base/bytes-per-element' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var pkg = require( './../package.json' ).name; +var sswap = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': !hasWebAssemblySupport() +}; +var options = { + 'dtype': 'float32' +}; + + +// 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 byteOffset; + var view; + var xptr; + var yptr; + var mod; + var mem; + var nb; + var i; + + // Create a new BLAS routine interface: + mem = new Memory({ + 'initial': 0 + }); + mod = new sswap.Module( mem ); + + // Initialize the module: + mod.initializeSync(); // eslint-disable-line node/no-sync + + // Reallocate the underlying memory to allow storing two vectors: + nb = bytesPerElement( options.dtype ); + mod.realloc( len*2*nb ); + + // Define pointers (i.e., byte offsets) to the first vector elements: + xptr = 0; + yptr = len * nb; + + // Write random values to module memory: + mod.write( xptr, uniform( len, -100.0, 100.0, options ) ); + mod.write( yptr, uniform( len, -100.0, 100.0, options ) ); + + // Retrieve a DataView of module memory: + view = mod.view; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + mod.ndarray( len, xptr, 1, 0, yptr, 1, 0 ); + byteOffset = yptr + ( (i%len)*nb ); + if ( isnan( view.getFloat32( byteOffset, true ) ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( view.getFloat32( byteOffset, true ) ) ) { + b.fail( 'should not return NaN' ); + } + 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+'::module,pointers:ndarray:len='+len, opts, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/wasm/sswap/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/base/wasm/sswap/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..6f896a37285a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/wasm/sswap/benchmark/benchmark.ndarray.js @@ -0,0 +1,106 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 hasWebAssemblySupport = require( '@stdlib/assert/has-wasm-support' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var pkg = require( './../package.json' ).name; +var sswap = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': !hasWebAssemblySupport() +}; +var options = { + 'dtype': 'float32' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = uniform( len, -100.0, 100.0, options ); + var y = uniform( len, -100.0, 100.0, options ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + sswap.ndarray( x.length, x, 1, 0, y, 1, 0 ); + if ( isnan( y[ i%y.length ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y[ i%y.length ] ) ) { + b.fail( 'should not return NaN' ); + } + 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+':ndarray:len='+len, opts, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/wasm/sswap/docs/repl.txt b/lib/node_modules/@stdlib/blas/base/wasm/sswap/docs/repl.txt new file mode 100644 index 000000000000..79e846ee5d33 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/wasm/sswap/docs/repl.txt @@ -0,0 +1,547 @@ + +{{alias}}.main( N, x, strideX, y, strideY ) + Interchanges two single-precision floating-point vectors. + + The `N` and stride parameters determine how values from `x` are swapped with + values from `y`. + + Indexing is relative to the first index. To introduce an offset, use typed + array views. + + If `N` is less than or equal to `0`, the vectors are unchanged. + + Parameters + ---------- + N: integer + Number of indexed elements. + + x: Float32Array + First input array. + + strideX: integer + Index increment for `x`. + + y: Float32Array + Second input array. + + strideY: integer + Index increment for `y`. + + Returns + ------- + y: Float32Array + Second input array. + + Examples + -------- + // Standard usage: + > var x = new {{alias:@stdlib/array/float32}}( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + > var y = new {{alias:@stdlib/array/float32}}( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ); + > {{alias}}.main( x.length, x, 1, y, 1 ) + [ 1.0, 2.0, 3.0, 4.0, 5.0 ] + + // Using `N` and stride parameters: + > x = new {{alias:@stdlib/array/float32}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + > y = new {{alias:@stdlib/array/float32}}( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); + > {{alias}}.main( 3, x, 2, y, -1 ) + [ 5.0, 3.0, 1.0, 1.0, 1.0, 1.0 ] + + // Using view offsets: + > var x0 = new {{alias:@stdlib/array/float32}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + > var y0 = new {{alias:@stdlib/array/float32}}( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); + > var x1 = new {{alias:@stdlib/array/float32}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); + > var y1 = new {{alias:@stdlib/array/float32}}( y0.buffer, y0.BYTES_PER_ELEMENT*3 ); + > {{alias}}.main( 3, x1, -2, y1, 1 ) + [ 6.0, 4.0, 2.0 ] + > y0 + [ 7.0, 8.0, 9.0, 6.0, 4.0, 2.0 ] + + +{{alias}}.ndarray( N, x, strideX, offsetX, y, strideY, offsetY ) + Interchanges two single-precision floating-point vectors 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. + + x: Float32Array + First input array. + + strideX: integer + Index increment for `x`. + + offsetX: integer + Starting index for `x`. + + y: Float32Array + Second input array. + + strideY: integer + Index increment for `y`. + + offsetY: integer + Starting index for `y`. + + Returns + ------- + y: Float32Array + Second input array. + + Examples + -------- + // Standard usage: + > var x = new {{alias:@stdlib/array/float32}}( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + > var y = new {{alias:@stdlib/array/float32}}( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ); + > {{alias}}.ndarray( x.length, x, 1, 0, y, 1, 0 ) + [ 1.0, 2.0, 3.0, 4.0, 5.0 ] + + // Advanced indexing: + > x = new {{alias:@stdlib/array/float32}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + > y = new {{alias:@stdlib/array/float32}}( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); + > {{alias}}.ndarray( 3, x, 2, 1, y, -1, y.length-1 ) + [ 7.0, 8.0, 9.0, 6.0, 4.0, 2.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 ) + Interchanges two single-precision floating point vectors. + + Parameters + ---------- + N: integer + Number of indexed elements. + + xp: integer + First input array pointer (i.e., byte offset). + + sx: integer + Index increment for `x`. + + yp: integer + Second input array pointer (i.e., byte offset). + + sy: integer + Index increment for `y`. + + Returns + ------- + yp: integer + Second input 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, 'float32' ) ); + > mod.write( yptr, {{alias:@stdlib/array/ones}}( 5, 'float32' ) ); + + // Perform computation: + > mod.main( 5, xptr, 1, yptr, 1 ); + + // Extract results from module memory: + > var view = {{alias:@stdlib/array/zeros}}( 5, 'float32' ); + > mod.read( yptr, view ); + > view + [ 1.0, 2.0, 3.0, 4.0, 5.0 ] + + +{{alias}}.Module.prototype.ndarray( N, xp, sx, ox, yp, sy, oy ) + Interchanges two single-precision floating point vectors using alternative + indexing semantics. + + Parameters + ---------- + N: integer + Number of indexed elements. + + xp: integer + First input array pointer (i.e., byte offset). + + sx: integer + Index increment for `x`. + + ox: integer + Starting index for `x`. + + yp: integer + Second input array pointer (i.e., byte offset). + + sy: integer + Index increment for `y`. + + oy: integer + Starting index for `y`. + + Returns + ------- + oy: integer + Second input 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, 'float32' ) ); + > mod.write( yptr, {{alias:@stdlib/array/ones}}( 5, 'float32' ) ); + + // Perform computation: + > mod.ndarray( 5, xptr, 1, 0, yptr, 1, 0 ); + + // Extract results from module memory: + > var view = {{alias:@stdlib/array/zeros}}( 5, 'float32' ); + > mod.read( yptr, view ); + > view + [ 1.0, 2.0, 3.0, 4.0, 5.0 ] + + See Also + -------- diff --git a/lib/node_modules/@stdlib/blas/base/wasm/sswap/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/base/wasm/sswap/docs/types/index.d.ts new file mode 100644 index 000000000000..f2fe05c7f591 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/wasm/sswap/docs/types/index.d.ts @@ -0,0 +1,415 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 mod = new sswap.Module( mem ); + * // returns + * + * // Initialize the routine: + * mod.initializeSync(); + * + * // Define a vector data type: + * var dtype = 'float32'; + * + * // 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: + * mod.write( xptr, oneTo( N, dtype ) ); + * mod.write( yptr, ones( N, dtype ) ); + * + * // Perform computation: + * var ptr = mod.main( N, xptr, 1, yptr, 1 ); + * // returns + * + * var bool = ( ptr === yptr ); + * // returns true + * + * // Read out the results: + * var viewX = zeros( N, dtype ); + * var viewY = zeros( n, dtype ); + * mod.read( xptr, viewX ) + * mod.read( yptr, viewY ); + * // viewX => [ 1.0, 1.0, 1.0, 1.0, 1.0 ] + * // viewY => [ 1.0, 2.0, 3.0, 4.0, 5.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 mod = sswap.Module( mem ); + * // returns + * + * // Initialize the routine: + * mod.initializeSync(); + * + * // Define a vector data type: + * var dtype = 'float32'; + * + * // 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: + * mod.write( xptr, oneTo( N, dtype ) ); + * mod.write( yptr, ones( N, dtype ) ); + * + * // Perform computation: + * var ptr = mod.main( N, xptr, 1, yptr, 1 ); + * // returns + * + * var bool = ( ptr === yptr ); + * // returns true + * + * // Read out the results: + * var viewX = zeros( N, dtype ); + * var viewY = zeros( n, dtype ); + * mod.read( xptr, viewX ) + * mod.read( yptr, viewY ); + * // viewX => [ 1.0, 1.0, 1.0, 1.0, 1.0 ] + * // viewY => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] + */ + ( mem: Memory ): Module; // callable +} + +/** +* Interface describing a `sswap` WebAssembly module. +*/ +interface Module extends ModuleWrapper { + /** + * Interchanges two single-precision floating point vectors. + * + * @param N - number of indexed elements + * @param xptr - first input array pointer (i.e., byte offset) + * @param strideX - `x` stride length + * @param yptr - second input array pointer (i.e., byte offset) + * @param strideY - `y` stride length + * @returns second input 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 mod = new sswap.Module( mem ); + * // returns + * + * // Initialize the routine: + * mod.initializeSync(); + * + * // Define a vector data type: + * var dtype = 'float32'; + * + * // 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: + * mod.write( xptr, oneTo( N, dtype ) ); + * mod.write( yptr, ones( N, dtype ) ); + * + * // Perform computation: + * var ptr = mod.main( N, xptr, 1, yptr, 1 ); + * // returns + * + * var bool = ( ptr === yptr ); + * // returns true + * + * // Read out the results: + * var viewX = zeros( N, dtype ); + * var viewY = zeros( n, dtype ); + * mod.read( xptr, viewX ) + * mod.read( yptr, viewY ); + * // viewX => [ 1.0, 1.0, 1.0, 1.0, 1.0 ] + * // viewY => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] + */ + main( N: number, xptr: number, strideX: number, yptr: number, strideY: number ): number; + + /** + * Interchanges two single-precision floating point vectors using alternative indexing semantics. + * + * @param N - number of indexed elements + * @param xptr - first input array pointer (i.e., byte offset) + * @param strideX - `x` stride length + * @param offsetX - starting index for `x` + * @param yptr - second input array pointer (i.e., byte offset) + * @param strideY - `y` stride length + * @param offsetY - starting index for `y` + * @returns second input 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 mod = new sswap.Module( mem ); + * // returns + * + * // Initialize the routine: + * mod.initializeSync(); + * + * // Define a vector data type: + * var dtype = 'float32'; + * + * // 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: + * mod.write( xptr, oneTo( N, dtype ) ); + * mod.write( yptr, ones( N, dtype ) ); + * + * // Perform computation: + * var ptr = mod.ndarray( N, xptr, 1, 0, yptr, 1, 0 ); + * // returns + * + * var bool = ( ptr === yptr ); + * // returns true + * + * // Read out the results: + * var viewX = zeros( N, dtype ); + * var viewY = zeros( n, dtype ); + * mod.read( xptr, viewX ) + * mod.read( yptr, viewY ); + * // viewX => [ 1.0, 1.0, 1.0, 1.0, 1.0 ] + * // viewY => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] + */ + ndarray( N: number, xptr: number, strideX: number, offsetX: number, yptr: number, strideY: number, offsetY: number ): number; +} + +/** +* Interface describing `sswap`. +*/ +interface Routine extends ModuleWrapper { + /** + * Interchanges two single-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 + * @returns second input array + * + * @example + * var Float32Array = require( '@stdlib/array/float32' ); + * + * var x = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + * var y = new Float32Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ); + * + * sswap.main( x.length, x, 1, y, 1 ); + * // x => [ 1.0, 1.0, 1.0, 1.0, 1.0 ] + * // y => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] + */ + main( N: number, x: Float32Array, strideX: number, y: Float32Array, strideY: number ): Float32Array; + + /** + * Interchanges two single-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` + * @returns second input array + * + * @example + * var Float32Array = require( '@stdlib/array/float32' ); + * + * var x = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + * var y = new Float32Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ); + * + * sswap.ndarray( x.length, x, 1, 0, y, 1, 0 ); + * // x => [ 1.0, 1.0, 1.0, 1.0, 1.0 ] + * // y => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] + */ + ndarray( N: number, x: Float32Array, strideX: number, offsetX: number, y: Float32Array, strideY: number, offsetY: number ): Float32Array; + + /** + * 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 mod = new sswap.Module( mem ); + * // returns + * + * // Initialize the routine: + * mod.initializeSync(); + * + * // Define a vector data type: + * var dtype = 'float32'; + * + * // 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: + * mod.write( xptr, oneTo( N, dtype ) ); + * mod.write( yptr, ones( N, dtype ) ); + * + * // Perform computation: + * var ptr = mod.main( N, xptr, 1, yptr, 1 ); + * // returns + * + * var bool = ( ptr === yptr ); + * // returns true + * + * // Read out the results: + * var viewX = zeros( N, dtype ); + * var viewY = zeros( n, dtype ); + * mod.read( xptr, viewX ) + * mod.read( yptr, viewY ); + * // viewX => [ 1.0, 1.0, 1.0, 1.0, 1.0 ] + * // viewY => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] + */ + Module: ModuleConstructor; +} + +/** +* Interchanges two single-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 +* @returns second input array +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* +* var x = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +* var y = new Float32Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +* +* sswap.main( x.length, x, 1, y, 1 ); +* // x => [ 1.0, 1.0, 1.0, 1.0, 1.0 ] +* // y => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* +* var x = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +* var y = new Float32Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +* +* sswap.ndarray( x.length, x, 1, 0, y, 1, 0 ); +* // y => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] +*/ +declare var sswap: Routine; + + +// EXPORTS // + +export = sswap; diff --git a/lib/node_modules/@stdlib/blas/base/wasm/sswap/docs/types/test.ts b/lib/node_modules/@stdlib/blas/base/wasm/sswap/docs/types/test.ts new file mode 100644 index 000000000000..faf0f65eca04 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/wasm/sswap/docs/types/test.ts @@ -0,0 +1,528 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 sswap = require( './index' ); + + +// TESTS // + +// Attached to the main export is a `main` method which returns a Float32Array... +{ + const x = new Float32Array( 10 ); + const y = new Float32Array( 10 ); + + sswap.main( x.length, x, 1, y, 1 ); // $ExpectType Float32Array +} + +// The compiler throws an error if the `main` method is provided a first argument which is not a number... +{ + const x = new Float32Array( 10 ); + const y = new Float32Array( 10 ); + + sswap.main( '10', x, 1, y, 1 ); // $ExpectError + sswap.main( true, x, 1, y, 1 ); // $ExpectError + sswap.main( false, x, 1, y, 1 ); // $ExpectError + sswap.main( null, x, 1, y, 1 ); // $ExpectError + sswap.main( undefined, x, 1, y, 1 ); // $ExpectError + sswap.main( [], x, 1, y, 1 ); // $ExpectError + sswap.main( {}, x, 1, y, 1 ); // $ExpectError + sswap.main( ( x: number ): number => x, x, 1, y, 1 ); // $ExpectError +} + +// The compiler throws an error if the `main` method is provided a second argument which is not a Float32Array... +{ + const x = new Float32Array( 10 ); + const y = new Float32Array( 10 ); + + sswap.main( x.length, 10, 1, y, 1 ); // $ExpectError + sswap.main( x.length, '10', 1, y, 1 ); // $ExpectError + sswap.main( x.length, true, 1, y, 1 ); // $ExpectError + sswap.main( x.length, false, 1, y, 1 ); // $ExpectError + sswap.main( x.length, null, 1, y, 1 ); // $ExpectError + sswap.main( x.length, undefined, 1, y, 1 ); // $ExpectError + sswap.main( x.length, [], 1, y, 1 ); // $ExpectError + sswap.main( x.length, {}, 1, y, 1 ); // $ExpectError + sswap.main( x.length, ( x: number ): number => x, 1, y, 1 ); // $ExpectError +} + +// The compiler throws an error if the `main` method is provided a third argument which is not a number... +{ + const x = new Float32Array( 10 ); + const y = new Float32Array( 10 ); + + sswap.main( x.length, x, '10', y, 1 ); // $ExpectError + sswap.main( x.length, x, true, y, 1 ); // $ExpectError + sswap.main( x.length, x, false, y, 1 ); // $ExpectError + sswap.main( x.length, x, null, y, 1 ); // $ExpectError + sswap.main( x.length, x, undefined, y, 1 ); // $ExpectError + sswap.main( x.length, x, [], y, 1 ); // $ExpectError + sswap.main( x.length, x, {}, y, 1 ); // $ExpectError + sswap.main( x.length, x, ( x: number ): number => x, y, 1 ); // $ExpectError +} + +// The compiler throws an error if the `main` method is provided a fourth argument which is not a Float32Array... +{ + const x = new Float32Array( 10 ); + + sswap.main( x.length, x, 1, 10, 1 ); // $ExpectError + sswap.main( x.length, x, 1, '10', 1 ); // $ExpectError + sswap.main( x.length, x, 1, true, 1 ); // $ExpectError + sswap.main( x.length, x, 1, false, 1 ); // $ExpectError + sswap.main( x.length, x, 1, null, 1 ); // $ExpectError + sswap.main( x.length, x, 1, undefined, 1 ); // $ExpectError + sswap.main( x.length, x, 1, [], 1 ); // $ExpectError + sswap.main( x.length, x, 1, {}, 1 ); // $ExpectError + sswap.main( x.length, x, 1, ( x: number ): number => x, 1 ); // $ExpectError +} + +// The compiler throws an error if the `main` method is provided a fifth argument which is not a number... +{ + const x = new Float32Array( 10 ); + const y = new Float32Array( 10 ); + + sswap.main( x.length, x, 1, y, '10' ); // $ExpectError + sswap.main( x.length, x, 1, y, true ); // $ExpectError + sswap.main( x.length, x, 1, y, false ); // $ExpectError + sswap.main( x.length, x, 1, y, null ); // $ExpectError + sswap.main( x.length, x, 1, y, undefined ); // $ExpectError + sswap.main( x.length, x, 1, y, [] ); // $ExpectError + sswap.main( x.length, x, 1, y, {} ); // $ExpectError + sswap.main( x.length, 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 Float32Array( 10 ); + const y = new Float32Array( 10 ); + + sswap.main(); // $ExpectError + sswap.main( x.length ); // $ExpectError + sswap.main( x.length, x ); // $ExpectError + sswap.main( x.length, x, 1 ); // $ExpectError + sswap.main( x.length, x, 1, y ); // $ExpectError + sswap.main( x.length, x, 1, y, 1, 10 ); // $ExpectError +} + +// Attached to main export is an `ndarray` method which returns a Float32Array... +{ + const x = new Float32Array( 10 ); + const y = new Float32Array( 10 ); + + sswap.ndarray( x.length, x, 1, 0, y, 1, 0 ); // $ExpectType Float32Array +} + +// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number... +{ + const x = new Float32Array( 10 ); + const y = new Float32Array( 10 ); + + sswap.ndarray( '10', x, 1, 0, y, 1, 0 ); // $ExpectError + sswap.ndarray( true, x, 1, 0, y, 1, 0 ); // $ExpectError + sswap.ndarray( false, x, 1, 0, y, 1, 0 ); // $ExpectError + sswap.ndarray( null, x, 1, 0, y, 1, 0 ); // $ExpectError + sswap.ndarray( undefined, x, 1, 0, y, 1, 0 ); // $ExpectError + sswap.ndarray( [], x, 1, 0, y, 1, 0 ); // $ExpectError + sswap.ndarray( {}, x, 1, 0, y, 1, 0 ); // $ExpectError + sswap.ndarray( ( x: number ): number => x, 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 Float32Array... +{ + const x = new Float32Array( 10 ); + const y = new Float32Array( 10 ); + + sswap.ndarray( x.length, 10, 1, 0, y, 1, 0 ); // $ExpectError + sswap.ndarray( x.length, '10', 1, 0, y, 1, 0 ); // $ExpectError + sswap.ndarray( x.length, true, 1, 0, y, 1, 0 ); // $ExpectError + sswap.ndarray( x.length, false, 1, 0, y, 1, 0 ); // $ExpectError + sswap.ndarray( x.length, null, 1, 0, y, 1, 0 ); // $ExpectError + sswap.ndarray( x.length, undefined, 1, 0, y, 1, 0 ); // $ExpectError + sswap.ndarray( x.length, [], 1, 0, y, 1, 0 ); // $ExpectError + sswap.ndarray( x.length, {}, 1, 0, y, 1, 0 ); // $ExpectError + sswap.ndarray( x.length, ( x: number ): number => 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 number... +{ + const x = new Float32Array( 10 ); + const y = new Float32Array( 10 ); + + sswap.ndarray( x.length, x, '10', 0, y, 1, 0 ); // $ExpectError + sswap.ndarray( x.length, x, true, 0, y, 1, 0 ); // $ExpectError + sswap.ndarray( x.length, x, false, 0, y, 1, 0 ); // $ExpectError + sswap.ndarray( x.length, x, null, 0, y, 1, 0 ); // $ExpectError + sswap.ndarray( x.length, x, undefined, 0, y, 1, 0 ); // $ExpectError + sswap.ndarray( x.length, x, [], 0, y, 1, 0 ); // $ExpectError + sswap.ndarray( x.length, x, {}, 0, y, 1, 0 ); // $ExpectError + sswap.ndarray( x.length, x, ( x: number ): number => x, 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 Float32Array( 10 ); + const y = new Float32Array( 10 ); + + sswap.ndarray( x.length, x, 1, '10', y, 1, 0 ); // $ExpectError + sswap.ndarray( x.length, x, 1, true, y, 1, 0 ); // $ExpectError + sswap.ndarray( x.length, x, 1, false, y, 1, 0 ); // $ExpectError + sswap.ndarray( x.length, x, 1, null, y, 1, 0 ); // $ExpectError + sswap.ndarray( x.length, x, 1, undefined, y, 1, 0 ); // $ExpectError + sswap.ndarray( x.length, x, 1, [], y, 1, 0 ); // $ExpectError + sswap.ndarray( x.length, x, 1, {}, y, 1, 0 ); // $ExpectError + sswap.ndarray( x.length, x, 1, ( x: number ): number => x, y, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fifth argument which is not a Float32Array... +{ + const x = new Float32Array( 10 ); + + sswap.ndarray( x.length, x, 1, 0, 10, 1, 0 ); // $ExpectError + sswap.ndarray( x.length, x, 1, 0, '10', 1, 0 ); // $ExpectError + sswap.ndarray( x.length, x, 1, 0, true, 1, 0 ); // $ExpectError + sswap.ndarray( x.length, x, 1, 0, false, 1, 0 ); // $ExpectError + sswap.ndarray( x.length, x, 1, 0, null, 1, 0 ); // $ExpectError + sswap.ndarray( x.length, x, 1, 0, undefined, 1, 0 ); // $ExpectError + sswap.ndarray( x.length, x, 1, 0, [], 1, 0 ); // $ExpectError + sswap.ndarray( x.length, x, 1, 0, {}, 1, 0 ); // $ExpectError + sswap.ndarray( x.length, x, 1, 0, ( x: number ): number => x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a sixth argument which is not a number... +{ + const x = new Float32Array( 10 ); + const y = new Float32Array( 10 ); + + sswap.ndarray( x.length, x, 1, 0, y, '10', 0 ); // $ExpectError + sswap.ndarray( x.length, x, 1, 0, y, true, 0 ); // $ExpectError + sswap.ndarray( x.length, x, 1, 0, y, false, 0 ); // $ExpectError + sswap.ndarray( x.length, x, 1, 0, y, null, 0 ); // $ExpectError + sswap.ndarray( x.length, x, 1, 0, y, undefined, 0 ); // $ExpectError + sswap.ndarray( x.length, x, 1, 0, y, [], 0 ); // $ExpectError + sswap.ndarray( x.length, x, 1, 0, y, {}, 0 ); // $ExpectError + sswap.ndarray( x.length, x, 1, 0, y, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a seventh argument which is not a number... +{ + const x = new Float32Array( 10 ); + const y = new Float32Array( 10 ); + + sswap.ndarray( x.length, x, 1, 0, y, 1, '10' ); // $ExpectError + sswap.ndarray( x.length, x, 1, 0, y, 1, true ); // $ExpectError + sswap.ndarray( x.length, x, 1, 0, y, 1, false ); // $ExpectError + sswap.ndarray( x.length, x, 1, 0, y, 1, null ); // $ExpectError + sswap.ndarray( x.length, x, 1, 0, y, 1, undefined ); // $ExpectError + sswap.ndarray( x.length, x, 1, 0, y, 1, [] ); // $ExpectError + sswap.ndarray( x.length, x, 1, 0, y, 1, {} ); // $ExpectError + sswap.ndarray( x.length, 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 Float32Array( 10 ); + const y = new Float32Array( 10 ); + + sswap.ndarray(); // $ExpectError + sswap.ndarray( x.length ); // $ExpectError + sswap.ndarray( x.length, x ); // $ExpectError + sswap.ndarray( x.length, x, 1 ); // $ExpectError + sswap.ndarray( x.length, x, 1, 0 ); // $ExpectError + sswap.ndarray( x.length, x, 1, 0, y ); // $ExpectError + sswap.ndarray( x.length, x, 1, 0, y, 1 ); // $ExpectError + sswap.ndarray( x.length, 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 + }); + + sswap.Module( mem ); // $ExpectType Module +} + +// The compiler throws an error if the `Module` constructor is not provided a WebAssembly memory instance... +{ + sswap.Module( '10' ); // $ExpectError + sswap.Module( true ); // $ExpectError + sswap.Module( false ); // $ExpectError + sswap.Module( null ); // $ExpectError + sswap.Module( undefined ); // $ExpectError + sswap.Module( [] ); // $ExpectError + sswap.Module( {} ); // $ExpectError + sswap.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 = sswap.Module( mem ); + + mod.main( 10, 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 = sswap.Module( mem ); + + mod.main( '10', 10, 1, 80, 1 ); // $ExpectError + mod.main( true, 10, 1, 80, 1 ); // $ExpectError + mod.main( false, 10, 1, 80, 1 ); // $ExpectError + mod.main( null, 10, 1, 80, 1 ); // $ExpectError + mod.main( undefined, 10, 1, 80, 1 ); // $ExpectError + mod.main( [], 10, 1, 80, 1 ); // $ExpectError + mod.main( {}, 10, 1, 80, 1 ); // $ExpectError + mod.main( ( x: number ): number => x, 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 = sswap.Module( mem ); + + mod.main( 10, '10', 1, 80, 1 ); // $ExpectError + mod.main( 10, true, 1, 80, 1 ); // $ExpectError + mod.main( 10, false, 1, 80, 1 ); // $ExpectError + mod.main( 10, null, 1, 80, 1 ); // $ExpectError + mod.main( 10, undefined, 1, 80, 1 ); // $ExpectError + mod.main( 10, [], 1, 80, 1 ); // $ExpectError + mod.main( 10, {}, 1, 80, 1 ); // $ExpectError + mod.main( 10, ( x: number ): number => x, 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 = sswap.Module( mem ); + + mod.main( 10, 0, '10', 80, 1 ); // $ExpectError + mod.main( 10, 0, true, 80, 1 ); // $ExpectError + mod.main( 10, 0, false, 80, 1 ); // $ExpectError + mod.main( 10, 0, null, 80, 1 ); // $ExpectError + mod.main( 10, 0, undefined, 80, 1 ); // $ExpectError + mod.main( 10, 0, [], 80, 1 ); // $ExpectError + mod.main( 10, 0, {}, 80, 1 ); // $ExpectError + mod.main( 10, 0, ( x: number ): number => x, 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 = sswap.Module( mem ); + + mod.main( 10, 0, 1, '10', 1 ); // $ExpectError + mod.main( 10, 0, 1, true, 1 ); // $ExpectError + mod.main( 10, 0, 1, false, 1 ); // $ExpectError + mod.main( 10, 0, 1, null, 1 ); // $ExpectError + mod.main( 10, 0, 1, undefined, 1 ); // $ExpectError + mod.main( 10, 0, 1, [], 1 ); // $ExpectError + mod.main( 10, 0, 1, {}, 1 ); // $ExpectError + mod.main( 10, 0, 1, ( x: number ): number => x, 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 = sswap.Module( mem ); + + mod.main( 10, 0, 1, 80, '10' ); // $ExpectError + mod.main( 10, 0, 1, 80, true ); // $ExpectError + mod.main( 10, 0, 1, 80, false ); // $ExpectError + mod.main( 10, 0, 1, 80, null ); // $ExpectError + mod.main( 10, 0, 1, 80, undefined ); // $ExpectError + mod.main( 10, 0, 1, 80, [] ); // $ExpectError + mod.main( 10, 0, 1, 80, {} ); // $ExpectError + mod.main( 10, 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 = sswap.Module( mem ); + + mod.main(); // $ExpectError + mod.main( 10 ); // $ExpectError + mod.main( 10, 0 ); // $ExpectError + mod.main( 10, 0, 1 ); // $ExpectError + mod.main( 10, 0, 1, 80 ); // $ExpectError + mod.main( 10, 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 = sswap.Module( mem ); + + mod.ndarray( 10, 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 = sswap.Module( mem ); + + mod.ndarray( '10', 0, 1, 0, 80, 1, 0 ); // $ExpectError + mod.ndarray( true, 0, 1, 0, 80, 1, 0 ); // $ExpectError + mod.ndarray( false, 0, 1, 0, 80, 1, 0 ); // $ExpectError + mod.ndarray( null, 0, 1, 0, 80, 1, 0 ); // $ExpectError + mod.ndarray( undefined, 0, 1, 0, 80, 1, 0 ); // $ExpectError + mod.ndarray( [], 0, 1, 0, 80, 1, 0 ); // $ExpectError + mod.ndarray( {}, 0, 1, 0, 80, 1, 0 ); // $ExpectError + mod.ndarray( ( 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 second argument which is not a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = sswap.Module( mem ); + + mod.ndarray( 10, '10', 1, 0, 80, 1, 0 ); // $ExpectError + mod.ndarray( 10, true, 1, 0, 80, 1, 0 ); // $ExpectError + mod.ndarray( 10, false, 1, 0, 80, 1, 0 ); // $ExpectError + mod.ndarray( 10, null, 1, 0, 80, 1, 0 ); // $ExpectError + mod.ndarray( 10, undefined, 1, 0, 80, 1, 0 ); // $ExpectError + mod.ndarray( 10, [], 1, 0, 80, 1, 0 ); // $ExpectError + mod.ndarray( 10, {}, 1, 0, 80, 1, 0 ); // $ExpectError + mod.ndarray( 10, ( 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 third argument which is not a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = sswap.Module( mem ); + + mod.ndarray( 10, 0, '10', 0, 80, 1, 0 ); // $ExpectError + mod.ndarray( 10, 0, true, 0, 80, 1, 0 ); // $ExpectError + mod.ndarray( 10, 0, false, 0, 80, 1, 0 ); // $ExpectError + mod.ndarray( 10, 0, null, 0, 80, 1, 0 ); // $ExpectError + mod.ndarray( 10, 0, undefined, 0, 80, 1, 0 ); // $ExpectError + mod.ndarray( 10, 0, [], 0, 80, 1, 0 ); // $ExpectError + mod.ndarray( 10, 0, {}, 0, 80, 1, 0 ); // $ExpectError + mod.ndarray( 10, 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 fourth argument which is not a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = sswap.Module( mem ); + + mod.ndarray( 10, 0, 1, '10', 80, 1, 0 ); // $ExpectError + mod.ndarray( 10, 0, 1, true, 80, 1, 0 ); // $ExpectError + mod.ndarray( 10, 0, 1, false, 80, 1, 0 ); // $ExpectError + mod.ndarray( 10, 0, 1, null, 80, 1, 0 ); // $ExpectError + mod.ndarray( 10, 0, 1, undefined, 80, 1, 0 ); // $ExpectError + mod.ndarray( 10, 0, 1, [], 80, 1, 0 ); // $ExpectError + mod.ndarray( 10, 0, 1, {}, 80, 1, 0 ); // $ExpectError + mod.ndarray( 10, 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 fifth argument which is not a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = sswap.Module( mem ); + + mod.ndarray( 10, 0, 1, 0, '10', 1, 0 ); // $ExpectError + mod.ndarray( 10, 0, 1, 0, true, 1, 0 ); // $ExpectError + mod.ndarray( 10, 0, 1, 0, false, 1, 0 ); // $ExpectError + mod.ndarray( 10, 0, 1, 0, null, 1, 0 ); // $ExpectError + mod.ndarray( 10, 0, 1, 0, undefined, 1, 0 ); // $ExpectError + mod.ndarray( 10, 0, 1, 0, [], 1, 0 ); // $ExpectError + mod.ndarray( 10, 0, 1, 0, {}, 1, 0 ); // $ExpectError + mod.ndarray( 10, 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 sixth argument which is not a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = sswap.Module( mem ); + + mod.ndarray( 10, 0, 1, 0, 80, '10', 0 ); // $ExpectError + mod.ndarray( 10, 0, 1, 0, 80, true, 0 ); // $ExpectError + mod.ndarray( 10, 0, 1, 0, 80, false, 0 ); // $ExpectError + mod.ndarray( 10, 0, 1, 0, 80, null, 0 ); // $ExpectError + mod.ndarray( 10, 0, 1, 0, 80, undefined, 0 ); // $ExpectError + mod.ndarray( 10, 0, 1, 0, 80, [], 0 ); // $ExpectError + mod.ndarray( 10, 0, 1, 0, 80, {}, 0 ); // $ExpectError + mod.ndarray( 10, 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 a seventh argument which is not a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = sswap.Module( mem ); + + mod.ndarray( 10, 0, 1, 0, 80, 1, '10' ); // $ExpectError + mod.ndarray( 10, 0, 1, 0, 80, 1, true ); // $ExpectError + mod.ndarray( 10, 0, 1, 0, 80, 1, false ); // $ExpectError + mod.ndarray( 10, 0, 1, 0, 80, 1, null ); // $ExpectError + mod.ndarray( 10, 0, 1, 0, 80, 1, undefined ); // $ExpectError + mod.ndarray( 10, 0, 1, 0, 80, 1, [] ); // $ExpectError + mod.ndarray( 10, 0, 1, 0, 80, 1, {} ); // $ExpectError + mod.ndarray( 10, 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 = sswap.Module( mem ); + + mod.ndarray(); // $ExpectError + mod.ndarray( 10 ); // $ExpectError + mod.ndarray( 10, 0 ); // $ExpectError + mod.ndarray( 10, 0, 1 ); // $ExpectError + mod.ndarray( 10, 0, 1, 0 ); // $ExpectError + mod.ndarray( 10, 0, 1, 0, 80 ); // $ExpectError + mod.ndarray( 10, 0, 1, 0, 80, 1 ); // $ExpectError + mod.ndarray( 10, 0, 1, 0, 80, 1, 0, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/base/wasm/sswap/examples/index.js b/lib/node_modules/@stdlib/blas/base/wasm/sswap/examples/index.js new file mode 100644 index 000000000000..9151b67f8645 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/wasm/sswap/examples/index.js @@ -0,0 +1,49 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 oneTo = require( '@stdlib/array/one-to' ); +var ones = require( '@stdlib/array/ones' ); +var sswap = require( './../lib' ); + +function main() { + if ( !hasWebAssemblySupport() ) { + console.error( 'Environment does not support WebAssembly.' ); + return; + } + // Specify a vector length: + var N = 5; + + // Create two arrays: + var x = oneTo( N, 'float32' ); + var y = ones( N, 'float32' ); + + // Perform computation: + sswap.ndarray( N, x, 1, 0, y, 1, 0 ); + + // Print the results: + console.log( x ); + // => [ 1.0, 1.0, 1.0, 1.0, 1.0 ] + + console.log( y ); + // => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/wasm/sswap/examples/little_endian_array.js b/lib/node_modules/@stdlib/blas/base/wasm/sswap/examples/little_endian_array.js new file mode 100644 index 000000000000..82323b4cab18 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/wasm/sswap/examples/little_endian_array.js @@ -0,0 +1,74 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 Float32ArrayLE = require( '@stdlib/array/little-endian-float32' ); +var sswap = 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 sswap.Module( mem ); + // returns + + // Initialize the routine: + mod.initializeSync(); // eslint-disable-line node/no-sync + + // Define a vector data type: + var dtype = 'float32'; + + // 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 Float32ArrayLE( mod.memory.buffer, xptr, N ); + var y = new Float32ArrayLE( 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, 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/wasm/sswap/examples/module.js b/lib/node_modules/@stdlib/blas/base/wasm/sswap/examples/module.js new file mode 100644 index 000000000000..0c50cd30fdb3 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/wasm/sswap/examples/module.js @@ -0,0 +1,77 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 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' ); +var sswap = 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 sswap.Module( mem ); + // returns + + // Initialize the routine: + mod.initializeSync(); // eslint-disable-line node/no-sync + + // Define a vector data type: + var dtype = 'float32'; + + // 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: + mod.write( xptr, oneTo( N, dtype ) ); + mod.write( yptr, ones( N, dtype ) ); + + // Perform computation: + mod.ndarray( N, xptr, 1, 0, yptr, 1, 0 ); + + // Read out the results: + var viewX = zeros( N, dtype ); + var viewY = zeros( N, dtype ); + mod.read( xptr, viewX ); + mod.read( yptr, viewY ); + + console.log( viewX ); + // => [ 1.0, 1.0, 1.0, 1.0, 1.0 ] + + console.log( viewY ); + // => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/wasm/sswap/lib/binary.browser.js b/lib/node_modules/@stdlib/blas/base/wasm/sswap/lib/binary.browser.js new file mode 100644 index 000000000000..f17378873bab --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/wasm/sswap/lib/binary.browser.js @@ -0,0 +1,33 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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( 'AGFzbQEAAAAADwhkeWxpbmsuMAEEAAAAAAEWA2AAAGAFf39/f38AYAd/f39/f39/AAIPAQNlbnYGbWVtb3J5AgAAAwQDAAECBzEDEV9fd2FzbV9jYWxsX2N0b3JzAAAHY19zc3dhcAABD2Nfc3N3YXBfbmRhcnJheQACCvgCAwMAAQstACAAIAEgAkEBIABrIgAgAmxBACACQQBMGyADIAQgACAEbEEAIARBAEwbEAILwwICAX0CfwJAIABBAEwNACACQQFHIAVBAUdyRQRAIABBA3AiCARAQQAhAgNAIAIgCEZFBEAgASADQQJ0aiIFKgIAIQcgBSAEIAZBAnRqIgUqAgA4AgAgBSAHOAIAIAJBAWohAiAGQQFqIQYgA0EBaiEDDAELCyAAQQNIDQILA0AgACAITA0CIAEgA0ECdGoiAioCACEHIAIgBCAGQQJ0aiIFKgIAOAIAIAUgBzgCACACKgIEIQcgAiAFKgIEOAIEIAUgBzgCBCACKgIIIQcgAiAFKgIIOAIIIAUgBzgCCCAIQQNqIQggBkEDaiEGIANBA2ohAwwACwALA0AgACAIRg0BIAEgA0ECdGoiCSoCACEHIAkgBCAGQQJ0aiIJKgIAOAIAIAkgBzgCACAIQQFqIQggBSAGaiEGIAIgA2ohAwwACwALCw==' ); + + +// EXPORTS // + +module.exports = wasm; diff --git a/lib/node_modules/@stdlib/blas/base/wasm/sswap/lib/binary.js b/lib/node_modules/@stdlib/blas/base/wasm/sswap/lib/binary.js new file mode 100644 index 000000000000..2b83fe651780 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/wasm/sswap/lib/binary.js @@ -0,0 +1,34 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 readWASM = require( '@stdlib/fs/read-wasm' ).sync; + + +// MAIN // + +var wasm = readWASM( resolve( __dirname, '..', 'src', 'main.wasm' ) ); + + +// EXPORTS // + +module.exports = wasm; diff --git a/lib/node_modules/@stdlib/blas/base/wasm/sswap/lib/index.js b/lib/node_modules/@stdlib/blas/base/wasm/sswap/lib/index.js new file mode 100644 index 000000000000..d44d75f1353c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/wasm/sswap/lib/index.js @@ -0,0 +1,119 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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'; + +/** +* WebAssembly routine to interchange two single-precision floating-point vectors. +* +* @module @stdlib/blas/base/wasm/sswap +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* var sswap = require( '@stdlib/blas/base/wasm/sswap' ); +* +* // Define strided arrays: +* var x = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +* var y = new Float32Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +* +* // Perform operation: +* sswap.main( x.length, x, 1, y, 1 ); +* // x => [ 1.0, 1.0, 1.0, 1.0, 1.0 ] +* // y => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* var sswap = require( '@stdlib/blas/base/wasm/sswap' ); +* +* // Define strided arrays: +* var x = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +* var y = new Float32Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +* +* // Perform operation: +* sswap.ndarray( x.length, x, 1, 0, y, 1, 0 ); +* // x => [ 1.0, 1.0, 1.0, 1.0, 1.0 ] +* // y => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] +* +* @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' ); +* var sswap = require( '@stdlib/blas/base/wasm/sswap' ); +* +* // 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 sswap.Module( mem ); +* // returns +* +* // Initialize the routine: +* mod.initializeSync(); +* +* // Define a vector data type: +* var dtype = 'float32'; +* +* // 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: +* mod.write( xptr, oneTo( N, dtype ) ); +* mod.write( yptr, ones( N, dtype ) ); +* +* // Perform computation: +* mod.main( N, xptr, 1, yptr, 1 ); +* +* // Read out the results: +* var viewX = zeros( N, dtype ); +* var viewY = zeros( N, dtype ); +* mod.read( xptr, viewX ); +* mod.read( yptr, viewY ); +* +* console.log( viewX ); +* // => [ 1.0, 1.0, 1.0, 1.0, 1.0 ] +* +* console.log( viewY ); +* // => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] +*/ + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var main = require( './main.js' ); +var Module = require( './module.js' ); + + +// MAIN // + +setReadOnly( main, 'Module', Module ); + + +// EXPORTS // + +module.exports = main; + +// exports: { "Module": "main.Module" } diff --git a/lib/node_modules/@stdlib/blas/base/wasm/sswap/lib/main.js b/lib/node_modules/@stdlib/blas/base/wasm/sswap/lib/main.js new file mode 100644 index 000000000000..dbbb3399fe73 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/wasm/sswap/lib/main.js @@ -0,0 +1,64 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 Routine = require( './routine.js' ); + + +// MAIN // + +/** +* WebAssembly module to interchange two single-precision floating-point vectors. +* +* @name sswap +* @type {Routine} +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* +* // Define strided arrays: +* var x = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +* var y = new Float32Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +* +* // Perform operation: +* sswap.main( x.length, x, 1, y, 1 ); +* // x => [ 1.0, 1.0, 1.0, 1.0, 1.0 ] +* // y => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* +* // Define strided arrays: +* var x = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +* var y = new Float32Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +* +* // Perform operation: +* sswap.ndarray( x.length, x, 1, 0, y, 1, 0 ); +* // x => [ 1.0, 1.0, 1.0, 1.0, 1.0 ] +* // y => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] +*/ +var sswap = new Routine(); +sswap.initializeSync(); // eslint-disable-line node/no-sync + + +// EXPORTS // + +module.exports = sswap; diff --git a/lib/node_modules/@stdlib/blas/base/wasm/sswap/lib/module.js b/lib/node_modules/@stdlib/blas/base/wasm/sswap/lib/module.js new file mode 100644 index 000000000000..0863463f5cc6 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/wasm/sswap/lib/module.js @@ -0,0 +1,256 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 no-restricted-syntax, no-invalid-this */ + +'use strict'; + +// MODULES // + +var isWebAssemblyMemory = require( '@stdlib/assert/is-wasm-memory' ); +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var inherits = require( '@stdlib/utils/inherit' ); +var WasmModule = require( '@stdlib/wasm/module-wrapper' ); +var format = require( '@stdlib/string/format' ); +var wasmBinary = require( './binary.js' ); + + +// MAIN // + +/** +* BLAS routine WebAssembly module wrapper constructor. +* +* @constructor +* @param {Object} memory - WebAssembly memory instance +* @throws {TypeError} must provide a WebAssembly memory instance +* @returns {Module} module 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 sswap = new Module( mem ); +* // returns +* +* // Initialize the routine: +* sswap.initializeSync(); +* +* // Define a vector data type: +* var dtype = 'float32'; +* +* // 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: +* sswap.write( xptr, oneTo( N, dtype ) ); +* sswap.write( yptr, ones( N, dtype ) ); +* +* // Perform computation: +* var ptr = sswap.main( N, xptr, 1, yptr, 1 ); +* // returns +* +* var bool = ( ptr === yptr ); +* // returns true +* +* // Read out the results: +* var viewX = zeros( N, dtype ); +* sswap.read( xptr, viewX ); +* // viewX => [ 1.0, 1.0, 1.0, 1.0, 1.0 ] +* +* var viewY = zeros( N, dtype ); +* sswap.read( yptr, viewY ); +* // viewY => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] +*/ +function Module( memory ) { + if ( !( this instanceof Module ) ) { + return new Module( memory ); + } + if ( !isWebAssemblyMemory( memory ) ) { + throw new TypeError( format( 'invalid argument. Must provide a WebAssembly memory instance. Value: `%s`.', memory ) ); + } + // Call the parent constructor: + WasmModule.call( this, wasmBinary, memory, { + 'env': { + 'memory': memory + } + }); + + return this; +} + +// Inherit from the parent constructor: +inherits( Module, WasmModule ); + +/** +* Interchanges two single-precision floating-point vectors. +* +* @name main +* @memberof Module.prototype +* @readonly +* @type {Function} +* @param {PositiveInteger} N - number of indexed elements +* @param {NonNegativeInteger} xptr - first input array pointer (i.e., byte offset) +* @param {integer} strideX - `x` stride length +* @param {NonNegativeInteger} yptr - second input array pointer (i.e., byte offset) +* @param {integer} strideY - `y` stride length +* @returns {NonNegativeInteger} second input 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 sswap = new Module( mem ); +* // returns +* +* // Initialize the routine: +* sswap.initializeSync(); +* +* // Define a vector data type: +* var dtype = 'float32'; +* +* // 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: +* sswap.write( xptr, oneTo( N, dtype ) ); +* sswap.write( yptr, ones( N, dtype ) ); +* +* // Perform computation: +* var ptr = sswap.main( N, xptr, 1, yptr, 1 ); +* // returns +* +* var bool = ( ptr === yptr ); +* // returns true +* +* // Read out the results: +* var viewX = zeros( N, dtype ); +* sswap.read( xptr, viewX ); +* // viewX => [ 1.0, 1.0, 1.0, 1.0, 1.0 ] +* +* var viewY = zeros( N, dtype ); +* sswap.read( yptr, viewY ); +* // viewY => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] +*/ +setReadOnly( Module.prototype, 'main', function sswap( N, xptr, strideX, yptr, strideY ) { // eslint-disable-line stdlib/jsdoc-doctest-decimal-point + this._instance.exports.c_sswap( N, xptr, strideX, yptr, strideY ); + return yptr; +}); + +/** +* Interchanges two single-precision floating-point vectors using alternative indexing semantics. +* +* @name ndarray +* @memberof Module.prototype +* @readonly +* @type {Function} +* @param {PositiveInteger} N - number of indexed elements +* @param {NonNegativeInteger} xptr - first input array pointer (i.e., byte offset) +* @param {integer} strideX - `x` stride length +* @param {NonNegativeInteger} offsetX - starting `x` index +* @param {NonNegativeInteger} yptr - second input array pointer (i.e., byte offset) +* @param {integer} strideY - `y` stride length +* @param {NonNegativeInteger} offsetY - starting `y` index +* @returns {NonNegativeInteger} second input 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 sswap = new Module( mem ); +* // returns +* +* // Initialize the routine: +* sswap.initializeSync(); +* +* // Define a vector data type: +* var dtype = 'float32'; +* +* // 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: +* sswap.write( xptr, oneTo( N, dtype ) ); +* sswap.write( yptr, ones( N, dtype ) ); +* +* // Perform computation: +* var ptr = sswap.ndarray( N, xptr, 1, 0, yptr, 1, 0 ); +* // returns +* +* var bool = ( ptr === yptr ); +* // returns true +* +* // Read out the results: +* var viewX = zeros( N, dtype ); +* sswap.read( xptr, viewX ); +* // viewX => [ 1.0, 1.0, 1.0, 1.0, 1.0 ] +* +* var viewY = zeros( N, dtype ); +* sswap.read( yptr, viewY ); +* // viewY => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] +*/ +setReadOnly( Module.prototype, 'ndarray', function sswap( N, xptr, strideX, offsetX, yptr, strideY, offsetY ) { // eslint-disable-line stdlib/jsdoc-doctest-decimal-point + this._instance.exports.c_sswap_ndarray( N, xptr, strideX, offsetX, yptr, strideY, offsetY ); // eslint-disable-line max-len + return yptr; +}); + + +// EXPORTS // + +module.exports = Module; diff --git a/lib/node_modules/@stdlib/blas/base/wasm/sswap/lib/routine.js b/lib/node_modules/@stdlib/blas/base/wasm/sswap/lib/routine.js new file mode 100644 index 000000000000..ca832c802fd3 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/wasm/sswap/lib/routine.js @@ -0,0 +1,192 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 no-restricted-syntax, no-invalid-this */ + +'use strict'; + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var inherits = require( '@stdlib/utils/inherit' ); +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var readDataView = require( '@stdlib/strided/base/read-dataview' ).ndarray; +var Memory = require( '@stdlib/wasm/memory' ); +var arrays2ptrs = require( '@stdlib/wasm/base/arrays2ptrs' ); +var strided2object = require( '@stdlib/wasm/base/strided2object' ); +var Module = require( './module.js' ); + + +// MAIN // + +/** +* Routine constructor. +* +* @private +* @constructor +* @returns {Routine} routine instance +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* +* // Create a new routine: +* var sswap = new Routine(); +* +* // Initialize the module: +* sswap.initializeSync(); +* +* // Define strided arrays: +* var x = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +* var y = new Float32Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +* +* // Perform operation: +* sswap.main( x.length, x, 1, y, 1 ); +* // x => [ 1.0, 1.0, 1.0, 1.0, 1.0 ] +* // y => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* +* // Create a new routine: +* var sswap = new Routine(); +* +* // Initialize the module: +* sswap.initializeSync(); +* +* // Define strided arrays: +* var x = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +* var y = new Float32Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +* +* // Perform operation: +* sswap.ndarray( x.length, x, 1, 0, y, 1, 0 ); +* // x => [ 1.0, 1.0, 1.0, 1.0, 1.0 ] +* // y => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] +*/ +function Routine() { + if ( !( this instanceof Routine ) ) { + return new Routine(); + } + Module.call( this, new Memory({ + 'initial': 0 + })); + return this; +} + +// Inherit from the parent constructor: +inherits( Routine, Module ); + +/** +* Interchanges two single-precision floating-point vectors. +* +* @name main +* @memberof Routine.prototype +* @readonly +* @type {Function} +* @param {PositiveInteger} N - number of indexed elements +* @param {Float32Array} x - first input array +* @param {integer} strideX - `x` stride length +* @param {Float32Array} y - second input array +* @param {integer} strideY - `y` stride length +* @returns {Float32Array} second input array +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* +* // Create a new routine: +* var sswap = new Routine(); +* +* // Initialize the module: +* sswap.initializeSync(); +* +* // Define strided arrays: +* var x = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +* var y = new Float32Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +* +* // Perform operation: +* sswap.main( x.length, x, 1, y, 1 ); +* // x => [ 1.0, 1.0, 1.0, 1.0, 1.0 ] +* // y => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] +*/ +setReadOnly( Routine.prototype, 'main', function sswap( N, x, strideX, y, strideY ) { + return this.ndarray( N, x, strideX, stride2offset( N, strideX ), y, strideY, stride2offset( N, strideY ) ); // eslint-disable-line max-len +}); + +/** +* Interchanges two single-precision floating-point vectors using alternative indexing semantics. +* +* @name ndarray +* @memberof Routine.prototype +* @readonly +* @type {Function} +* @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 {Float32Array} y - second input array +* @param {integer} strideY - `y` stride length +* @param {NonNegativeInteger} offsetY - starting `y` index +* @returns {Float32Array} second input array +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* +* // Create a new routine: +* var sswap = new Routine(); +* +* // Initialize the module: +* sswap.initializeSync(); +* +* // Define strided arrays: +* var x = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +* var y = new Float32Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +* +* // Perform operation: +* sswap.ndarray( x.length, x, 1, 0, y, 1, 0 ); +* // x => [ 1.0, 1.0, 1.0, 1.0, 1.0 ] +* // y => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] +*/ +setReadOnly( Routine.prototype, 'ndarray', function sswap( N, x, strideX, offsetX, y, strideY, offsetY ) { + var ptrs; + var p0; + var p1; + + // Convert the input arrays to "pointers" in the module's memory: + ptrs = arrays2ptrs( this, [ + strided2object( N, x, strideX, offsetX ), + strided2object( N, y, strideY, offsetY ) + ]); + p0 = ptrs[ 0 ]; + p1 = ptrs[ 1 ]; + + // Perform computation by calling the corresponding parent method: + Module.prototype.ndarray.call( this, N, p0.ptr, p0.stride, p0.offset, p1.ptr, p1.stride, p1.offset ); // eslint-disable-line max-len + + // If the arrays data had to be copied to module memory, copy the results to the provided corresponding output arrays... + if ( p0.copy ) { + readDataView( N, this.view, p0.stride*p0.BYTES_PER_ELEMENT, p0.ptr, x, strideX, offsetX, true ); // eslint-disable-line max-len + } + if ( p1.copy ) { + readDataView( N, this.view, p1.stride*p1.BYTES_PER_ELEMENT, p1.ptr, y, strideY, offsetY, true ); // eslint-disable-line max-len + } + return y; +}); + + +// EXPORTS // + +module.exports = Routine; diff --git a/lib/node_modules/@stdlib/blas/base/wasm/sswap/manifest.json b/lib/node_modules/@stdlib/blas/base/wasm/sswap/manifest.json new file mode 100644 index 000000000000..a23edb896747 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/wasm/sswap/manifest.json @@ -0,0 +1,36 @@ +{ + "options": {}, + "fields": [ + { + "field": "src", + "resolve": true, + "relative": true + }, + { + "field": "include", + "resolve": true, + "relative": true + }, + { + "field": "libraries", + "resolve": false, + "relative": false + }, + { + "field": "libpath", + "resolve": true, + "relative": false + } + ], + "confs": [ + { + "src": [], + "include": [], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/sswap" + ] + } + ] +} diff --git a/lib/node_modules/@stdlib/blas/base/wasm/sswap/package.json b/lib/node_modules/@stdlib/blas/base/wasm/sswap/package.json new file mode 100644 index 000000000000..b9582075c68c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/wasm/sswap/package.json @@ -0,0 +1,80 @@ +{ + "name": "@stdlib/blas/base/wasm/sswap", + "version": "0.0.0", + "description": "Interchange two single-precision floating-point vectors.", + "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", + "browser": { + "./lib/binary.js": "./lib/binary.browser.js" + }, + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "scripts": "./scripts", + "src": "./src", + "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", + "stdmath", + "mathematics", + "math", + "blas", + "level 1", + "sswap", + "linear", + "algebra", + "subroutines", + "swap", + "vector", + "array", + "ndarray", + "float32", + "single", + "float32array", + "webassembly", + "wasm" + ], + "__stdlib__": { + "wasm": true + } +} diff --git a/lib/node_modules/@stdlib/blas/base/wasm/sswap/scripts/build.js b/lib/node_modules/@stdlib/blas/base/wasm/sswap/scripts/build.js new file mode 100644 index 000000000000..66bf9650b6d6 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/wasm/sswap/scripts/build.js @@ -0,0 +1,66 @@ +#!/usr/bin/env node + +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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' ); +var currentYear = require( '@stdlib/time/current-year' ); + + +// 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}}'; +var YEAR = '{{YEAR}}'; + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var wasm; + var tmpl; + + wasm = readFile( wpath ); + tmpl = readFile( tpath, opts ); + + tmpl = replace( tmpl, YEAR, currentYear().toString() ); + tmpl = replace( tmpl, PLACEHOLDER, wasm.toString( 'base64' ) ); + + writeFile( opath, tmpl, opts ); +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/wasm/sswap/scripts/template.txt b/lib/node_modules/@stdlib/blas/base/wasm/sswap/scripts/template.txt new file mode 100644 index 000000000000..f66cdb9735b1 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/wasm/sswap/scripts/template.txt @@ -0,0 +1,33 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) {{YEAR}} The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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/wasm/sswap/src/Makefile b/lib/node_modules/@stdlib/blas/base/wasm/sswap/src/Makefile new file mode 100644 index 000000000000..1b1f35347760 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/wasm/sswap/src/Makefile @@ -0,0 +1,243 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2025 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +#/ +# To compile targets listed in this Makefile, use top-level project `make` +# commands rather than commands listed in this Makefile. The top-level project +# `make` commands will ensure that various environment variables and flags are +# appropriately set. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files to WebAssembly: +ifdef EMCC_COMPILER + EMCC := $(EMCC_COMPILER) +else + EMCC := emcc +endif + +# Define the program used for compiling WebAssembly files to the WebAssembly text format: +ifdef WASM2WAT + WASM_TO_WAT := $(WASM2WAT) +else + WASM_TO_WAT := wasm2wat +endif + +# Define the program used for compiling WebAssembly files to JavaScript: +ifdef WASM2JS + WASM_TO_JS := $(WASM2JS) +else + WASM_TO_JS := wasm2js +endif + +# Define the path to the Node.js executable: +ifdef NODE + NODEJS := $(NODE) +else + NODEJS := node +endif + +# Define the integer size: +ifdef CBLAS_INT + INT_TYPE := $(CBLAS_INT) +else + INT_TYPE := int32_t +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -flto \ + -Wall \ + -pedantic \ + -D CBLAS_INT=$(INT_TYPE) + +# Define the command-line options when compiling C files to WebAssembly and asm.js: +EMCCFLAGS ?= $(CFLAGS) + +# Define shared `emcc` flags: +EMCC_SHARED_FLAGS := \ + -Oz \ + -fwasm-exceptions \ + -s SUPPORT_LONGJMP=1 \ + -s SIDE_MODULE=2 \ + -s EXPORTED_FUNCTIONS="$(shell cat exports.json | tr -d ' \t\n' | sed s/\"/\'/g)" + +# Define WebAssembly `emcc` flags: +EMCC_WASM_FLAGS := $(EMCC_SHARED_FLAGS) \ + -s WASM=1 \ + -s WASM_BIGINT=0 + +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= + +# List of WebAssembly targets: +wasm_targets := main.wasm + +# List of WebAssembly WAT targets: +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 # + +#/ +# Compiles source files. +# +# @param {string} [EMCC_COMPILER] - EMCC compiler (e.g., `emcc`) +# @param {string} [EMCCFLAGS] - EMCC compiler options +# @param {string} [WASM2WAT] - WebAssembly text format compiler (e.g., `wasm2wat`) +# @param {string} [WASM2JS] - WebAssembly JavaScript compiler (e.g., `wasm2js`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make +# +# @example +# make all +#/ +all: wasm + +.PHONY: all + +#/ +# Compiles source files to WebAssembly. +# +# @param {string} [EMCC_COMPILER] - EMCC compiler (e.g., `emcc`) +# @param {string} [EMCCFLAGS] - EMCC compiler options +# @param {string} [WASM2WAT] - WebAssembly text format compiler (e.g., `wasm2wat`) +# @param {string} [WASM2JS] - WebAssembly JavaScript compiler (e.g., `wasm2js`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make wasm +#/ +wasm: $(wasm_targets) $(wat_targets) $(browser_js_targets) + +.PHONY: wasm + +#/ +# Compiles C source files to WebAssembly binaries. +# +# @private +# @param {string} EMCC - EMCC compiler (e.g., `emcc`) +# @param {string} EMCCFLAGS - EMCC compiler options +# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) +# @param {string} SOURCE_FILES - list of source files +# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) +# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) +#/ +$(wasm_targets): + $(QUIET) $(EMCC) $(EMCCFLAGS) $(EMCC_WASM_FLAGS) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) $(LIBRARIES) + +#/ +# Compiles WebAssembly binary files to the WebAssembly text format. +# +# @private +# @param {string} WASM2WAT - WAT compiler (e.g., `wasm2wat`) +#/ +$(wat_targets): %.wat: %.wasm + $(QUIET) $(WASM_TO_WAT) -o $@ $(wasm_targets) + +#/ +# Compiles WebAssembly binary files to JavaScript. +# +# @private +# @param {string} WASM2JS - JavaScript compiler (e.g., `wasm2js`) +#/ +$(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. +# +# @example +# make clean-wasm +#/ +clean-wasm: + $(QUIET) -rm -f *.wasm *.wat *.wasm.js $(browser_js_targets) + +.PHONY: clean-wasm + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: clean-wasm + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/blas/base/wasm/sswap/src/exports.json b/lib/node_modules/@stdlib/blas/base/wasm/sswap/src/exports.json new file mode 100644 index 000000000000..fd3bf8bb3f5f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/wasm/sswap/src/exports.json @@ -0,0 +1,4 @@ +[ + "_c_sswap", + "_c_sswap_ndarray" +] diff --git a/lib/node_modules/@stdlib/blas/base/wasm/sswap/src/main.wasm b/lib/node_modules/@stdlib/blas/base/wasm/sswap/src/main.wasm new file mode 100755 index 000000000000..fbc6ebe14376 Binary files /dev/null and b/lib/node_modules/@stdlib/blas/base/wasm/sswap/src/main.wasm differ diff --git a/lib/node_modules/@stdlib/blas/base/wasm/sswap/src/main.wat b/lib/node_modules/@stdlib/blas/base/wasm/sswap/src/main.wat new file mode 100644 index 000000000000..47173ba5b056 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/wasm/sswap/src/main.wat @@ -0,0 +1,223 @@ +;; @license Apache-2.0 +;; +;; Copyright (c) 2025 The Stdlib Authors. +;; +;; Licensed under the Apache License, Version 2.0 (the "License"); +;; you may not use this file except in compliance with the License. +;; You may obtain a copy of the License at +;; +;; http://www.apache.org/licenses/LICENSE-2.0 +;; +;; Unless required by applicable law or agreed to in writing, software +;; distributed under the License is distributed on an "AS IS" BASIS, +;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +;; See the License for the specific language governing permissions and +;; limitations under the License. + +(module + (type (;0;) (func)) + (type (;1;) (func (param i32 i32 i32 i32 i32))) + (type (;2;) (func (param i32 i32 i32 i32 i32 i32 i32))) + (import "env" "memory" (memory (;0;) 0)) + (func (;0;) (type 0) + nop) + (func (;1;) (type 1) (param i32 i32 i32 i32 i32) + local.get 0 + local.get 1 + local.get 2 + i32.const 1 + local.get 0 + i32.sub + local.tee 0 + local.get 2 + i32.mul + i32.const 0 + local.get 2 + i32.const 0 + i32.le_s + select + local.get 3 + local.get 4 + local.get 0 + local.get 4 + i32.mul + i32.const 0 + local.get 4 + i32.const 0 + i32.le_s + select + call 2) + (func (;2;) (type 2) (param i32 i32 i32 i32 i32 i32 i32) + (local f32 i32 i32) + block ;; label = @1 + local.get 0 + i32.const 0 + i32.le_s + br_if 0 (;@1;) + local.get 2 + i32.const 1 + i32.ne + local.get 5 + i32.const 1 + i32.ne + i32.or + i32.eqz + if ;; label = @2 + local.get 0 + i32.const 3 + i32.rem_u + local.tee 8 + if ;; label = @3 + i32.const 0 + local.set 2 + loop ;; label = @4 + local.get 2 + local.get 8 + i32.eq + i32.eqz + if ;; label = @5 + local.get 1 + local.get 3 + i32.const 2 + i32.shl + i32.add + local.tee 5 + f32.load + local.set 7 + local.get 5 + local.get 4 + local.get 6 + i32.const 2 + i32.shl + i32.add + local.tee 5 + f32.load + f32.store + local.get 5 + local.get 7 + f32.store + local.get 2 + i32.const 1 + i32.add + local.set 2 + local.get 6 + i32.const 1 + i32.add + local.set 6 + local.get 3 + i32.const 1 + i32.add + local.set 3 + br 1 (;@4;) + end + end + local.get 0 + i32.const 3 + i32.lt_s + br_if 2 (;@1;) + end + loop ;; label = @3 + local.get 0 + local.get 8 + i32.le_s + br_if 2 (;@1;) + local.get 1 + local.get 3 + i32.const 2 + i32.shl + i32.add + local.tee 2 + f32.load + local.set 7 + local.get 2 + local.get 4 + local.get 6 + i32.const 2 + i32.shl + i32.add + local.tee 5 + f32.load + f32.store + local.get 5 + local.get 7 + f32.store + local.get 2 + f32.load offset=4 + local.set 7 + local.get 2 + local.get 5 + f32.load offset=4 + f32.store offset=4 + local.get 5 + local.get 7 + f32.store offset=4 + local.get 2 + f32.load offset=8 + local.set 7 + local.get 2 + local.get 5 + f32.load offset=8 + f32.store offset=8 + local.get 5 + local.get 7 + f32.store offset=8 + local.get 8 + i32.const 3 + i32.add + local.set 8 + local.get 6 + i32.const 3 + i32.add + local.set 6 + local.get 3 + i32.const 3 + i32.add + local.set 3 + br 0 (;@3;) + end + unreachable + end + loop ;; label = @2 + local.get 0 + local.get 8 + i32.eq + br_if 1 (;@1;) + local.get 1 + local.get 3 + i32.const 2 + i32.shl + i32.add + local.tee 9 + f32.load + local.set 7 + local.get 9 + local.get 4 + local.get 6 + i32.const 2 + i32.shl + i32.add + local.tee 9 + f32.load + f32.store + local.get 9 + local.get 7 + f32.store + local.get 8 + i32.const 1 + i32.add + local.set 8 + local.get 5 + local.get 6 + i32.add + local.set 6 + local.get 2 + local.get 3 + i32.add + local.set 3 + br 0 (;@2;) + end + unreachable + end) + (export "__wasm_call_ctors" (func 0)) + (export "c_sswap" (func 1)) + (export "c_sswap_ndarray" (func 2))) diff --git a/lib/node_modules/@stdlib/blas/base/wasm/sswap/test/test.js b/lib/node_modules/@stdlib/blas/base/wasm/sswap/test/test.js new file mode 100644 index 000000000000..45a1efa95f72 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/wasm/sswap/test/test.js @@ -0,0 +1,53 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 sswap = require( './../lib' ); + + +// TESTS // + +tape( 'main export is an object', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof sswap, 'object', 'returns expected value' ); + t.end(); +}); + +tape( 'attached to the main export is a `main` method', function test( t ) { + t.strictEqual( typeof sswap.main, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'attached to the main export is an `ndarray` method', function test( t ) { + t.strictEqual( typeof sswap.ndarray, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'attached to the main export is a `Module` constructor', function test( t ) { + t.strictEqual( typeof sswap.Module, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'the main export is a `Module` instance', function test( t ) { + t.strictEqual( sswap instanceof sswap.Module, true, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/wasm/sswap/test/test.main.js b/lib/node_modules/@stdlib/blas/base/wasm/sswap/test/test.main.js new file mode 100644 index 000000000000..f6c08bd8e0f9 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/wasm/sswap/test/test.main.js @@ -0,0 +1,282 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 Float32Array = require( '@stdlib/array/float32' ); +var sswap = require( './../lib' ); + + +// TESTS // + +tape( 'main export is an object', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof sswap, 'object', 'main export is an object' ); + t.end(); +}); + +tape( 'the `main` method has an arity of 5', function test( t ) { + t.strictEqual( sswap.main.length, 5, 'returns expected value' ); + t.end(); +}); + +tape( 'the `main` method interchanges vectors `x` and `y`', function test( t ) { + var xe; + var ye; + var x; + var y; + + x = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + y = new Float32Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ); + + sswap.main( x.length, x, 1, y, 1 ); + + xe = new Float32Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ); + ye = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + + t.deepEqual( x, xe, 'returns expected value' ); + t.deepEqual( y, ye, 'returns expected value' ); + + // Short datasets: + x = new Float32Array( [ 1.0, 2.0 ] ); + y = new Float32Array( [ 1.0, 1.0 ] ); + + sswap.main( x.length, x, 1, y, 1 ); + + xe = new Float32Array( [ 1.0, 1.0 ] ); + ye = new Float32Array( [ 1.0, 2.0 ] ); + + t.deepEqual( x, xe, 'returns expected value' ); + t.deepEqual( y, ye, 'returns expected value' ); + + t.end(); +}); + +tape( 'the `main` method supports an `x` stride', function test( t ) { + var xe; + var ye; + var x; + var y; + var N; + + x = new Float32Array([ + 1.0, // 0 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 2 + ]); + y = new Float32Array([ + 1.0, // 0 + 1.0, // 1 + 1.0, // 2 + 1.0, + 1.0 + ]); + N = 3; + + sswap.main( N, x, 2, y, 1 ); + + xe = new Float32Array( [ 1.0, 2.0, 1.0, 4.0, 1.0 ] ); + ye = new Float32Array( [ 1.0, 3.0, 5.0, 1.0, 1.0 ] ); + + t.deepEqual( x, xe, 'returns expected value' ); + t.deepEqual( y, ye, 'returns expected value' ); + t.end(); +}); + +tape( 'the `main` method supports a `y` stride', function test( t ) { + var xe; + var ye; + var x; + var y; + var N; + + x = new Float32Array([ + 1.0, // 0 + 2.0, // 1 + 3.0, // 2 + 4.0, + 5.0 + ]); + y = new Float32Array([ + 1.0, // 0 + 1.0, + 1.0, // 1 + 1.0, + 1.0 // 2 + ]); + N = 3; + + sswap.main( N, x, 1, y, 2 ); + + xe = new Float32Array( [ 1.0, 1.0, 1.0, 4.0, 5.0 ] ); + ye = new Float32Array( [ 1.0, 1.0, 2.0, 1.0, 3.0 ] ); + + t.deepEqual( x, xe, 'returns expected value' ); + t.deepEqual( y, ye, 'returns expected value' ); + t.end(); +}); + +tape( 'the `main` method returns a reference to the second input array', function test( t ) { + var out; + var x; + var y; + + x = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + y = new Float32Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); + + out = sswap.main( x.length, 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 vectors unchanged', function test( t ) { + var xe; + var ye; + var x; + var y; + + x = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + y = new Float32Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); + + xe = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + ye = new Float32Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); + + sswap.main( -1, x, 1, y, 1 ); + t.deepEqual( x, xe, 'returns expected value' ); + t.deepEqual( y, ye, 'returns expected value' ); + + sswap.main( 0, x, 1, y, 1 ); + t.deepEqual( x, xe, 'returns expected value' ); + t.deepEqual( y, ye, 'returns expected value' ); + + t.end(); +}); + +tape( 'the `main` method supports negative strides', function test( t ) { + var xe; + var ye; + var x; + var y; + var N; + + x = new Float32Array([ + 1.0, // 2 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 0 + ]); + y = new Float32Array([ + 6.0, // 2 + 7.0, // 1 + 8.0, // 0 + 9.0, + 10.0 + ]); + N = 3; + + sswap.main( N, x, -2, y, -1 ); + + xe = new Float32Array( [ 6.0, 2.0, 7.0, 4.0, 8.0 ] ); + ye = new Float32Array( [ 1.0, 3.0, 5.0, 9.0, 10.0 ] ); + + t.deepEqual( x, xe, 'returns expected value' ); + t.deepEqual( y, ye, 'returns expected value' ); + t.end(); +}); + +tape( 'the `main` method supports complex access patterns', function test( t ) { + var xe; + var ye; + var x; + var y; + var N; + + x = new Float32Array([ + 1.0, // 0 + 2.0, + 3.0, // 1 + 4.0, + 5.0, // 2 + 6.0 + ]); + y = new Float32Array([ + 7.0, // 2 + 8.0, // 1 + 9.0, // 0 + 10.0, + 11.0, + 12.0 + ]); + N = 3; + + sswap.main( N, x, 2, y, -1 ); + + xe = new Float32Array( [ 9.0, 2.0, 8.0, 4.0, 7.0, 6.0 ] ); + ye = new Float32Array( [ 5.0, 3.0, 1.0, 10.0, 11.0, 12.0 ] ); + + t.deepEqual( x, xe, 'returns expected value' ); + t.deepEqual( y, ye, 'returns expected value' ); + t.end(); +}); + +tape( 'the `main` method supports view offsets', function test( t ) { + var x0; + var y0; + var x1; + var y1; + var xe; + var ye; + + // Initial arrays... + x0 = new Float32Array([ + 1.0, + 2.0, // 2 + 3.0, + 4.0, // 1 + 5.0, + 6.0 // 0 + ]); + y0 = new Float32Array([ + 7.0, + 8.0, + 9.0, + 10.0, // 0 + 11.0, // 1 + 12.0 // 2 + ]); + + // Create offset views... + x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // begin at 2nd element + y1 = new Float32Array( y0.buffer, y0.BYTES_PER_ELEMENT*3 ); // begin at 4th element + + sswap.main( 3, x1, -2, y1, 1 ); + + xe = new Float32Array( [ 1.0, 12.0, 3.0, 11.0, 5.0, 10.0 ] ); + ye = new Float32Array( [ 7.0, 8.0, 9.0, 6.0, 4.0, 2.0 ] ); + + t.deepEqual( x0, xe, 'returns expected value' ); + t.deepEqual( y0, ye, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/wasm/sswap/test/test.module.js b/lib/node_modules/@stdlib/blas/base/wasm/sswap/test/test.module.js new file mode 100644 index 000000000000..0cdcd97ef151 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/wasm/sswap/test/test.module.js @@ -0,0 +1,154 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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/wasm/sswap/test/test.module.main.js b/lib/node_modules/@stdlib/blas/base/wasm/sswap/test/test.module.main.js new file mode 100644 index 000000000000..29171be97751 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/wasm/sswap/test/test.module.main.js @@ -0,0 +1,398 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 Float32Array = require( '@stdlib/array/float32' ); +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 5', function test( t ) { + var mem; + var mod; + + mem = new Memory({ + 'initial': 0 + }); + mod = new Module( mem ); + t.strictEqual( mod.main.length, 5, 'returns expected value' ); + t.end(); +}); + +tape( 'a module instance has a `main` method which interchanges vectors `x` and `y`', function test( t ) { + var actualX; + var actualY; + var mem; + var mod; + var xe; + var ye; + var xp; + var yp; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + yp = 40; + + mod.write( xp, new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ) ); + mod.write( yp, new Float32Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ) ); + + xe = new Float32Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ); + ye = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + + mod.main( 5, xp, 1, yp, 1 ); + + actualX = new Float32Array( 5 ); + mod.read( xp, actualX ); + + actualY = new Float32Array( 5 ); + mod.read( yp, actualY ); + + t.deepEqual( actualX, xe, 'returns expected value' ); + t.deepEqual( actualY, ye, 'returns expected value' ); + + // Short datasets: + xp = 0; + yp = 16; + + mod.write( xp, new Float32Array( [ 1.0, 2.0 ] ) ); + mod.write( yp, new Float32Array( [ 1.0, 1.0 ] ) ); + + mod.main( 2, xp, 1, yp, 1 ); + + xe = new Float32Array( [ 1.0, 1.0 ] ); + ye = new Float32Array( [ 1.0, 2.0 ] ); + + actualX = new Float32Array( 2 ); + mod.read( xp, actualX ); + + actualY = new Float32Array( 2 ); + mod.read( yp, actualY ); + + t.deepEqual( actualX, xe, 'returns expected value' ); + t.deepEqual( actualY, ye, 'returns expected value' ); + + t.end(); +}); + +tape( 'a module instance has a `main` method which supports an `x` stride', function test( t ) { + var actualX; + var actualY; + var mem; + var mod; + var xe; + var ye; + 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 Float32Array([ + 1.0, // 0 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 2 + ])); + mod.write( yp, new Float32Array([ + 1.0, // 0 + 1.0, // 1 + 1.0, // 2 + 1.0, + 1.0 + ])); + N = 3; + + mod.main( N, xp, 2, yp, 1 ); + + xe = new Float32Array( [ 1.0, 2.0, 1.0, 4.0, 1.0 ] ); + ye = new Float32Array( [ 1.0, 3.0, 5.0, 1.0, 1.0 ] ); + + actualX = new Float32Array( 5 ); + mod.read( xp, actualX ); + + actualY = new Float32Array( 5 ); + mod.read( yp, actualY ); + + t.deepEqual( actualX, xe, 'returns expected value' ); + t.deepEqual( actualY, ye, 'returns expected value' ); + + t.end(); +}); + +tape( 'a module instance has a `main` method which supports a `y` stride', function test( t ) { + var actualX; + var actualY; + var mem; + var mod; + var xe; + var ye; + 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 Float32Array([ + 1.0, // 0 + 2.0, // 1 + 3.0, // 2 + 4.0, + 5.0 + ])); + mod.write( yp, new Float32Array([ + 1.0, // 0 + 1.0, + 1.0, // 1 + 1.0, + 1.0 // 2 + ])); + N = 3; + + mod.main( N, xp, 1, yp, 2 ); + + xe = new Float32Array( [ 1.0, 1.0, 1.0, 4.0, 5.0 ] ); + ye = new Float32Array( [ 1.0, 1.0, 2.0, 1.0, 3.0 ] ); + + actualX = new Float32Array( 5 ); + mod.read( xp, actualX ); + + actualY = new Float32Array( 5 ); + mod.read( yp, actualY ); + + t.deepEqual( actualX, xe, 'returns expected value' ); + t.deepEqual( actualY, ye, 'returns expected value' ); + + t.end(); +}); + +tape( 'a module instance has a `main` method which returns a pointer to the second input 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 Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ) ); + mod.write( yp, new Float32Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ) ); + + out = mod.main( 5, 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 vectors unchanged', function test( t ) { + var actualX; + var actualY; + var mem; + var mod; + var xe; + var ye; + var xp; + var yp; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + yp = 40; + + mod.write( xp, new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ) ); + mod.write( yp, new Float32Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ) ); + + xe = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + ye = new Float32Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); + + mod.main( -1, xp, 1, yp, 1 ); + + actualX = new Float32Array( 5 ); + mod.read( xp, actualX ); + + actualY = new Float32Array( 5 ); + mod.read( yp, actualY ); + + t.deepEqual( actualX, xe, 'returns expected value' ); + t.deepEqual( actualY, ye, 'returns expected value' ); + + mod.main( 0, xp, 1, yp, 1 ); + + actualX = new Float32Array( 5 ); + mod.read( xp, actualX ); + + actualY = new Float32Array( 5 ); + mod.read( yp, actualY ); + + t.deepEqual( actualX, xe, 'returns expected value' ); + t.deepEqual( actualY, ye, 'returns expected value' ); + + t.end(); +}); + +tape( 'a module instance has a `main` method which supports negative strides', function test( t ) { + var actualX; + var actualY; + var mem; + var mod; + var xe; + var ye; + 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 Float32Array([ + 1.0, // 2 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 0 + ])); + mod.write( yp, new Float32Array([ + 6.0, // 2 + 7.0, // 1 + 8.0, // 0 + 9.0, + 10.0 + ])); + N = 3; + + mod.main( N, xp, -2, yp, -1 ); + + xe = new Float32Array( [ 6.0, 2.0, 7.0, 4.0, 8.0 ] ); + ye = new Float32Array( [ 1.0, 3.0, 5.0, 9.0, 10.0 ] ); + + actualX = new Float32Array( 5 ); + mod.read( xp, actualX ); + + actualY = new Float32Array( 5 ); + mod.read( yp, actualY ); + + t.deepEqual( actualX, xe, 'returns expected value' ); + t.deepEqual( actualY, ye, 'returns expected value' ); + + t.end(); +}); + +tape( 'a module instance has a `main` method which supports complex access patterns', function test( t ) { + var actualX; + var actualY; + var mem; + var mod; + var xe; + var ye; + 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 Float32Array([ + 1.0, // 0 + 2.0, + 3.0, // 1 + 4.0, + 5.0, // 2 + 6.0 + ])); + mod.write( 48, new Float32Array([ + 7.0, // 2 + 8.0, // 1 + 9.0, // 0 + 10.0, + 11.0, + 12.0 + ])); + N = 3; + + mod.main( N, xp, 2, yp, -1 ); + + xe = new Float32Array( [ 9.0, 2.0, 8.0, 4.0, 7.0, 6.0 ] ); + ye = new Float32Array( [ 5.0, 3.0, 1.0, 10.0, 11.0, 12.0 ] ); + + actualX = new Float32Array( 6 ); + mod.read( xp, actualX ); + + actualY = new Float32Array( 6 ); + mod.read( yp, actualY ); + + t.deepEqual( actualX, xe, 'returns expected value' ); + t.deepEqual( actualY, ye, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/wasm/sswap/test/test.module.ndarray.js b/lib/node_modules/@stdlib/blas/base/wasm/sswap/test/test.module.ndarray.js new file mode 100644 index 000000000000..8ab8cc9c8790 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/wasm/sswap/test/test.module.ndarray.js @@ -0,0 +1,504 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 Float32Array = require( '@stdlib/array/float32' ); +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 7', function test( t ) { + var mem; + var mod; + + mem = new Memory({ + 'initial': 0 + }); + mod = new Module( mem ); + t.strictEqual( mod.ndarray.length, 7, 'returns expected value' ); + t.end(); +}); + +tape( 'a module instance has an `ndarray` method which interchanges vectors `x` and `y`', function test( t ) { + var actualX; + var actualY; + var mem; + var mod; + var xe; + var xp; + var ye; + var yp; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + yp = 40; + + mod.write( xp, new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ) ); + mod.write( yp, new Float32Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ) ); + + mod.ndarray( 5, xp, 1, 0, yp, 1, 0 ); + + xe = new Float32Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ); + ye = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + + actualX = new Float32Array( 5 ); + mod.read( xp, actualX ); + + actualY = new Float32Array( 5 ); + mod.read( yp, actualY ); + + t.deepEqual( actualX, xe, 'returns expected value' ); + t.deepEqual( actualY, ye, 'returns expected value' ); + + // Short datasets: + xp = 0; + yp = 16; + + mod.write( xp, new Float32Array( [ 1.0, 2.0 ] ) ); + mod.write( yp, new Float32Array( [ 1.0, 1.0 ] ) ); + + mod.ndarray( 2, xp, 1, 0, yp, 1, 0 ); + + xe = new Float32Array( [ 1.0, 1.0 ] ); + ye = new Float32Array( [ 1.0, 2.0 ] ); + + actualX = new Float32Array( 2 ); + mod.read( xp, actualX ); + + actualY = new Float32Array( 2 ); + mod.read( yp, actualY ); + + t.deepEqual( actualX, xe, 'returns expected value' ); + t.deepEqual( actualY, ye, 'returns expected value' ); + + t.end(); +}); + +tape( 'a module instance has an `ndarray` method which supports an `x` stride', function test( t ) { + var actualX; + var actualY; + var mem; + var mod; + var xe; + var xp; + var ye; + var yp; + var N; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + yp = 40; + + mod.write( xp, new Float32Array([ + 1.0, // 0 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 2 + ])); + mod.write( yp, new Float32Array([ + 1.0, // 0 + 1.0, // 1 + 1.0, // 2 + 1.0, + 1.0 + ])); + N = 3; + + mod.ndarray( N, xp, 2, 0, yp, 1, 0 ); + + xe = new Float32Array( [ 1.0, 2.0, 1.0, 4.0, 1.0 ] ); + ye = new Float32Array( [ 1.0, 3.0, 5.0, 1.0, 1.0 ] ); + + actualX = new Float32Array( 5 ); + mod.read( xp, actualX ); + + actualY = new Float32Array( 5 ); + mod.read( yp, actualY ); + + t.deepEqual( actualX, xe, 'returns expected value' ); + t.deepEqual( actualY, ye, 'returns expected value' ); + + t.end(); +}); + +tape( 'a module instance has an `ndarray` method which supports an `x` offset', function test( t ) { + var actualX; + var actualY; + var mem; + var mod; + var xe; + var xp; + var ye; + var yp; + var N; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + yp = 40; + + mod.write( xp, new Float32Array([ + 1.0, + 2.0, + 3.0, // 0 + 4.0, // 1 + 5.0 // 2 + ])); + mod.write( yp, new Float32Array([ + 6.0, // 0 + 7.0, // 1 + 8.0, // 2 + 9.0, + 10.0 + ])); + N = 3; + + mod.ndarray( N, xp, 1, 2, yp, 1, 0 ); + + xe = new Float32Array( [ 1.0, 2.0, 6.0, 7.0, 8.0 ] ); + ye = new Float32Array( [ 3.0, 4.0, 5.0, 9.0, 10.0 ] ); + + actualX = new Float32Array( 5 ); + mod.read( xp, actualX ); + + actualY = new Float32Array( 5 ); + mod.read( yp, actualY ); + + t.deepEqual( actualX, xe, 'returns expected value' ); + t.deepEqual( actualY, ye, 'returns expected value' ); + + t.end(); +}); + +tape( 'a module instance has an `ndarray` method which supports a `y` stride', function test( t ) { + var actualX; + var actualY; + var mem; + var mod; + var xe; + var xp; + var ye; + var yp; + var N; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + yp = 40; + + mod.write( xp, new Float32Array([ + 1.0, // 0 + 2.0, // 1 + 3.0, // 2 + 4.0, + 5.0 + ])); + mod.write( yp, new Float32Array([ + 1.0, // 0 + 1.0, + 1.0, // 1 + 1.0, + 1.0 // 2 + ])); + N = 3; + + mod.ndarray( N, xp, 1, 0, yp, 2, 0 ); + + xe = new Float32Array( [ 1.0, 1.0, 1.0, 4.0, 5.0 ] ); + ye = new Float32Array( [ 1.0, 1.0, 2.0, 1.0, 3.0 ] ); + + actualX = new Float32Array( 5 ); + mod.read( xp, actualX ); + + actualY = new Float32Array( 5 ); + mod.read( yp, actualY ); + + t.deepEqual( actualX, xe, 'returns expected value' ); + t.deepEqual( actualY, ye, 'returns expected value' ); + + t.end(); +}); + +tape( 'a module instance has an `ndarray` method which supports a `y` offset', function test( t ) { + var actualX; + var actualY; + var mem; + var mod; + var xe; + var xp; + var ye; + var yp; + var N; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + yp = 40; + + mod.write( xp, new Float32Array([ + 1.0, // 0 + 2.0, // 1 + 3.0, // 2 + 4.0, + 5.0 + ])); + mod.write( yp, new Float32Array([ + 6.0, + 7.0, + 8.0, // 0 + 9.0, // 1 + 10.0 // 2 + ])); + N = 3; + + mod.ndarray( N, xp, 1, 0, yp, 1, 2 ); + + xe = new Float32Array( [ 8.0, 9.0, 10.0, 4.0, 5.0 ] ); + ye = new Float32Array( [ 6.0, 7.0, 1.0, 2.0, 3.0 ] ); + + actualX = new Float32Array( 5 ); + mod.read( xp, actualX ); + + actualY = new Float32Array( 5 ); + mod.read( yp, actualY ); + + t.deepEqual( actualX, xe, 'returns expected value' ); + t.deepEqual( actualY, ye, 'returns expected value' ); + + t.end(); +}); + +tape( 'a module instance has an `ndarray` method which returns a pointer to the second input 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 Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ) ); + mod.write( yp, new Float32Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ) ); + + out = mod.ndarray( 5, 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 vectors unchanged', function test( t ) { + var actualX; + var actualY; + var mem; + var mod; + var xe; + var xp; + var ye; + var yp; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + yp = 40; + + mod.write( xp, new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ) ); + mod.write( yp, new Float32Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ) ); + + mod.ndarray( -1, xp, 1, 0, yp, 1, 0 ); + + xe = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + ye = new Float32Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); + + actualX = new Float32Array( 5 ); + mod.read( xp, actualX ); + + actualY = new Float32Array( 5 ); + mod.read( yp, actualY ); + + t.deepEqual( actualX, xe, 'returns expected value' ); + t.deepEqual( actualY, ye, 'returns expected value' ); + + mod.ndarray( 0, xp, 1, 0, yp, 1, 0 ); + + actualX = new Float32Array( 5 ); + mod.read( xp, actualX ); + + actualY = new Float32Array( 5 ); + mod.read( yp, actualY ); + + t.deepEqual( actualX, xe, 'returns expected value' ); + t.deepEqual( actualY, ye, 'returns expected value' ); + + t.end(); +}); + +tape( 'a module instance has an `ndarray` method which supports negative strides', function test( t ) { + var actualX; + var actualY; + var mem; + var mod; + var xe; + var xp; + var ye; + var yp; + var N; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + yp = 40; + + mod.write( xp, new Float32Array([ + 1.0, // 2 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 0 + ])); + mod.write( yp, new Float32Array([ + 6.0, // 2 + 7.0, // 1 + 8.0, // 0 + 9.0, + 10.0 + ])); + N = 3; + + mod.ndarray( N, xp, -2, 4, yp, -1, 2 ); + + xe = new Float32Array( [ 6.0, 2.0, 7.0, 4.0, 8.0 ] ); + ye = new Float32Array( [ 1.0, 3.0, 5.0, 9.0, 10.0 ] ); + + actualX = new Float32Array( 5 ); + mod.read( xp, actualX ); + + actualY = new Float32Array( 5 ); + mod.read( yp, actualY ); + + t.deepEqual( actualX, xe, 'returns expected value' ); + t.deepEqual( actualY, ye, 'returns expected value' ); + + t.end(); +}); + +tape( 'a module instance has an `ndarray` method which supports complex access patterns', function test( t ) { + var actualX; + var actualY; + var mem; + var mod; + var xe; + var xp; + var ye; + var yp; + var N; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + yp = 48; + + mod.write( xp, new Float32Array([ + 1.0, // 0 + 2.0, + 3.0, // 1 + 4.0, + 5.0, // 2 + 6.0 + ])); + mod.write( yp, new Float32Array([ + 7.0, // 2 + 8.0, // 1 + 9.0, // 0 + 10.0, + 11.0, + 12.0 + ])); + N = 3; + + mod.ndarray( N, xp, 2, 0, yp, -1, 2 ); + + xe = new Float32Array( [ 9.0, 2.0, 8.0, 4.0, 7.0, 6.0 ] ); + ye = new Float32Array( [ 5.0, 3.0, 1.0, 10.0, 11.0, 12.0 ] ); + + actualX = new Float32Array( 6 ); + mod.read( xp, actualX ); + + actualY = new Float32Array( 6 ); + mod.read( yp, actualY ); + + t.deepEqual( actualX, xe, 'returns expected value' ); + t.deepEqual( actualY, ye, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/wasm/sswap/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/base/wasm/sswap/test/test.ndarray.js new file mode 100644 index 000000000000..7b9769fd37b2 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/wasm/sswap/test/test.ndarray.js @@ -0,0 +1,308 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 Float32Array = require( '@stdlib/array/float32' ); +var sswap = require( './../lib' ); + + +// TESTS // + +tape( 'main export is an object', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof sswap, 'object', 'main export is an object' ); + t.end(); +}); + +tape( 'the `ndarray` method has an arity of 7', function test( t ) { + t.strictEqual( sswap.ndarray.length, 7, 'returns expected value' ); + t.end(); +}); + +tape( 'the `ndarray` method interchanges vectors `x` and `y`', function test( t ) { + var xe; + var ye; + var x; + var y; + + x = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + y = new Float32Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ); + + sswap.ndarray( x.length, x, 1, 0, y, 1, 0 ); + + xe = new Float32Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ); + ye = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + + t.deepEqual( x, xe, 'returns expected value' ); + t.deepEqual( y, ye, 'returns expected value' ); + + // Short datasets: + x = new Float32Array( [ 1.0, 2.0 ] ); + y = new Float32Array( [ 1.0, 1.0 ] ); + + sswap.ndarray( x.length, x, 1, 0, y, 1, 0 ); + + xe = new Float32Array( [ 1.0, 1.0 ] ); + ye = new Float32Array( [ 1.0, 2.0 ] ); + + t.deepEqual( x, xe, 'returns expected value' ); + t.deepEqual( y, ye, 'returns expected value' ); + + t.end(); +}); + +tape( 'the `ndarray` method supports an `x` stride', function test( t ) { + var xe; + var ye; + var x; + var y; + var N; + + x = new Float32Array([ + 1.0, // 0 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 2 + ]); + y = new Float32Array([ + 1.0, // 0 + 1.0, // 1 + 1.0, // 2 + 1.0, + 1.0 + ]); + N = 3; + + sswap.ndarray( N, x, 2, 0, y, 1, 0 ); + + xe = new Float32Array( [ 1.0, 2.0, 1.0, 4.0, 1.0 ] ); + ye = new Float32Array( [ 1.0, 3.0, 5.0, 1.0, 1.0 ] ); + + t.deepEqual( x, xe, 'returns expected value' ); + t.deepEqual( y, ye, 'returns expected value' ); + t.end(); +}); + +tape( 'the `ndarray` method supports an `x` offset', function test( t ) { + var xe; + var ye; + var x; + var y; + var N; + + x = new Float32Array([ + 1.0, + 2.0, + 3.0, // 0 + 4.0, // 1 + 5.0 // 2 + ]); + y = new Float32Array([ + 6.0, // 0 + 7.0, // 1 + 8.0, // 2 + 9.0, + 10.0 + ]); + N = 3; + + sswap.ndarray( N, x, 1, 2, y, 1, 0 ); + + xe = new Float32Array( [ 1.0, 2.0, 6.0, 7.0, 8.0 ] ); + ye = new Float32Array( [ 3.0, 4.0, 5.0, 9.0, 10.0 ] ); + + t.deepEqual( x, xe, 'returns expected value' ); + t.deepEqual( y, ye, 'returns expected value' ); + t.end(); +}); + +tape( 'the `ndarray` method supports a `y` stride', function test( t ) { + var xe; + var ye; + var x; + var y; + var N; + + x = new Float32Array([ + 1.0, // 0 + 2.0, // 1 + 3.0, // 2 + 4.0, + 5.0 + ]); + y = new Float32Array([ + 1.0, // 0 + 1.0, + 1.0, // 1 + 1.0, + 1.0 // 2 + ]); + N = 3; + + sswap.ndarray( N, x, 1, 0, y, 2, 0 ); + + xe = new Float32Array( [ 1.0, 1.0, 1.0, 4.0, 5.0 ] ); + ye = new Float32Array( [ 1.0, 1.0, 2.0, 1.0, 3.0 ] ); + + t.deepEqual( x, xe, 'returns expected value' ); + t.deepEqual( y, ye, 'returns expected value' ); + t.end(); +}); + +tape( 'the `ndarray` method supports a `y` offset', function test( t ) { + var xe; + var ye; + var x; + var y; + var N; + + x = new Float32Array([ + 1.0, // 0 + 2.0, // 1 + 3.0, // 2 + 4.0, + 5.0 + ]); + y = new Float32Array([ + 6.0, + 7.0, + 8.0, // 0 + 9.0, // 1 + 10.0 // 2 + ]); + N = 3; + + sswap.ndarray( N, x, 1, 0, y, 1, 2 ); + + xe = new Float32Array( [ 8.0, 9.0, 10.0, 4.0, 5.0 ] ); + ye = new Float32Array( [ 6.0, 7.0, 1.0, 2.0, 3.0 ] ); + + t.deepEqual( x, xe, 'returns expected value' ); + t.deepEqual( y, ye, 'returns expected value' ); + t.end(); +}); + +tape( 'the `ndarray` method returns a reference to the second input array', function test( t ) { + var out; + var x; + var y; + + x = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + y = new Float32Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); + + out = sswap.ndarray( x.length, 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 vectors unchanged', function test( t ) { + var xe; + var ye; + var x; + var y; + + x = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + y = new Float32Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); + + xe = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + ye = new Float32Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); + + sswap.ndarray( -1, x, 1, 0, y, 1, 0 ); + t.deepEqual( x, xe, 'returns expected value' ); + t.deepEqual( y, ye, 'returns expected value' ); + + sswap.ndarray( 0, x, 1, 0, y, 1, 0 ); + t.deepEqual( x, xe, 'returns expected value' ); + t.deepEqual( y, ye, 'returns expected value' ); + + t.end(); +}); + +tape( 'the `ndarray` method supports negative strides', function test( t ) { + var xe; + var ye; + var x; + var y; + var N; + + x = new Float32Array([ + 1.0, // 2 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 0 + ]); + y = new Float32Array([ + 6.0, + 7.0, // 2 + 8.0, // 1 + 9.0, // 0 + 10.0 + ]); + N = 3; + + sswap.ndarray( N, x, -2, x.length-1, y, -1, y.length-2 ); + + xe = new Float32Array( [ 7.0, 2.0, 8.0, 4.0, 9.0 ] ); + ye = new Float32Array( [ 6.0, 1.0, 3.0, 5.0, 10.0 ] ); + + t.deepEqual( x, xe, 'returns expected value' ); + t.deepEqual( y, ye, 'returns expected value' ); + t.end(); +}); + +tape( 'the `ndarray` method supports complex access patterns', function test( t ) { + var xe; + var ye; + var x; + var y; + var N; + + x = new Float32Array([ + 1.0, + 2.0, // 0 + 3.0, + 4.0, // 1 + 5.0, + 6.0 // 2 + ]); + y = new Float32Array([ + 7.0, + 8.0, + 9.0, + 10.0, // 2 + 11.0, // 1 + 12.0 // 0 + ]); + N = 3; + + sswap.ndarray( N, x, 2, 1, y, -1, y.length-1 ); + + xe = new Float32Array( [ 1.0, 12.0, 3.0, 11.0, 5.0, 10.0 ] ); + ye = new Float32Array( [ 7.0, 8.0, 9.0, 6.0, 4.0, 2.0 ] ); + + t.deepEqual( x, xe, 'returns expected value' ); + t.deepEqual( y, ye, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/wasm/sswap/test/test.routine.js b/lib/node_modules/@stdlib/blas/base/wasm/sswap/test/test.routine.js new file mode 100644 index 000000000000..d90a5804a8e1 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/wasm/sswap/test/test.routine.js @@ -0,0 +1,71 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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/console/log-each-map/test/test.js b/lib/node_modules/@stdlib/console/log-each-map/test/test.js index b758bf72e00e..acf98cc70234 100644 --- a/lib/node_modules/@stdlib/console/log-each-map/test/test.js +++ b/lib/node_modules/@stdlib/console/log-each-map/test/test.js @@ -639,3 +639,33 @@ tape( 'the function supports providing a callback execution context', function t actual.push( str ); } }); + +tape( 'the function handles escaped percent signs (%%)', function test( t ) { + var logEachMap; + var expected; + var actual; + var x; + var y; + + logEachMap = proxyquire( './../lib/main.js', { + '@stdlib/console/log': logger + }); + + x = [ 4, 5, 6 ]; + y = [ 1, 2, 3 ]; + expected = [ '4%1 = 0', '5%2 = 1', '6%3 = 0' ]; + actual = []; + + logEachMap( '%d%%%d = %d', x, y, mod ); + + t.deepEqual( actual, expected, 'returns expected value' ); + t.end(); + + function mod( v1, v2 ) { + return v1 % v2; + } + + function logger( str ) { + actual.push( str ); + } +}); diff --git a/lib/node_modules/@stdlib/console/log-each/test/test.js b/lib/node_modules/@stdlib/console/log-each/test/test.js index 3def3b72d2ef..9e1ef53faf32 100644 --- a/lib/node_modules/@stdlib/console/log-each/test/test.js +++ b/lib/node_modules/@stdlib/console/log-each/test/test.js @@ -520,3 +520,35 @@ tape( 'the function prints a formatted message when only provided two scalar arg j += 1; } }); + +tape( 'the function handles escaped percent signs (%%)', function test( t ) { + var expected; + var logEach; + var j; + + logEach = proxyquire( './../lib/main.js', { + '@stdlib/console/log': logger + }); + + expected = [ + 'Progress: 100% complete', + 'Rate: 75% success', + '50.0% + 25.0% = 75.0%', + '5%2 = 1' + ]; + + j = 0; + + logEach( 'Progress: 100%% complete' ); + logEach( 'Rate: %d%% success', 75 ); + logEach( '%0.1f%% + %0.1f%% = %.1f%%', 50.00, 25.00, 75.00 ); + logEach( '%d%%%d = %d', 5, 2, 1 ); + + t.strictEqual( j, expected.length, 'returns expected value' ); + t.end(); + + function logger( str ) { + t.equal( str, expected[ j ], 'returns expected value' ); + j += 1; + } +}); diff --git a/lib/node_modules/@stdlib/constants/float64/apery/test/test.js b/lib/node_modules/@stdlib/constants/float64/apery/test/test.js index 36a872e1b4d3..829ad4ba2872 100644 --- a/lib/node_modules/@stdlib/constants/float64/apery/test/test.js +++ b/lib/node_modules/@stdlib/constants/float64/apery/test/test.js @@ -33,6 +33,6 @@ tape( 'main export is a number', function test( t ) { }); tape( 'the exported value is a double-precision floating-point number equal to 1.2020569031595942', function test( t ) { - t.equal( APERY, 1.2020569031595942, 'returns 1.2020569031595942' ); + t.equal( APERY, 1.2020569031595942, 'returns expected value' ); t.end(); }); diff --git a/lib/node_modules/@stdlib/constants/float64/catalan/test/test.js b/lib/node_modules/@stdlib/constants/float64/catalan/test/test.js index 202fe992cbda..534143eb2555 100644 --- a/lib/node_modules/@stdlib/constants/float64/catalan/test/test.js +++ b/lib/node_modules/@stdlib/constants/float64/catalan/test/test.js @@ -33,6 +33,6 @@ tape( 'main export is a number', function test( t ) { }); tape( 'the exported value is a double-precision floating-point number equal to 0.915965594177219', function test( t ) { - t.equal( CATALAN, 0.915965594177219, 'returns 0.915965594177219' ); + t.equal( CATALAN, 0.915965594177219, 'returns expected value' ); t.end(); }); diff --git a/lib/node_modules/@stdlib/constants/float64/cbrt-eps/test/test.js b/lib/node_modules/@stdlib/constants/float64/cbrt-eps/test/test.js index e8407b7bebdb..46647fa5f575 100644 --- a/lib/node_modules/@stdlib/constants/float64/cbrt-eps/test/test.js +++ b/lib/node_modules/@stdlib/constants/float64/cbrt-eps/test/test.js @@ -36,6 +36,6 @@ tape( 'main export is a number', function test( t ) { tape( 'the exported value equals the cube root of the difference between one and the smallest value greater than one which is representable as a double (2**-52)', function test( t ) { var expected = cbrt( pow( 2, -52 ) ); - t.equal( FLOAT64_CBRT_EPSILON, expected, 'equals cbrt(2**-52)' ); + t.equal( FLOAT64_CBRT_EPSILON, expected, 'returns expected value' ); t.end(); }); diff --git a/lib/node_modules/@stdlib/constants/float64/e/test/test.js b/lib/node_modules/@stdlib/constants/float64/e/test/test.js index 25af0d419fd6..c948f3ed520a 100644 --- a/lib/node_modules/@stdlib/constants/float64/e/test/test.js +++ b/lib/node_modules/@stdlib/constants/float64/e/test/test.js @@ -33,6 +33,6 @@ tape( 'main export is a number', function test( t ) { }); tape( 'export is a double-precision floating-point number equal to 2.718281828459045', function test( t ) { - t.equal( E, 2.718281828459045, 'equals 2.718281828459045' ); + t.equal( E, 2.718281828459045, 'returns expected value' ); t.end(); }); diff --git a/lib/node_modules/@stdlib/constants/float64/eps/test/test.js b/lib/node_modules/@stdlib/constants/float64/eps/test/test.js index 252072989c85..029960186c2d 100644 --- a/lib/node_modules/@stdlib/constants/float64/eps/test/test.js +++ b/lib/node_modules/@stdlib/constants/float64/eps/test/test.js @@ -35,6 +35,6 @@ tape( 'main export is a number', function test( t ) { tape( 'the exported value equals the difference between one and the smallest value greater than one which is representable as a double (2**-52)', function test( t ) { var expected = pow( 2, -52 ); - t.equal( FLOAT64_EPSILON, expected, 'equals 2**-52' ); + t.equal( FLOAT64_EPSILON, expected, 'returns expected value' ); t.end(); }); diff --git a/lib/node_modules/@stdlib/constants/float64/eulergamma/test/test.js b/lib/node_modules/@stdlib/constants/float64/eulergamma/test/test.js index 1a077914dd17..d07f28c102bf 100644 --- a/lib/node_modules/@stdlib/constants/float64/eulergamma/test/test.js +++ b/lib/node_modules/@stdlib/constants/float64/eulergamma/test/test.js @@ -33,6 +33,6 @@ tape( 'main export is a number', function test( t ) { }); tape( 'the exported value is a double-precision floating-point number equal to 0.5772156649015329', function test( t ) { - t.equal( EULERGAMMA, 0.5772156649015329, 'returns 0.5772156649015329' ); + t.equal( EULERGAMMA, 0.5772156649015329, 'returns expected value' ); t.end(); }); diff --git a/lib/node_modules/@stdlib/constants/float64/exponent-bias/test/test.js b/lib/node_modules/@stdlib/constants/float64/exponent-bias/test/test.js index 8f0e4f8d3086..91f9b614d611 100644 --- a/lib/node_modules/@stdlib/constants/float64/exponent-bias/test/test.js +++ b/lib/node_modules/@stdlib/constants/float64/exponent-bias/test/test.js @@ -33,6 +33,6 @@ tape( 'main export is a number', function test( t ) { }); tape( 'the exported value is 1023', function test( t ) { - t.equal( FLOAT64_EXPONENT_BIAS, 1023, 'equals 1023' ); + t.equal( FLOAT64_EXPONENT_BIAS, 1023, 'returns expected value' ); t.end(); }); diff --git a/lib/node_modules/@stdlib/constants/float64/fourth-pi/test/test.js b/lib/node_modules/@stdlib/constants/float64/fourth-pi/test/test.js index 95d4da82827e..7045c32d1808 100644 --- a/lib/node_modules/@stdlib/constants/float64/fourth-pi/test/test.js +++ b/lib/node_modules/@stdlib/constants/float64/fourth-pi/test/test.js @@ -33,6 +33,6 @@ tape( 'main export is a number', function test( t ) { }); tape( 'export is a double-precision floating-point number equal to 7.85398163397448309616e-1', function test( t ) { - t.equal( FOURTH_PI, 7.85398163397448309616e-1, 'equals 7.85398163397448309616e-1' ); + t.equal( FOURTH_PI, 7.85398163397448309616e-1, 'returns expected value' ); t.end(); }); diff --git a/lib/node_modules/@stdlib/constants/float64/fourth-root-eps/test/test.js b/lib/node_modules/@stdlib/constants/float64/fourth-root-eps/test/test.js index 3012476e3f31..76e0bd9c5bde 100644 --- a/lib/node_modules/@stdlib/constants/float64/fourth-root-eps/test/test.js +++ b/lib/node_modules/@stdlib/constants/float64/fourth-root-eps/test/test.js @@ -36,6 +36,6 @@ tape( 'main export is a number', function test( t ) { tape( 'the exported value equals the fourth root of the difference between one and the smallest value greater than one which is representable as a double (2**-52)', function test( t ) { var expected = sqrt( sqrt( pow( 2, -52 ) ) ); - t.equal( FLOAT64_FOURTH_ROOT_EPS, expected, 'equals sqrt( sqrt(2**-52) )' ); + t.equal( FLOAT64_FOURTH_ROOT_EPS, expected, 'returns expected value' ); t.end(); }); diff --git a/lib/node_modules/@stdlib/constants/float64/gamma-lanczos-g/test/test.js b/lib/node_modules/@stdlib/constants/float64/gamma-lanczos-g/test/test.js index bc20cc8f556f..d23fe460dd50 100644 --- a/lib/node_modules/@stdlib/constants/float64/gamma-lanczos-g/test/test.js +++ b/lib/node_modules/@stdlib/constants/float64/gamma-lanczos-g/test/test.js @@ -34,6 +34,6 @@ tape( 'main export is a number', function test( t ) { tape( 'the exported value equals `10.900511`', function test( t ) { var expected = 10.900511; - t.strictEqual( FLOAT64_GAMMA_LANCZOS_G, expected, 'equals 10.900511' ); + t.strictEqual( FLOAT64_GAMMA_LANCZOS_G, expected, 'returns expected value' ); t.end(); }); diff --git a/lib/node_modules/@stdlib/math/base/special/README.md b/lib/node_modules/@stdlib/math/base/special/README.md index 7c4896a63cb7..bb446bff5f3a 100644 --- a/lib/node_modules/@stdlib/math/base/special/README.md +++ b/lib/node_modules/@stdlib/math/base/special/README.md @@ -154,7 +154,7 @@ var fcns = special; - [`cabs2f( z )`][@stdlib/math/base/special/cabs2f]: compute the squared absolute value of a single-precision complex floating-point number. - [`cabsf( z )`][@stdlib/math/base/special/cabsf]: compute the absolute value of a single-precision complex floating-point number. - [`cceil( z )`][@stdlib/math/base/special/cceil]: round each component of a double-precision complex floating-point number toward positive infinity. -- [`cceilf( z )`][@stdlib/math/base/special/cceilf]: round a single-precision complex floating-point number toward positive infinity. +- [`cceilf( z )`][@stdlib/math/base/special/cceilf]: round each component of a single-precision complex floating-point number toward positive infinity. - [`cceiln( z, n )`][@stdlib/math/base/special/cceiln]: round each component of a double-precision complex floating-point number to the nearest multiple of `10^n` toward positive infinity. - [`ceil( x )`][@stdlib/math/base/special/ceil]: round a double-precision floating-point number toward positive infinity. - [`ceil10( x )`][@stdlib/math/base/special/ceil10]: round a numeric value to the nearest power of 10 toward positive infinity. diff --git a/lib/node_modules/@stdlib/math/base/special/cabs2f/README.md b/lib/node_modules/@stdlib/math/base/special/cabs2f/README.md index 39cc61ff6c5d..791ff508ad3b 100644 --- a/lib/node_modules/@stdlib/math/base/special/cabs2f/README.md +++ b/lib/node_modules/@stdlib/math/base/special/cabs2f/README.md @@ -139,18 +139,20 @@ for ( i = 0; i < 100; i++ ) { Computes the squared [absolute value][absolute-value] of a single-precision complex floating-point number. ```c -#include +#include "stdlib/complex/float32/ctor.h" -float y = stdlib_base_cabs2f( 5.0+3.0*I ); +stdlib_complex64_t z = stdlib_complex64( 5.0f, 3.0f ); + +float y = stdlib_base_cabs2f( z ); // returns 34.0f ``` The function accepts the following arguments: -- **z**: `[in] float complex` input value. +- **z**: `[in] stdlib_complex64_t` input value. ```c -float stdlib_base_cabs2f( const float complex z ); +float stdlib_base_cabs2f( const stdlib_complex64_t z ); ``` @@ -173,19 +175,28 @@ float stdlib_base_cabs2f( const float complex z ); ```c #include "stdlib/math/base/special/cabs2f.h" +#include "stdlib/complex/float32/ctor.h" +#include "stdlib/complex/float32/reim.h" #include -#include int main( void ) { - const float complex x[] = { 3.14f+1.0f*I, -3.14f-1.0f*I, 0.0f+0.0f*I, 0.0f/0.0f+0.0f/0.0f*I }; - - float complex v; + const stdlib_complex64_t x[] = { + stdlib_complex64( 3.14f, 1.0f ), + stdlib_complex64( -3.14f, -1.0f ), + stdlib_complex64( 0.0f, 0.0f ), + stdlib_complex64( 0.0f/0.0f, 0.0f/0.0f ) + }; + + stdlib_complex64_t v; + float re; + float im; float y; int i; for ( i = 0; i < 4; i++ ) { v = x[ i ]; y = stdlib_base_cabs2f( v ); - printf( "f(%f + %f) = %f\n", crealf( v ), cimagf( v ), y ); + stdlib_complex64_reim( v, &re, &im ); + printf( "f(%f + %fi) = %f\n", re, im, y ); } } ``` diff --git a/lib/node_modules/@stdlib/math/base/special/cabs2f/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/math/base/special/cabs2f/benchmark/benchmark.native.js new file mode 100644 index 000000000000..dd28316c66f5 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cabs2f/benchmark/benchmark.native.js @@ -0,0 +1,65 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/base/uniform' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var cabs2f = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( cabs2f instanceof Error ) +}; + + +// MAIN // + +bench( pkg+'::native', opts, function benchmark( b ) { + var values; + var y; + var i; + + values = [ + new Complex64( uniform( -500.0, 500.0 ), uniform( -500.0, 500.0 ) ), + new Complex64( uniform( -500.0, 500.0 ), uniform( -500.0, 500.0 ) ) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = cabs2f( values[ i%values.length ] ); + if ( isnanf( y ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( y ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/special/cabs2f/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/special/cabs2f/benchmark/c/native/benchmark.c index 6a9e4a273010..ad9152827ae8 100644 --- a/lib/node_modules/@stdlib/math/base/special/cabs2f/benchmark/c/native/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/cabs2f/benchmark/c/native/benchmark.c @@ -17,7 +17,8 @@ */ #include "stdlib/math/base/special/cabs2f.h" -#include +#include "stdlib/complex/float32/ctor.h" +#include "stdlib/complex/float32/reim.h" #include #include #include @@ -91,7 +92,6 @@ static float rand_float( void ) { * @return elapsed time in seconds */ static double benchmark( void ) { - float complex z; double elapsed; double t; float re; @@ -99,12 +99,17 @@ static double benchmark( void ) { float y; int i; - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { + stdlib_complex64_t z[ 100 ]; + + for ( i = 0; i < 100; i++ ) { re = ( 1000.0f*rand_float() ) - 500.0f; im = ( 1000.0f*rand_float() ) - 500.0f; - z = re + im*I; - y = stdlib_base_cabs2f( z ); + z[ i ] = stdlib_complex64( re, im ); + } + + t = tic(); + for ( i = 0; i < ITERATIONS; i++ ) { + y = stdlib_base_cabs2f( z[ i%100 ] ); if ( y != y ) { printf( "should not return NaN\n" ); break; diff --git a/lib/node_modules/@stdlib/math/base/special/cabs2f/binding.gyp b/lib/node_modules/@stdlib/math/base/special/cabs2f/binding.gyp new file mode 100644 index 000000000000..68a1ca11d160 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cabs2f/binding.gyp @@ -0,0 +1,170 @@ +# @license Apache-2.0 +# +# Copyright (c) 2025 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# A `.gyp` file for building a Node.js native add-on. +# +# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md +# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md +{ + # List of files to include in this file: + 'includes': [ + './include.gypi', + ], + + # Define variables to be used throughout the configuration for all targets: + 'variables': { + # Target name should match the add-on export name: + 'addon_target_name%': 'addon', + + # Set variables based on the host OS: + 'conditions': [ + [ + 'OS=="win"', + { + # Define the object file suffix: + 'obj': 'obj', + }, + { + # Define the object file suffix: + 'obj': 'o', + } + ], # end condition (OS=="win") + ], # end conditions + }, # end variables + + # Define compile targets: + 'targets': [ + + # Target to generate an add-on: + { + # The target name should match the add-on export name: + 'target_name': '<(addon_target_name)', + + # Define dependencies: + 'dependencies': [], + + # Define directories which contain relevant include headers: + 'include_dirs': [ + # Local include directory: + '<@(include_dirs)', + ], + + # List of source files: + 'sources': [ + '<@(src_files)', + ], + + # Settings which should be applied when a target's object files are used as linker input: + 'link_settings': { + # Define libraries: + 'libraries': [ + '<@(libraries)', + ], + + # Define library directories: + 'library_dirs': [ + '<@(library_dirs)', + ], + }, + + # C/C++ compiler flags: + 'cflags': [ + # Enable commonly used warning options: + '-Wall', + + # Aggressive optimization: + '-O3', + ], + + # C specific compiler flags: + 'cflags_c': [ + # Specify the C standard to which a program is expected to conform: + '-std=c99', + ], + + # C++ specific compiler flags: + 'cflags_cpp': [ + # Specify the C++ standard to which a program is expected to conform: + '-std=c++11', + ], + + # Linker flags: + 'ldflags': [], + + # Apply conditions based on the host OS: + 'conditions': [ + [ + 'OS=="mac"', + { + # Linker flags: + 'ldflags': [ + '-undefined dynamic_lookup', + '-Wl,-no-pie', + '-Wl,-search_paths_first', + ], + }, + ], # end condition (OS=="mac") + [ + 'OS!="win"', + { + # C/C++ flags: + 'cflags': [ + # Generate platform-independent code: + '-fPIC', + ], + }, + ], # end condition (OS!="win") + ], # end conditions + }, # end target <(addon_target_name) + + # Target to copy a generated add-on to a standard location: + { + 'target_name': 'copy_addon', + + # Declare that the output of this target is not linked: + 'type': 'none', + + # Define dependencies: + 'dependencies': [ + # Require that the add-on be generated before building this target: + '<(addon_target_name)', + ], + + # Define a list of actions: + 'actions': [ + { + 'action_name': 'copy_addon', + 'message': 'Copying addon...', + + # Explicitly list the inputs in the command-line invocation below: + 'inputs': [], + + # Declare the expected outputs: + 'outputs': [ + '<(addon_output_dir)/<(addon_target_name).node', + ], + + # Define the command-line invocation: + 'action': [ + 'cp', + '<(PRODUCT_DIR)/<(addon_target_name).node', + '<(addon_output_dir)/<(addon_target_name).node', + ], + }, + ], # end actions + }, # end target copy_addon + ], # end targets +} diff --git a/lib/node_modules/@stdlib/math/base/special/cabs2f/examples/c/example.c b/lib/node_modules/@stdlib/math/base/special/cabs2f/examples/c/example.c index 5e46ab652b1a..5f7b260079bf 100644 --- a/lib/node_modules/@stdlib/math/base/special/cabs2f/examples/c/example.c +++ b/lib/node_modules/@stdlib/math/base/special/cabs2f/examples/c/example.c @@ -17,18 +17,27 @@ */ #include "stdlib/math/base/special/cabs2f.h" +#include "stdlib/complex/float32/ctor.h" +#include "stdlib/complex/float32/reim.h" #include -#include int main( void ) { - float complex x[] = { 3.14f+1.0f*I, -3.14f-1.0f*I, 0.0f+0.0f*I, 0.0f/0.0f+0.0f/0.0f*I }; + const stdlib_complex64_t x[] = { + stdlib_complex64( 3.14f, 1.0f ), + stdlib_complex64( -3.14f, -1.0f ), + stdlib_complex64( 0.0f, 0.0f ), + stdlib_complex64( 0.0f/0.0f, 0.0f/0.0f ) + }; - float complex v; + stdlib_complex64_t v; + float re; + float im; float y; int i; for ( i = 0; i < 4; i++ ) { v = x[ i ]; y = stdlib_base_cabs2f( v ); - printf( "f(%f + %f) = %f\n", crealf( v ), cimagf( v ), y ); + stdlib_complex64_reim( v, &re, &im ); + printf( "f(%f + %fi) = %f\n", re, im, y ); } } diff --git a/lib/node_modules/@stdlib/math/base/special/cabs2f/include.gypi b/lib/node_modules/@stdlib/math/base/special/cabs2f/include.gypi new file mode 100644 index 000000000000..ecfaf82a3279 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cabs2f/include.gypi @@ -0,0 +1,53 @@ +# @license Apache-2.0 +# +# Copyright (c) 2025 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# A GYP include file for building a Node.js native add-on. +# +# Main documentation: +# +# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md +# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md +{ + # Define variables to be used throughout the configuration for all targets: + 'variables': { + # Source directory: + 'src_dir': './src', + + # Include directories: + 'include_dirs': [ + ' +#include "stdlib/complex/float32/ctor.h" /* * If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. @@ -31,7 +31,7 @@ extern "C" { /** * Computes the squared absolute value of a single-precision complex floating-point number. */ -float stdlib_base_cabs2f( const float complex z ); +float stdlib_base_cabs2f( const stdlib_complex64_t z ); #ifdef __cplusplus } diff --git a/lib/node_modules/@stdlib/math/base/special/cabs2f/lib/native.js b/lib/node_modules/@stdlib/math/base/special/cabs2f/lib/native.js new file mode 100644 index 000000000000..d2f37f07907a --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cabs2f/lib/native.js @@ -0,0 +1,48 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 addon = require( './../src/addon.node' ); + + +// MAIN // + +/** +* Computes the squared absolute value of a single-precision complex floating-point number. +* +* @private +* @param {Complex64} z - complex number +* @returns {number} squared absolute value +* +* @example +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* +* var v = cabs2f( new Complex64( 5.0, 3.0 ) ); +* // returns 34.0 +*/ +function cabs2f( z ) { + return addon( z ); +} + + +// EXPORTS // + +module.exports = cabs2f; diff --git a/lib/node_modules/@stdlib/math/base/special/cabs2f/manifest.json b/lib/node_modules/@stdlib/math/base/special/cabs2f/manifest.json index 890a937a3dc0..b36aa0ccd4c6 100644 --- a/lib/node_modules/@stdlib/math/base/special/cabs2f/manifest.json +++ b/lib/node_modules/@stdlib/math/base/special/cabs2f/manifest.json @@ -1,38 +1,75 @@ { - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [] - } - ] + "options": { + "task": "build" + }, + "fields": [ + { + "field": "src", + "resolve": true, + "relative": true + }, + { + "field": "include", + "resolve": true, + "relative": true + }, + { + "field": "libraries", + "resolve": false, + "relative": false + }, + { + "field": "libpath", + "resolve": true, + "relative": false + } + ], + "confs": [ + { + "task": "build", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/napi/unary", + "@stdlib/complex/float32/ctor", + "@stdlib/complex/float32/reim" + ] + }, + { + "task": "benchmark", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/complex/float32/ctor", + "@stdlib/complex/float32/reim" + ] + }, + { + "task": "examples", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/complex/float32/ctor", + "@stdlib/complex/float32/reim" + ] + } + ] } diff --git a/lib/node_modules/@stdlib/math/base/special/cabs2f/package.json b/lib/node_modules/@stdlib/math/base/special/cabs2f/package.json index 2e31d01d6154..2c268482d0c5 100644 --- a/lib/node_modules/@stdlib/math/base/special/cabs2f/package.json +++ b/lib/node_modules/@stdlib/math/base/special/cabs2f/package.json @@ -14,6 +14,7 @@ } ], "main": "./lib", + "gypfile": true, "directories": { "benchmark": "./benchmark", "doc": "./docs", diff --git a/lib/node_modules/@stdlib/math/base/special/cabs2f/src/Makefile b/lib/node_modules/@stdlib/math/base/special/cabs2f/src/Makefile new file mode 100644 index 000000000000..7733b6180cb4 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cabs2f/src/Makefile @@ -0,0 +1,70 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2025 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + + +# RULES # + +#/ +# Removes generated files for building an add-on. +# +# @example +# make clean-addon +#/ +clean-addon: + $(QUIET) -rm -f *.o *.node + +.PHONY: clean-addon + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: clean-addon + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/math/base/special/cabs2f/src/addon.c b/lib/node_modules/@stdlib/math/base/special/cabs2f/src/addon.c new file mode 100644 index 000000000000..a59c74d2f126 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cabs2f/src/addon.c @@ -0,0 +1,22 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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/math/base/special/cabs2f.h" +#include "stdlib/math/base/napi/unary.h" + +STDLIB_MATH_BASE_NAPI_MODULE_C_F( stdlib_base_cabs2f ) diff --git a/lib/node_modules/@stdlib/math/base/special/cabs2f/src/main.c b/lib/node_modules/@stdlib/math/base/special/cabs2f/src/main.c index f83b3faa0595..f6bf2e78cf41 100644 --- a/lib/node_modules/@stdlib/math/base/special/cabs2f/src/main.c +++ b/lib/node_modules/@stdlib/math/base/special/cabs2f/src/main.c @@ -17,7 +17,8 @@ */ #include "stdlib/math/base/special/cabs2f.h" -#include +#include "stdlib/complex/float32/ctor.h" +#include "stdlib/complex/float32/reim.h" /** * Computes the squared absolute value of a single-precision complex floating-point number. @@ -26,11 +27,16 @@ * @return result * * @example -* float y = stdlib_base_cabs2f( 5.0+3.0*I ); +* #include "stdlib/complex/float32/ctor.h" +* +* stdlib_complex64_t z = stdlib_complex64( 5.0f, 3.0f ); +* +* float y = stdlib_base_cabs2f( z ); * // returns 34.0f */ -float stdlib_base_cabs2f( const float complex z ) { - float re = crealf( z ); - float im = cimagf( z ); - return (re*re) + (im*im); +float stdlib_base_cabs2f( const stdlib_complex64_t z ) { + float re; + float im; + stdlib_complex64_reim( z, &re, &im ); + return ( re*re ) + ( im*im ); } diff --git a/lib/node_modules/@stdlib/math/base/special/cabs2f/test/test.js b/lib/node_modules/@stdlib/math/base/special/cabs2f/test/test.js index c8df7d5aa311..360f3e9485bf 100644 --- a/lib/node_modules/@stdlib/math/base/special/cabs2f/test/test.js +++ b/lib/node_modules/@stdlib/math/base/special/cabs2f/test/test.js @@ -23,7 +23,7 @@ var tape = require( 'tape' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var EPS = require( '@stdlib/constants/float32/eps' ); -var abs = require( '@stdlib/math/base/special/abs' ); +var absf = require( '@stdlib/math/base/special/absf' ); var Complex64 = require( '@stdlib/complex/float32/ctor' ); var cabs2f = require( './../lib' ); @@ -59,8 +59,8 @@ tape( 'the function computes the squared absolute value of a complex number', fu if ( y === expected[ i ] ) { t.strictEqual( y, expected[ i ], 're: '+re[i]+'. im: '+im[i]+'. Expected: '+expected[i] ); } else { - delta = abs( y - expected[i] ); - tol = EPS * abs( expected[i] ); + delta = absf( y - expected[i] ); + tol = EPS * absf( expected[i] ); t.ok( delta <= tol, 'within tolerance. re: '+re[i]+'. im: '+im[i]+' y: '+y+'. Expected: '+expected[i]+'. delta: '+delta+'. tol: '+tol+'.' ); } } @@ -71,13 +71,13 @@ tape( 'if either the real or imaginary component is `NaN`, the function returns var v; v = cabs2f( new Complex64( NaN, 3.0 ) ); - t.strictEqual( isnanf( v ), true, 'returns NaN' ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); v = cabs2f( new Complex64( 5.0, NaN ) ); - t.strictEqual( isnanf( v ), true, 'returns NaN' ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); v = cabs2f( new Complex64( NaN, NaN ) ); - t.strictEqual( isnanf( v ), true, 'returns NaN' ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); t.end(); }); diff --git a/lib/node_modules/@stdlib/math/base/special/cabs2f/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/cabs2f/test/test.native.js new file mode 100644 index 000000000000..4d5990cf523b --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cabs2f/test/test.native.js @@ -0,0 +1,92 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 tape = require( 'tape' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var EPS = require( '@stdlib/constants/float32/eps' ); +var absf = require( '@stdlib/math/base/special/absf' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var tryRequire = require( '@stdlib/utils/try-require' ); + + +// VARIABLES // + +var cabs2f = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( cabs2f instanceof Error ) +}; + + +// FIXTURES // + +var data = require( './fixtures/julia/data.json' ); + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof cabs2f, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function computes the squared absolute value of a complex number', opts, function test( t ) { + var expected; + var delta; + var tol; + var re; + var im; + var y; + var i; + + re = data.re; + im = data.im; + expected = data.expected; + + for ( i = 0; i < re.length; i++ ) { + y = cabs2f( new Complex64( re[ i ], im[ i ] ) ); + if ( y === expected[ i ] ) { + t.equal( y, expected[ i ], 're: '+re[i]+'. im: '+im[i]+'. Expected: '+expected[i] ); + } else { + delta = absf( y - expected[i] ); + tol = EPS * absf( expected[i] ); + t.ok( delta <= tol, 'within tolerance. re: '+re[i]+'. im: '+im[i]+' y: '+y+'. Expected: '+expected[i]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'if either the real or imaginary component is `NaN`, the function returns `NaN`', opts, function test( t ) { + var v; + + v = cabs2f( new Complex64( NaN, 3.0 ) ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); + + v = cabs2f( new Complex64( 5.0, NaN ) ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); + + v = cabs2f( new Complex64( NaN, NaN ) ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/special/cceilf/README.md b/lib/node_modules/@stdlib/math/base/special/cceilf/README.md index 99b848325ca5..06de1f94fb3a 100644 --- a/lib/node_modules/@stdlib/math/base/special/cceilf/README.md +++ b/lib/node_modules/@stdlib/math/base/special/cceilf/README.md @@ -20,7 +20,7 @@ limitations under the License. # cceilf -> Round a single-precision complex floating-point number toward positive infinity. +> Round each component of a single-precision complex floating-point number toward positive infinity.
@@ -32,7 +32,7 @@ var cceilf = require( '@stdlib/math/base/special/cceilf' ); #### cceilf( z ) -Rounds a single-precision complex floating-point number toward positive infinity. +Rounds each component of a single-precision complex floating-point number toward positive infinity. ```javascript var Complex64 = require( '@stdlib/complex/float32/ctor' ); @@ -106,21 +106,30 @@ for ( i = 0; i < 100; i++ ) { #### stdlib_base_cceilf( z ) -Rounds a single-precision complex floating-point number toward positive infinity. +Rounds each component of a single-precision complex floating-point number toward positive infinity. ```c -#include +#include "stdlib/complex/float32/ctor.h" +#include "stdlib/complex/float32/real.h" +#include "stdlib/complex/float32/imag.h" -float complex y = stdlib_base_cceilf( 2.5f-1.5f*I ); -// returns 3.0f-1.0f*I +stdlib_complex64_t z = stdlib_complex64( 2.5f, -1.5f ); + +stdlib_complex64_t out = stdlib_base_cceilf( z ); + +float re = stdlib_complex64_real( out ); +// returns 3.0f + +float im = stdlib_complex64_imag( out ); +// returns -1.0f ``` The function accepts the following arguments: -- **z**: `[in] float complex` input value. +- **z**: `[in] stdlib_complex64_t` input value. ```c -float complex stdlib_base_cceilf( const float complex z ); +stdlib_complex64_t stdlib_base_cceilf( const stdlib_complex64_t z ); ```
@@ -143,19 +152,31 @@ float complex stdlib_base_cceilf( const float complex z ); ```c #include "stdlib/math/base/special/cceilf.h" +#include "stdlib/complex/float32/ctor.h" +#include "stdlib/complex/float32/reim.h" #include -#include int main( void ) { - const float complex x[] = { 3.14f+1.5f*I, -3.14f-1.5f*I, 0.0f+0.0f*I, 0.0f/0.0f+0.0f/0.0f*I }; - - float complex v; - float complex y; + const stdlib_complex64_t x[] = { + stdlib_complex64( 3.14f, 1.5f ), + stdlib_complex64( -3.14f, -1.5f ), + stdlib_complex64( 0.0f, 0.0f ), + stdlib_complex64( 0.0f/0.0f, 0.0f/0.0f ) + }; + + stdlib_complex64_t v; + stdlib_complex64_t y; + float re1; + float im1; + float re2; + float im2; int i; for ( i = 0; i < 4; i++ ) { v = x[ i ]; y = stdlib_base_cceilf( v ); - printf( "cceilf(%f + %fi) = %f + %fi\n", crealf( v ), cimagf( v ), crealf( y ), cimagf( y ) ); + stdlib_complex64_reim( v, &re1, &im1 ); + stdlib_complex64_reim( y, &re2, &im2 ); + printf( "cceilf(%f + %fi) = %f + %fi\n", re1, im1, re2, im2 ); } } ``` @@ -172,12 +193,6 @@ int main( void ) { @@ -188,8 +203,6 @@ int main( void ) { -[@stdlib/math/base/special/cceil]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/cceil - diff --git a/lib/node_modules/@stdlib/math/base/special/cceilf/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/math/base/special/cceilf/benchmark/benchmark.native.js new file mode 100644 index 000000000000..5c2cdafe2bab --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cceilf/benchmark/benchmark.native.js @@ -0,0 +1,67 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/base/uniform' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var real = require( '@stdlib/complex/float32/real' ); +var imag = require( '@stdlib/complex/float32/imag' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var cceilf = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( cceilf instanceof Error ) +}; + + +// MAIN // + +bench( pkg, opts, function benchmark( b ) { + var values; + var y; + var i; + + values = [ + new Complex64( uniform( -500.0, 500.0 ), uniform( -500.0, 500.0 ) ), + new Complex64( uniform( -500.0, 500.0 ), uniform( -500.0, 500.0 ) ) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = cceilf( values[ i%values.length ] ); + if ( isnanf( real( y ) ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( imag( y ) ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/special/cceilf/benchmark/c/Makefile b/lib/node_modules/@stdlib/math/base/special/cceilf/benchmark/c/Makefile new file mode 100644 index 000000000000..a4bd7b38fd74 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cceilf/benchmark/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2025 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files: +ifdef C_COMPILER + CC := $(C_COMPILER) +else + CC := gcc +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate position independent code ([1][1], [2][2]). +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= + +# List of C targets: +c_targets := benchmark.out + + +# RULES # + +#/ +# Compiles source files. +# +# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) +# @param {string} [CFLAGS] - C compiler options +# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make +# +# @example +# make all +#/ +all: $(c_targets) + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +# @param {string} CC - C compiler (e.g., `gcc`) +# @param {string} CFLAGS - C compiler options +# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) +# @param {string} SOURCE_FILES - list of source files +# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) +# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) +#/ +$(c_targets): %.out: %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) + +#/ +# Runs compiled benchmarks. +# +# @example +# make run +#/ +run: $(c_targets) + $(QUIET) ./$< + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/math/base/special/cceilf/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/math/base/special/cceilf/benchmark/c/benchmark.c new file mode 100644 index 000000000000..6cade907a3ea --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cceilf/benchmark/c/benchmark.c @@ -0,0 +1,139 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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/math/base/special/ceilf.h" +#include +#include +#include +#include +#include +#include + +#define NAME "cceilf" +#define ITERATIONS 1000000 +#define REPEATS 3 + +/** +* Prints the TAP version. +*/ +static void print_version( void ) { + printf( "TAP version 13\n" ); +} + +/** +* Prints the TAP summary. +* +* @param total total number of tests +* @param passing total number of passing tests +*/ +static void print_summary( int total, int passing ) { + printf( "#\n" ); + printf( "1..%d\n", total ); // TAP plan + printf( "# total %d\n", total ); + printf( "# pass %d\n", passing ); + printf( "#\n" ); + printf( "# ok\n" ); +} + +/** +* Prints benchmarks results. +* +* @param elapsed elapsed time in seconds +*/ +static void print_results( double elapsed ) { + double rate = (double)ITERATIONS / elapsed; + printf( " ---\n" ); + printf( " iterations: %d\n", ITERATIONS ); + printf( " elapsed: %0.9f\n", elapsed ); + printf( " rate: %0.9f\n", rate ); + printf( " ...\n" ); +} + +/** +* Returns a clock time. +* +* @return clock time +*/ +static double tic( void ) { + struct timeval now; + gettimeofday( &now, NULL ); + return (double)now.tv_sec + (double)now.tv_usec/1.0e6; +} + +/** +* Generates a random number on the interval [0,1). +* +* @return random number +*/ +static float rand_float( void ) { + int r = rand(); + return (float)r / ( (float)RAND_MAX + 1.0f ); +} + +/** +* Runs a benchmark. +* +* @return elapsed time in seconds +*/ +static double benchmark( void ) { + float complex x; + float complex y; + double elapsed; + float v[ 100 ]; + double t; + int i; + + for ( i = 0; i < 100; i++ ) { + v[ i ] = ( 1000.0f*rand_float() ) - 500.0f; + } + + t = tic(); + for ( i = 0; i < ITERATIONS; i++ ) { + x = v[ i%100 ] + v[ i%100 ]*I; + y = stdlib_base_ceilf( crealf( x ) ) + stdlib_base_ceilf( cimagf( x ) )*I; + if ( crealf( y ) != crealf( y ) ) { + printf( "unexpected result\n" ); + break; + } + } + elapsed = tic() - t; + if ( cimagf( y ) != cimagf( y ) ) { + printf( "unexpected result\n" ); + } + return elapsed; +} + +/** +* Main execution sequence. +*/ +int main( void ) { + double elapsed; + int i; + + // Use the current time to seed the random number generator: + srand( time( NULL ) ); + + print_version(); + for ( i = 0; i < REPEATS; i++ ) { + printf( "# c::%s\n", NAME ); + elapsed = benchmark(); + print_results( elapsed ); + printf( "ok %d benchmark finished\n", i+1 ); + } + print_summary( REPEATS, REPEATS ); +} diff --git a/lib/node_modules/@stdlib/math/base/special/cceilf/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/special/cceilf/benchmark/c/native/benchmark.c index 2ea360db1d8b..907d66074264 100644 --- a/lib/node_modules/@stdlib/math/base/special/cceilf/benchmark/c/native/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/cceilf/benchmark/c/native/benchmark.c @@ -17,7 +17,8 @@ */ #include "stdlib/math/base/special/cceilf.h" -#include +#include "stdlib/complex/float32/ctor.h" +#include "stdlib/complex/float32/reim.h" #include #include #include @@ -91,25 +92,32 @@ static float rand_float( void ) { * @return elapsed time in seconds */ static double benchmark( void ) { - float complex x; - float complex y; double elapsed; + float v[ 100 ]; + float re; + float im; double t; - float v; int i; + stdlib_complex64_t x; + stdlib_complex64_t y; + + for ( i = 0; i < 100; i++ ) { + v[ i ] = ( 1000.0f*rand_float() ) - 500.0f; + } + t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - v = ( 1000.0f*rand_float() ) - 500.0f; - x = v + v*I; + x = stdlib_complex64( v[ i%100 ], v[ i%100 ] ); y = stdlib_base_cceilf( x ); - if ( crealf( y ) != crealf( y ) ) { + stdlib_complex64_reim( y, &re, &im ); + if ( re != re ) { printf( "unexpected result\n" ); break; } } elapsed = tic() - t; - if ( cimagf( y ) != cimagf( y ) ) { + if ( im != im ) { printf( "unexpected result\n" ); } return elapsed; diff --git a/lib/node_modules/@stdlib/math/base/special/cceilf/binding.gyp b/lib/node_modules/@stdlib/math/base/special/cceilf/binding.gyp new file mode 100644 index 000000000000..68a1ca11d160 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cceilf/binding.gyp @@ -0,0 +1,170 @@ +# @license Apache-2.0 +# +# Copyright (c) 2025 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# A `.gyp` file for building a Node.js native add-on. +# +# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md +# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md +{ + # List of files to include in this file: + 'includes': [ + './include.gypi', + ], + + # Define variables to be used throughout the configuration for all targets: + 'variables': { + # Target name should match the add-on export name: + 'addon_target_name%': 'addon', + + # Set variables based on the host OS: + 'conditions': [ + [ + 'OS=="win"', + { + # Define the object file suffix: + 'obj': 'obj', + }, + { + # Define the object file suffix: + 'obj': 'o', + } + ], # end condition (OS=="win") + ], # end conditions + }, # end variables + + # Define compile targets: + 'targets': [ + + # Target to generate an add-on: + { + # The target name should match the add-on export name: + 'target_name': '<(addon_target_name)', + + # Define dependencies: + 'dependencies': [], + + # Define directories which contain relevant include headers: + 'include_dirs': [ + # Local include directory: + '<@(include_dirs)', + ], + + # List of source files: + 'sources': [ + '<@(src_files)', + ], + + # Settings which should be applied when a target's object files are used as linker input: + 'link_settings': { + # Define libraries: + 'libraries': [ + '<@(libraries)', + ], + + # Define library directories: + 'library_dirs': [ + '<@(library_dirs)', + ], + }, + + # C/C++ compiler flags: + 'cflags': [ + # Enable commonly used warning options: + '-Wall', + + # Aggressive optimization: + '-O3', + ], + + # C specific compiler flags: + 'cflags_c': [ + # Specify the C standard to which a program is expected to conform: + '-std=c99', + ], + + # C++ specific compiler flags: + 'cflags_cpp': [ + # Specify the C++ standard to which a program is expected to conform: + '-std=c++11', + ], + + # Linker flags: + 'ldflags': [], + + # Apply conditions based on the host OS: + 'conditions': [ + [ + 'OS=="mac"', + { + # Linker flags: + 'ldflags': [ + '-undefined dynamic_lookup', + '-Wl,-no-pie', + '-Wl,-search_paths_first', + ], + }, + ], # end condition (OS=="mac") + [ + 'OS!="win"', + { + # C/C++ flags: + 'cflags': [ + # Generate platform-independent code: + '-fPIC', + ], + }, + ], # end condition (OS!="win") + ], # end conditions + }, # end target <(addon_target_name) + + # Target to copy a generated add-on to a standard location: + { + 'target_name': 'copy_addon', + + # Declare that the output of this target is not linked: + 'type': 'none', + + # Define dependencies: + 'dependencies': [ + # Require that the add-on be generated before building this target: + '<(addon_target_name)', + ], + + # Define a list of actions: + 'actions': [ + { + 'action_name': 'copy_addon', + 'message': 'Copying addon...', + + # Explicitly list the inputs in the command-line invocation below: + 'inputs': [], + + # Declare the expected outputs: + 'outputs': [ + '<(addon_output_dir)/<(addon_target_name).node', + ], + + # Define the command-line invocation: + 'action': [ + 'cp', + '<(PRODUCT_DIR)/<(addon_target_name).node', + '<(addon_output_dir)/<(addon_target_name).node', + ], + }, + ], # end actions + }, # end target copy_addon + ], # end targets +} diff --git a/lib/node_modules/@stdlib/math/base/special/cceilf/docs/repl.txt b/lib/node_modules/@stdlib/math/base/special/cceilf/docs/repl.txt index b21aaad7fafe..2e3c0b40b516 100644 --- a/lib/node_modules/@stdlib/math/base/special/cceilf/docs/repl.txt +++ b/lib/node_modules/@stdlib/math/base/special/cceilf/docs/repl.txt @@ -1,7 +1,7 @@ {{alias}}( z ) - Rounds a single-precision complex floating-point number toward positive - infinity. + Rounds each component of a single-precision complex floating-point number + toward positive infinity. Parameters ---------- diff --git a/lib/node_modules/@stdlib/math/base/special/cceilf/docs/types/index.d.ts b/lib/node_modules/@stdlib/math/base/special/cceilf/docs/types/index.d.ts index a2341d64f73a..b28c13f66a7b 100644 --- a/lib/node_modules/@stdlib/math/base/special/cceilf/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/math/base/special/cceilf/docs/types/index.d.ts @@ -23,7 +23,7 @@ import { Complex64 } from '@stdlib/types/complex'; /** -* Rounds a single-precision complex floating-point number toward positive infinity. +* Rounds each component of a single-precision complex floating-point number toward positive infinity. * * @param z - input value * @returns result diff --git a/lib/node_modules/@stdlib/math/base/special/cceilf/examples/c/example.c b/lib/node_modules/@stdlib/math/base/special/cceilf/examples/c/example.c index 0a7784391b11..0e6a6d8d2703 100644 --- a/lib/node_modules/@stdlib/math/base/special/cceilf/examples/c/example.c +++ b/lib/node_modules/@stdlib/math/base/special/cceilf/examples/c/example.c @@ -17,18 +17,30 @@ */ #include "stdlib/math/base/special/cceilf.h" +#include "stdlib/complex/float32/ctor.h" +#include "stdlib/complex/float32/reim.h" #include -#include int main( void ) { - float complex x[] = { 3.14f+1.5f*I, -3.14f-1.5f*I, 0.0f+0.0f*I, 0.0f/0.0f+0.0f/0.0f*I }; + const stdlib_complex64_t x[] = { + stdlib_complex64( 3.14f, 1.5f ), + stdlib_complex64( -3.14f, -1.5f ), + stdlib_complex64( 0.0f, 0.0f ), + stdlib_complex64( 0.0f/0.0f, 0.0f/0.0f ) + }; - float complex v; - float complex y; + stdlib_complex64_t v; + stdlib_complex64_t y; + float re1; + float im1; + float re2; + float im2; int i; for ( i = 0; i < 4; i++ ) { v = x[ i ]; y = stdlib_base_cceilf( v ); - printf( "cceilf(%f + %fi) = %f + %f\n", crealf( v ), cimagf( v ), crealf( y ), cimagf( y ) ); + stdlib_complex64_reim( v, &re1, &im1 ); + stdlib_complex64_reim( y, &re2, &im2 ); + printf( "cceilf(%f + %fi) = %f + %fi\n", re1, im1, re2, im2 ); } } diff --git a/lib/node_modules/@stdlib/math/base/special/cceilf/include.gypi b/lib/node_modules/@stdlib/math/base/special/cceilf/include.gypi new file mode 100644 index 000000000000..ecfaf82a3279 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cceilf/include.gypi @@ -0,0 +1,53 @@ +# @license Apache-2.0 +# +# Copyright (c) 2025 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# A GYP include file for building a Node.js native add-on. +# +# Main documentation: +# +# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md +# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md +{ + # Define variables to be used throughout the configuration for all targets: + 'variables': { + # Source directory: + 'src_dir': './src', + + # Include directories: + 'include_dirs': [ + ' +#include "stdlib/complex/float32/ctor.h" /* * If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. @@ -29,9 +29,9 @@ extern "C" { #endif /** -* Rounds a single-precision complex floating-point number toward positive infinity. +* Rounds each component of a single-precision complex floating-point number toward positive infinity. */ -float complex stdlib_base_cceilf( const float complex z ); +stdlib_complex64_t stdlib_base_cceilf( const stdlib_complex64_t z ); #ifdef __cplusplus } diff --git a/lib/node_modules/@stdlib/math/base/special/cceilf/lib/index.js b/lib/node_modules/@stdlib/math/base/special/cceilf/lib/index.js index 862ad76f1c3e..f5d737db4479 100644 --- a/lib/node_modules/@stdlib/math/base/special/cceilf/lib/index.js +++ b/lib/node_modules/@stdlib/math/base/special/cceilf/lib/index.js @@ -19,7 +19,7 @@ 'use strict'; /** -* Round a single-precision floating-point complex number toward positive infinity. +* Round each component of a single-precision complex floating-point number toward positive infinity. * * @module @stdlib/math/base/special/cceilf * diff --git a/lib/node_modules/@stdlib/math/base/special/cceilf/lib/main.js b/lib/node_modules/@stdlib/math/base/special/cceilf/lib/main.js index d2c6075138df..f92fc98e00c6 100644 --- a/lib/node_modules/@stdlib/math/base/special/cceilf/lib/main.js +++ b/lib/node_modules/@stdlib/math/base/special/cceilf/lib/main.js @@ -29,7 +29,7 @@ var imagf = require( '@stdlib/complex/float32/imag' ); // MAIN // /** -* Rounds a complex number toward positive infinity. +* Rounds each component of a single-precision complex floating-point number toward positive infinity. * * @param {Complex64} z - complex number * @returns {Complex64} result diff --git a/lib/node_modules/@stdlib/math/base/special/cceilf/lib/native.js b/lib/node_modules/@stdlib/math/base/special/cceilf/lib/native.js new file mode 100644 index 000000000000..dd2fa34aa43c --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cceilf/lib/native.js @@ -0,0 +1,58 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 Complex64 = require( '@stdlib/complex/float64/ctor' ); +var addon = require( './../src/addon.node' ); + + +// MAIN // + +/** +* Rounds each component of a single-precision complex floating-point number toward positive infinity. +* +* @private +* @param {Complex64} z - complex number +* @returns {Complex64} result +* +* @example +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* var realf = require( '@stdlib/complex/float32/real' ); +* var imagf = require( '@stdlib/complex/float32/imag' ); +* +* var v = cceilf( new Complex64( -1.5, 2.5 ) ); +* // returns +* +* var re = realf( v ); +* // returns -1.0 +* +* var im = imagf( v ); +* // returns 3.0 +*/ +function cceilf( z ) { + var v = addon( z ); + return new Complex64( v.re, v.im ); +} + + +// EXPORTS // + +module.exports = cceilf; diff --git a/lib/node_modules/@stdlib/math/base/special/cceilf/manifest.json b/lib/node_modules/@stdlib/math/base/special/cceilf/manifest.json index 12073db371ca..ace922f51335 100644 --- a/lib/node_modules/@stdlib/math/base/special/cceilf/manifest.json +++ b/lib/node_modules/@stdlib/math/base/special/cceilf/manifest.json @@ -1,5 +1,7 @@ { - "options": {}, + "options": { + "task": "build" + }, "fields": [ { "field": "src", @@ -24,6 +26,7 @@ ], "confs": [ { + "task": "build", "src": [ "./src/main.c" ], @@ -33,6 +36,41 @@ "libraries": [], "libpath": [], "dependencies": [ + "@stdlib/math/base/napi/unary", + "@stdlib/complex/float32/ctor", + "@stdlib/complex/float32/reim", + "@stdlib/math/base/special/ceilf" + ] + }, + { + "task": "benchmark", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/complex/float32/ctor", + "@stdlib/complex/float32/reim", + "@stdlib/math/base/special/ceilf" + ] + }, + { + "task": "examples", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/complex/float32/ctor", + "@stdlib/complex/float32/reim", "@stdlib/math/base/special/ceilf" ] } diff --git a/lib/node_modules/@stdlib/math/base/special/cceilf/package.json b/lib/node_modules/@stdlib/math/base/special/cceilf/package.json index fbcee18137e8..9727be736b09 100644 --- a/lib/node_modules/@stdlib/math/base/special/cceilf/package.json +++ b/lib/node_modules/@stdlib/math/base/special/cceilf/package.json @@ -1,7 +1,7 @@ { "name": "@stdlib/math/base/special/cceilf", "version": "0.0.0", - "description": "Round a single-precision complex floating-point number toward positive infinity.", + "description": "Round each component of a single-precision complex floating-point number toward positive infinity.", "license": "Apache-2.0", "author": { "name": "The Stdlib Authors", @@ -14,6 +14,7 @@ } ], "main": "./lib", + "gypfile": true, "directories": { "benchmark": "./benchmark", "doc": "./docs", diff --git a/lib/node_modules/@stdlib/math/base/special/cceilf/src/Makefile b/lib/node_modules/@stdlib/math/base/special/cceilf/src/Makefile new file mode 100644 index 000000000000..7733b6180cb4 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cceilf/src/Makefile @@ -0,0 +1,70 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2025 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + + +# RULES # + +#/ +# Removes generated files for building an add-on. +# +# @example +# make clean-addon +#/ +clean-addon: + $(QUIET) -rm -f *.o *.node + +.PHONY: clean-addon + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: clean-addon + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/math/base/special/cceilf/src/addon.c b/lib/node_modules/@stdlib/math/base/special/cceilf/src/addon.c new file mode 100644 index 000000000000..20ec3ec46213 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cceilf/src/addon.c @@ -0,0 +1,22 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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/math/base/special/cceilf.h" +#include "stdlib/math/base/napi/unary.h" + +STDLIB_MATH_BASE_NAPI_MODULE_C_C( stdlib_base_cceilf ) diff --git a/lib/node_modules/@stdlib/math/base/special/cceilf/src/main.c b/lib/node_modules/@stdlib/math/base/special/cceilf/src/main.c index 8423be94b793..55872e2345ff 100644 --- a/lib/node_modules/@stdlib/math/base/special/cceilf/src/main.c +++ b/lib/node_modules/@stdlib/math/base/special/cceilf/src/main.c @@ -18,18 +18,37 @@ #include "stdlib/math/base/special/cceilf.h" #include "stdlib/math/base/special/ceilf.h" -#include +#include "stdlib/complex/float32/ctor.h" +#include "stdlib/complex/float32/reim.h" /** -* Rounds a single-precision complex floating-point number toward positive infinity. +* Rounds each component of a single-precision complex floating-point number toward positive infinity. * * @param z input value * @return result * * @example -* float complex y = stdlib_base_cceilf( 3.5f-2.5f*I ); -* // returns 4.0f-2.0f*I +* #include "stdlib/complex/float32/ctor.h" +* #include "stdlib/complex/float32/real.h" +* #include "stdlib/complex/float32/imag.h" +* +* stdlib_complex64_t z = stdlib_complex64( 3.5f, -2.5f ); +* +* stdlib_complex64_t out = stdlib_base_cceilf( z ); +* +* float re = stdlib_complex64_real( out ); +* // returns 4.0f +* +* float im = stdlib_complex64_imag( out ); +* // returns -2.0f */ -float complex stdlib_base_cceilf( const float complex z ) { - return stdlib_base_ceilf( crealf( z ) ) + stdlib_base_ceilf( cimagf( z ) )*I; +stdlib_complex64_t stdlib_base_cceilf( const stdlib_complex64_t z ) { + float re; + float im; + + stdlib_complex64_reim( z, &re, &im ); + + re = stdlib_base_ceilf( re ); + im = stdlib_base_ceilf( im ); + return stdlib_complex64( re, im ); } diff --git a/lib/node_modules/@stdlib/math/base/special/cceilf/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/cceilf/test/test.native.js new file mode 100644 index 000000000000..833dadb34338 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cceilf/test/test.native.js @@ -0,0 +1,103 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 tape = require( 'tape' ); +var PINF = require( '@stdlib/constants/float32/pinf' ); +var NINF = require( '@stdlib/constants/float32/ninf' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var isNegativeZerof = require( '@stdlib/math/base/assert/is-negative-zerof' ); +var isPositiveZerof = require( '@stdlib/math/base/assert/is-positive-zerof' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var real = require( '@stdlib/complex/float32/real' ); +var imag = require( '@stdlib/complex/float32/imag' ); +var tryRequire = require( '@stdlib/utils/try-require' ); + + +// VARIABLES // + +var cceilf = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( cceilf instanceof Error ) +}; + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof cceilf, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function rounds real and imaginary components to the largest integer greater than or equal to a given number', opts, function test( t ) { + var v; + + v = cceilf( new Complex64( -4.2, 5.5 ) ); + t.strictEqual( real( v ), -4.0, 'returns expected value' ); + t.strictEqual( imag( v ), 6.0, 'returns expected value' ); + + v = cceilf( new Complex64( 9.99999, 0.1 ) ); + t.strictEqual( real( v ), 10.0, 'returns expected value' ); + t.strictEqual( imag( v ), 1.0, 'returns expected value' ); + + v = cceilf( new Complex64( 0.0, 0.0 ) ); + t.strictEqual( real( v ), 0.0, 'returns expected value' ); + t.strictEqual( imag( v ), 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a `NaN` if provided a `NaN`', opts, function test( t ) { + var v = cceilf( new Complex64( NaN, NaN ) ); + t.strictEqual( isnanf( real( v ) ), true, 'returns expected value' ); + t.strictEqual( isnanf( imag( v ) ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns `-0` if provided `-0`', opts, function test( t ) { + var v = cceilf( new Complex64( -0.0, -0.0 ) ); + t.strictEqual( isNegativeZerof( real( v ) ), true, 'returns expected value' ); + t.strictEqual( isNegativeZerof( imag( v ) ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns `+0` if provided `+0`', opts, function test( t ) { + var v = cceilf( new Complex64( +0.0, +0.0 ) ); + t.strictEqual( isPositiveZerof( real( v ) ), true, 'returns expected value' ); + t.strictEqual( isPositiveZerof( imag( v ) ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns `+infinity` if provided `+infinity`', opts, function test( t ) { + var v = cceilf( new Complex64( PINF, PINF ) ); + t.strictEqual( real( v ), PINF, 'returns expected value' ); + t.strictEqual( imag( v ), PINF, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns `-infinity` if provided `-infinity`', opts, function test( t ) { + var v = cceilf( new Complex64( NINF, NINF ) ); + t.strictEqual( real( v ), NINF, 'returns expected value' ); + t.strictEqual( imag( v ), NINF, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/special/floor10/README.md b/lib/node_modules/@stdlib/math/base/special/floor10/README.md index 50e7a48f2fa1..cdf494f111f6 100644 --- a/lib/node_modules/@stdlib/math/base/special/floor10/README.md +++ b/lib/node_modules/@stdlib/math/base/special/floor10/README.md @@ -98,18 +98,16 @@ v = floor10( NaN ); ```javascript -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var logEachMap = require( '@stdlib/console/log-each-map' ); var floor10 = require( '@stdlib/math/base/special/floor10' ); -var x; -var v; -var i; +var opts = { + 'dtype': 'float64' +}; +var x = uniform( 100, -50.0, 50.0, opts ); -for ( i = 0; i < 100; i++ ) { - x = (randu()*100.0) - 50.0; - v = floor10( x ); - console.log( 'Value: %d. Rounded: %d.', x, v ); -} +logEachMap( 'x: %0.4f. Rounded: %d.', x, floor10 ); ``` diff --git a/lib/node_modules/@stdlib/math/base/special/floor10/examples/index.js b/lib/node_modules/@stdlib/math/base/special/floor10/examples/index.js index 1402b0723bab..15dc72ca8d9a 100644 --- a/lib/node_modules/@stdlib/math/base/special/floor10/examples/index.js +++ b/lib/node_modules/@stdlib/math/base/special/floor10/examples/index.js @@ -18,15 +18,13 @@ 'use strict'; -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var logEachMap = require( '@stdlib/console/log-each-map' ); var floor10 = require( './../lib' ); -var x; -var v; -var i; +var opts = { + 'dtype': 'float64' +}; +var x = uniform( 100, -50.0, 50.0, opts ); -for ( i = 0; i < 100; i++ ) { - x = (randu()*100.0) - 50.0; - v = floor10( x ); - console.log( 'x: %d. Rounded: %d.', x, v ); -} +logEachMap( 'x: %0.4f. Rounded: %d.', x, floor10 ); diff --git a/lib/node_modules/@stdlib/math/base/special/floorf/README.md b/lib/node_modules/@stdlib/math/base/special/floorf/README.md index e60a7c3b0db0..ab40fa19a8bb 100644 --- a/lib/node_modules/@stdlib/math/base/special/floorf/README.md +++ b/lib/node_modules/@stdlib/math/base/special/floorf/README.md @@ -59,16 +59,16 @@ v = floorf( NaN ); ```javascript -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var logEachMap = require( '@stdlib/console/log-each-map' ); var floorf = require( '@stdlib/math/base/special/floorf' ); -var x; -var i; +var opts = { + 'dtype': 'float32' +}; +var x = uniform( 100, -50.0, 50.0, opts ); -for ( i = 0; i < 100; i++ ) { - x = (randu()*100.0) - 50.0; - console.log( 'floorf(%d) = %d', x, floorf( x ) ); -} +logEachMap( 'floorf(%0.4f) = %d', x, floorf ); ``` diff --git a/lib/node_modules/@stdlib/math/base/special/floorf/examples/index.js b/lib/node_modules/@stdlib/math/base/special/floorf/examples/index.js index 2147ee4446e7..789fc2784166 100644 --- a/lib/node_modules/@stdlib/math/base/special/floorf/examples/index.js +++ b/lib/node_modules/@stdlib/math/base/special/floorf/examples/index.js @@ -18,13 +18,13 @@ 'use strict'; -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var logEachMap = require( '@stdlib/console/log-each-map' ); var floorf = require( './../lib' ); -var x; -var i; +var opts = { + 'dtype': 'float32' +}; +var x = uniform( 100, -50.0, 50.0, opts ); -for ( i = 0; i < 100; i++ ) { - x = (randu()*100.0) - 50.0; - console.log( 'floorf(%d) = %d', x, floorf( x ) ); -} +logEachMap( 'floorf(%0.4f) = %d', x, floorf ); diff --git a/lib/node_modules/@stdlib/math/base/special/floorsd/README.md b/lib/node_modules/@stdlib/math/base/special/floorsd/README.md index e62941139d87..942156111a6b 100644 --- a/lib/node_modules/@stdlib/math/base/special/floorsd/README.md +++ b/lib/node_modules/@stdlib/math/base/special/floorsd/README.md @@ -65,18 +65,16 @@ v = floorsd( 0.0313, 2, 2 ); ```javascript -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var logEachMap = require( '@stdlib/console/log-each-map' ); var floorsd = require( '@stdlib/math/base/special/floorsd' ); -var x; -var y; -var i; +var opts = { + 'dtype': 'float32' +}; +var x = uniform( 100, -5000.0, 5000.0, opts ); -for ( i = 0; i < 100; i++ ) { - x = (randu()*10000.0) - 5000.0; - y = floorsd( x, 5, 10 ); - console.log( 'x: %d. Rounded: %d.', x, y ); -} +logEachMap( 'x: %0.4f. y: %d. z: %d. Rounded: %0.4f.', x, 5, 10, floorsd ); ``` diff --git a/lib/node_modules/@stdlib/math/base/special/floorsd/examples/index.js b/lib/node_modules/@stdlib/math/base/special/floorsd/examples/index.js index b7d7b724573e..fdf45358730f 100644 --- a/lib/node_modules/@stdlib/math/base/special/floorsd/examples/index.js +++ b/lib/node_modules/@stdlib/math/base/special/floorsd/examples/index.js @@ -18,15 +18,13 @@ 'use strict'; -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var logEachMap = require( '@stdlib/console/log-each-map' ); var floorsd = require( './../lib' ); -var x; -var y; -var i; +var opts = { + 'dtype': 'float32' +}; +var x = uniform( 100, -5000.0, 5000.0, opts ); -for ( i = 0; i < 100; i++ ) { - x = (randu()*10000.0) - 5000.0; - y = floorsd( x, 5, 10 ); - console.log( 'x: %d. Rounded: %d.', x, y ); -} +logEachMap( 'x: %0.4f. y: %d. z: %d. Rounded: %0.4f.', x, 5, 10, floorsd ); diff --git a/lib/node_modules/@stdlib/math/base/special/fmod/README.md b/lib/node_modules/@stdlib/math/base/special/fmod/README.md index ab87cd2d57ab..5af3face8720 100644 --- a/lib/node_modules/@stdlib/math/base/special/fmod/README.md +++ b/lib/node_modules/@stdlib/math/base/special/fmod/README.md @@ -83,19 +83,17 @@ v = fmod( NaN, NaN ); ```javascript -var randu = require( '@stdlib/random/base/randu' ); -var round = require( '@stdlib/math/base/special/round' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var logEachMap = require( '@stdlib/console/log-each-map' ); var fmod = require( '@stdlib/math/base/special/fmod' ); -var x; -var y; -var i; +var opts = { + 'dtype': 'float64' +}; +var x = discreteUniform( 100, 0, 10, opts ); +var y = discreteUniform( 100, -5, 5, opts ); -for ( i = 0; i < 100; i++ ) { - x = round( randu() * 10.0 ); - y = round( randu() * 10.0 ) - 5.0; - console.log( '%d%%%d = %d', x, y, fmod( x, y ) ); -} +logEachMap( '%d%%%d = %d', x, y, fmod ); ``` diff --git a/lib/node_modules/@stdlib/math/base/special/fmod/examples/index.js b/lib/node_modules/@stdlib/math/base/special/fmod/examples/index.js index dcd99929a8bf..a3580961d8b8 100644 --- a/lib/node_modules/@stdlib/math/base/special/fmod/examples/index.js +++ b/lib/node_modules/@stdlib/math/base/special/fmod/examples/index.js @@ -18,16 +18,14 @@ 'use strict'; -var randu = require( '@stdlib/random/base/randu' ); -var round = require( '@stdlib/math/base/special/round' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var logEachMap = require( '@stdlib/console/log-each-map' ); var fmod = require( './../lib' ); -var x; -var y; -var i; +var opts = { + 'dtype': 'float64' +}; +var x = discreteUniform( 100, 0, 10, opts ); +var y = discreteUniform( 100, -5, 5, opts ); -for ( i = 0; i < 100; i++ ) { - x = round( randu() * 10.0 ); - y = round( randu() * 10.0 ) - 5.0; - console.log( '%d%%%d = %d', x, y, fmod( x, y ) ); -} +logEachMap( '%d%%%d = %d', x, y, fmod ); diff --git a/lib/node_modules/@stdlib/math/base/special/fmodf/README.md b/lib/node_modules/@stdlib/math/base/special/fmodf/README.md index 5fc69800b819..40b4dcdf5004 100644 --- a/lib/node_modules/@stdlib/math/base/special/fmodf/README.md +++ b/lib/node_modules/@stdlib/math/base/special/fmodf/README.md @@ -84,15 +84,16 @@ v = fmodf( NaN, NaN ); ```javascript var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var logEachMap = require( '@stdlib/console/log-each-map' ); var fmodf = require( '@stdlib/math/base/special/fmodf' ); -var x = discreteUniform( 10, 0.0, 100.0 ); -var y = discreteUniform( 10, -50.0, 50.0 ); -var i; +var opts = { + 'dtype': 'float32' +}; +var x = discreteUniform( 100, 0, 100, opts ); +var y = discreteUniform( 100, -50, 50, opts ); -for ( i = 0; i < 10; i++ ) { - console.log( '%f%%%f = %f', x[ i ], y[ i ], fmodf( x[ i ], y[ i ] ) ); -} +logEachMap( '%d%%%d = %d', x, y, fmodf ); ``` diff --git a/lib/node_modules/@stdlib/math/base/special/fmodf/examples/index.js b/lib/node_modules/@stdlib/math/base/special/fmodf/examples/index.js index 5b519dd727f2..39bb0d36cd73 100644 --- a/lib/node_modules/@stdlib/math/base/special/fmodf/examples/index.js +++ b/lib/node_modules/@stdlib/math/base/special/fmodf/examples/index.js @@ -19,12 +19,13 @@ 'use strict'; var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var logEachMap = require( '@stdlib/console/log-each-map' ); var fmodf = require( './../lib' ); -var x = discreteUniform( 10, 0.0, 100.0 ); -var y = discreteUniform( 10, -50.0, 50.0 ); -var i; +var opts = { + 'dtype': 'float32' +}; +var x = discreteUniform( 100, 0, 100, opts ); +var y = discreteUniform( 100, -50, 50, opts ); -for ( i = 0; i < 10; i++ ) { - console.log( '%f%%%f = %f', x[ i ], y[ i ], fmodf( x[ i ], y[ i ] ) ); -} +logEachMap( '%d%%%d = %d', x, y, fmodf ); diff --git a/lib/node_modules/@stdlib/math/base/special/roundsd/README.md b/lib/node_modules/@stdlib/math/base/special/roundsd/README.md index 67b162fdb58a..f219dc7a20ce 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsd/README.md +++ b/lib/node_modules/@stdlib/math/base/special/roundsd/README.md @@ -20,7 +20,7 @@ limitations under the License. # roundsd -> Round a numeric value to the nearest number with `n` significant figures. +> Round a double-precision floating-point number to the nearest value with `n` significant figures.
@@ -32,7 +32,7 @@ var roundsd = require( '@stdlib/math/base/special/roundsd' ); #### roundsd( x, n\[, b] ) -Rounds a `numeric` value to the nearest `number` with `n` significant figures. +Rounds a double-precision floating-point number to the nearest value with `n` significant figures. ```javascript var v = roundsd( 3.141592653589793, 3 ); @@ -85,6 +85,93 @@ logEachMap( 'x: %0.4f. y: %d. Rounded: %0.4f.', x, 5, roundsd ); + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/math/base/special/roundsd.h" +``` + +#### stdlib_base_roundsd( x, n, b ) + +Rounds a double-precision floating-point number to the nearest value with `n` significant figures. + +```c +double v = stdlib_base_roundsd( 3.141592653589793, 3, 10 ); +// returns 3.14 +``` + +The function accepts the following arguments: + +- **x**: `[in] double` input value. +- **n**: `[in] int32_t` number of significant figures. +- **b**: `[in] int32_t` base. + +```c +double stdlib_base_roundsd( const double x, const int32_t n, const int32_t b ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/math/base/special/roundsd.h" +#include + +int main( void ) { + const double x[] = { 3.143546, -3.142635, 0.0, 0.0/0.0 }; + + double y; + int i; + for ( i = 0; i < 4; i++ ) { + y = stdlib_base_roundsd( x[ i ], 2, 10 ); + printf( "roundsd(%lf) = %lf\n", x[ i ], y ); + } +} +``` + +
+ + + +
+ + +